STC8上的2048中文版(做着玩玩)

安装说明
使用128*160并口彩屏LCD,驱动:ILI9163C

main函数

//P33 rs
//P34 cs
//P35 RES
//P36 wr
//P37 rd
//P2 数据口
//P42 背光

//P43 P45 P06 P46 上下左右
//P41 重启

void main()	
{
unsigned int seed = 0;
unsigned char m=0,l=0;
EWORD yanchi_CD=1500;
P_SW2 |= 0x80;//访问外部寄存器必须打头
CKSEL=0x00;//**时钟选择开关
CLKDIV=2;
//CLKDIV=18;//**8位分频
HIRCCR=0x80; //**高精度使能	 低位是振荡器稳定标志位
P_SW2 &= 0x7f;//访问外部寄存器必须结尾
IRCBAND=0x01;//IRC内部频段选择20M/35M
IRTRIM=0xf0;//添加 IRC内部频率调整器	//0xa0_41.216MHZ  0xb0_42.625MHZ
LIRTRIM=1;//添加
while(HIRCCR==0x80);
P4M0=0xff;//P44它激振荡器源 P40P41P46按键
P4M1=0xff;//P4设置P4M0_11111111    P4M11111111   

P42=0;
P10=0;

P0M0=0xbf; // P0M0_10111111  P1M1_10111011
P0M1=0xbb; //P02_LED P06_S2轻触开关—最左边一个

P1M0=0xff;// P12定时功能键	 //
P1M1=0xff;//P1口设置P1M0_11111101  P1M1_10111111  
   																									   
P2M0=0x00;//数码管
P2M1=0x00;//P2口设置P2M0_11111111  P2M1_00000000//数码管关闭  



P5M0=0xff;// 
P5M1=0xff;//P5M0_11111111  P5M1_11110000    

P3M0=0x07;
P3M1=0x07;//设置P3M0_11111111 P3M1_00000111//数码管关闭   
//LED_K  液晶1脚 接P42

//while(1){P02=~P02;Delayms(1000);}
RES=1;
Delayms(30);
RES=0;
Delayms(60);
RES=1;
Delayms(60);
Initial_ILI9163C(); 
P4M0=0x94;//P44它激振荡器源 P40P41P46按键
P4M1=0x90;//P4设置P4M0_10010110    P4M1_10010010 
P1M0=0xff;
P1M1=0xfe;
dr = 7;
paintPanel();
P42=1;P10=1; 

	while(1)   
	{   
		
		seed=0;
		while(1)
		{ 
			seed++;
			if(P06 == 0) { 
				Delayms(2);
				
			    if(P06 == 0) 
			   	{
				   while(P06 == 0); 
				   break;
				}
			}
			if(P43 == 0) { 
				Delayms(2); 
			    if(P43 == 0) 
			   	{
				   seed+=1;
				   while(P43 == 0); 
				   break;
				}
			}
			if(P45 == 0) { 
				Delayms(2); 
			    if(P45 == 0) 
			   	{
				   seed+=2;
				   while(P45 == 0); 
				   break;
				}
			}
			if(P46 == 0) { 
				Delayms(2); 
			    if(P46 == 0) 
			   	{
				   seed+=3;
				   while(P46 == 0); 
				   break;
				}
			}
			if(P41==0)
			{
				Delayms(2);
				if(P41==0)
				{
					while(P41==0);
					Reset();
				}
			}
			if(P40 == 0) { 
				Delayms(2);
				
			    if(P40 == 0) 
			   	{
				    while(P40 == 0); 
				    l=!l;
					if(l){
					  comm_out(0x21);
					}else{
					  comm_out(0x20);
					}
				  
				}
			}
		}
		
		/*
		value[3][3] = seed % 13;
		value[3][2] = seed / 13 % 13;
		value[3][1]	= seed / 13 / 13 % 13;
		value[3][0]	= seed / 13 / 13 /13 % 13;
		value[2][3]	= seed / 13 / 13 /13/13 % 13;
		value[2][2]	= seed / 13 / 13 /13/13 % 13;
		*/
		
		srand(seed);
		displayRect();
		Delayms(2500);P02=~P02;
		dr = 4;
		initCell();
		paintPanel2();
		dr=0;
		while(max < 14){

			
			seed = 0;
			while(1)
			{ 
				seed++;
				if(P06 == 0) { 
					Delayms(2); 
				    if(P06 == 0) 
				   	{
						seed+=3;
					   while(P06 == 0); 
					   dr = 3;
					   //dr++;
		    			//if(dr > 3) dr = 0;
					   break;
					}
				}
				if(P43 == 0) { 
					Delayms(2); 
				    if(P43 == 0) 
				   	{
					   
					   while(P43 == 0); 
					   dr = 0;
					   
					   break;
					}
				}
				if(P45 == 0) { 
					Delayms(2); 
				    if(P45 == 0) 
				   	{
						seed+=2;
					   while(P45 == 0); 
					   dr = 2;
					   
					   break;
					}
				}
				if(P46 == 0) { 
					Delayms(2); 
				    if(P46 == 0) 
				   	{
						seed+=1;
					   while(P46 == 0); 
					   dr = 1;
					   
					   break;
					}
				}
				if(P41==0)
				{
					Delayms(2);
					if(P41==0)
					{
						while(P41==0);
						Reset();
					}
				}
				if(P40 == 0) { 
					Delayms(2);
					
				    if(P40 == 0) 
				   	{
					    while(P40 == 0); 
					    l=!l;
						if(l){
						  comm_out(0x21);
						}else{
						  comm_out(0x20);
						}
					  
					}
				}
				
				/*
				if(P40 == 0) { 
					Delayms(2); 
				    if(P40 == 0) 
				   	{
					   while(P40 == 0); 
					    m++;
						m &= 0x01;
						if(m){
						    comm_out(0x21);
						    comm_out(0x36); //翻转 扫描顺序 颜色顺序设置
							data_out(0x00);
						}else{
							comm_out(0x20);
							comm_out(0x36); //翻转 扫描顺序 颜色顺序设置
							data_out(0xC0);
						}
						paintPanel();
					   
					}
				}*/


			}
			
			

			switch(dr){
				
				case 0://Up 
					up();
					
					//message = "UP";
				break;
				
				case 2: //down
					
					down();
					//message = "DOWN";
				break;
				
				case 3://left
					left();
					//message = "LEFT";
				break;
				
				case 1://right
					right();
					//message = "RIGHT";
				break;
				
				default:
					continue;
				//break;
		
			}//end switch 
			
			

			if(isMove){
				srand(seed);
				addNewCell();
			}
			
			paintPanel();

			Delayms(1000);P02=~P02;

			if(!isGameGoon()){
				break;
			}
		
			
		}
		if(max>=14){
		 	dr = 6;
		}else{
			dr = 5;
		}	
			
		paintPanel();
		Delayms(0x7FFF);  
		 
	}
}

源码: 码云

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值