毕设选题 单片机贪吃蛇游戏(AT89C51 12864)Protues仿真

一、电路设计

此电路由AT89C55、液晶屏和按键模块组成。

七个按键分别为:上、下、左、右、确定、取消、暂停。

二、运行结果

三、部分代码



    #include 
    #include <12864.h>
    #include 
    #include 


    struct menu_index
    {
    	unsigned char up_num;
    	unsigned char down_num;
    	unsigned char confirm_num;
    	unsigned char cansel_num;
    };
    
    struct menu_index code menu_num[14]=
    {
    	{3,1,4,0},
    	{0,2,5,1},
    	{1,3,9,2},
    	{2,0,12,3},
    
    	{0,0,0,0},
    
    	{8,6,5,1},
    	{5,7,6,1},
    	{6,8,7,1},
    	{7,5,8,1},
    
    	{11,10,9,2},
    	{9,11,10,2},
    	{10,9,11,2},
    
    	{13,13,12,3},
    	{12,12,13,3},
    };
    
    unsigned char present_menu_num; 
    extern unsigned char flag_exit_game;
    extern unsigned char tcs_nd;
    extern unsigned char tcs_dt;
    
    void tcs_game();
    
    void main()
    {
    	present_menu_num=0;
    	tcs_nd=1;
    	tcs_dt=1;
    	initial_lcd();
    	clear_lcd();
    	huihui(present_menu_num);
    			
    	while(1)
    	{
    		key_down();
    	}
    }


    void key_down()
    {
    	unsigned char h;
    	if((P2&0x7f)!=0x7f)
    	{
    		delay_ms(10);
    		if ((P2&0x7f)!=0x7f) 
    		{
    			h=P2&0x7f;
    			switch(h)
    			{
    				case 0x6f:	{
    								present_menu_num=menu_num[present_menu_num].confirm_num;
    								huihui(present_menu_num);
    								break;
    							}// È·¶¨¼ü
    	
    				case 0x5f:	{
    								present_menu_num=menu_num[present_menu_num].cansel_num;
    								huihui(present_menu_num);
    								break;
    							}//·µ»Ø¼ü
    
    				case 0x7e:	{
    								present_menu_num=menu_num[present_menu_num].up_num;
    								huihui(present_menu_num);
    								break;
    							}//¡ü
    
    				case 0x7b: 	break;//¡û
    
    				case 0x7d:  {
    								present_menu_num=menu_num[present_menu_num].down_num;
    								huihui(present_menu_num);
    								break;
    							}//¡ý
    
    				case 0x77:  break;//->
    			}
    			while( (P2&0x7f)!=0x7f );
    			P2=0xff;
    			delay_ms(10);
    		}
    				
    	}
    }


项目获取:

https://gitee.com/feifei1122/simulation-project

  • 8
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值