请各位帮看看为啥这个在仿真里显示不出来,是哪里有问题吗?
单片机源程序如下:
- #include<reg52.h> //此处省略定义uint,uchar
- #define DATA_PORT P0
- sbit LCD12864_RS = P2^0; //寄存器选择
- sbit LCD12864_RW = P2^1; //读/写控制
- sbit LCD12864_E = P2^2; //使能,此处PSB为并行方式
- sbit LCD12864_RST = P2^4;
- //此处省略定义按键IO口
- xdata uchar game=0; //当前第几关
- xdata uchar renwu_x,renwu_y; //人所在位置的坐标
- //关卡8*8点阵 人物1,砖头2,箱子3,目的4,成功5,人物目的6
- uchar idata map_ram[8][8]={
- 0,0,0,0,0,0,0,0,
- 0,1,0,0,0,0,0,0,
- 0,0,0,0,0,0,0,0,
- 0,0,0,0,0,0,0,0,
- 0,0,0,0,0,0,0,0,
- 0,0,0,0,0,0,0,0,
- 0,0,0,0,0,0,0,0,
- 0,0,0,0,0,0,0,0,
- };
- uchar code map[][8][8]={
- 2,2,2,2,2,2,2,2, //第一关
- 2,0,0,0,0,0,1,2,
- 2,0,0,0,5,0,0,2,
- 2,0,0,2,2,2,2,2,
- 2,2,0,0,2,0,0,0,
- 2,0,3,0,2,0,0,0,
- 2,0,0,4,2,0,0,0,
- 2,2,2,2,2,0,0,0,
- }; //此处省略剩余关卡
- uchar code map0[]={
-
- " 推箱子 "
- " 学电子 "
- " "
- " "
- };
- uchar code tuxiang[7][8]={
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,//空白
- 0x3C,0x3C,0x18,0x7E,0x5A,0x24,0x42,0x81,//人物
- 0x77,0x77,0x77,0x00,0xEE,0xEE,0xEE,0x00,//砖头
- 0xFF,0xC3,0xA5,0x99,0x99,0xA5,0xC3,0xFF,//箱子
- 0x00,0x3C,0x5A,0x66,0x66,0x5A,0x3C,0x00,//目的
- 0xFF,0xBD,0xDB,0xE7,0xE7,0xDB,0xBD,0xFF,//成功
- 0x3C,0x3C,0x18,0x7E,0x5A,0x24,0x42,0x81,//人物目的
- };
- //--定义全局函数--//
- void Lcd_WriteCmd(cmd);
- void Lcd_WriteData(dat);
- void delay_1ms();
- void Lcd_Init(); //初始化界面
- void Lcd_ClearScreen(void); //清除显示整个图片
- void busy(void); //忙标志位检查
- void Init_0(void); //初始化开始界面,等待进入游戏
- void guoguan(void); //过关后刷新界面
- //在指定位置一次显示两个标题
- void print_title(uchar xx,uchar yy,uchar code*title1,uchar code*title2);
- //在指定位置打印
- void print_onetitle(uchar xx,uchar yy,uchar code*title);
- void shuaxin(void); //刷新屏幕
- void key_scan(char sx,char zy);
- //此处省略延时函数
- void key_scan(char sx,char zy)
- {
- if(map_ram[renwu_x][renwu_y]==1) //人物
- {
- if(map_ram[renwu_x+sx][renwu_y+zy]==0)
- {
- print_onetitle(renwu_x,renwu_y,tuxiang[0]);
- map_ram[renwu_x][renwu_y]=0;
- renwu_x = renwu_x+sx;
- renwu_y=renwu_y+zy;
- print_onetitle(renwu_x,renwu_y,tuxiang[1]);
- map_ram[renwu_x][renwu_y]=1;
- }
- // else if(map_ram[renwu_x+sx][renwu_y+zy]==4)
- // {
- // print_onetitle(renwu_x,renwu_y,tuxiang[0]);
- // map_ram[renwu_x][renwu_y]=0;
- // renwu_x = renwu_x+sx;
- // renwu_y=renwu_y+zy;
- // print_onetitle(renwu_x,renwu_y,tuxiang[6]);
- // map_ram[renwu_x][renwu_y]=6;
- // }
- // else if(map_ram[renwu_x+sx][renwu_y+zy]==3)
- // {
- // if(map_ram[renwu_x+sx][renwu_y+zy]==0)
- // { print_onetitle(renwu_x,renwu_y,tuxiang[0]);
- // map_ram[renwu_x][renwu_y]=0;
- // renwu_x = renwu_x+sx;
- // renwu_y=renwu_y+zy;
- // print_onetitle(renwu_x,renwu_y,tuxiang[1]);
- // map_ram[renwu_x][renwu_y]=1;
- // print_onetitle(renwu_x,renwu_y,tuxiang[3]);
- // map_ram[renwu_x][renwu_y]=3;
- // }
- // else if(map_ram[renwu_x+sx][renwu_y+zy]==4)
- // {
- // print_onetitle(renwu_x,renwu_y,tuxiang[0]);
- // map_ram[renwu_x][renwu_y]=0;
- // renwu_x = renwu_x+sx;
- // renwu_y=renwu_y+zy;
- // print_onetitle(renwu_x,renwu_y,tuxiang[1]);
- // map_ram[renwu_x][renwu_y]=1;
- // print_onetitle(renwu_x,renwu_y,tuxiang[5]);
- // map_ram[renwu_x][renwu_y]=5;
- // }
- // }
- // else if(map_ram[renwu_x+sx][renwu_y+zy]==5)
- // {
- // if(map_ram[renwu_x+sx][renwu_y+zy]==0)
- // { print_onetitle(renwu_x,renwu_y,tuxiang[0]);
- // map_ram[renwu_x][renwu_y]=0;
- // renwu_x = renwu_x+sx;
- // renwu_y=renwu_y+zy;
- // print_onetitle(renwu_x,renwu_y,tuxiang[6]);
- // map_ram[renwu_x][renwu_y]=6;
- // print_onetitle(renwu_x,renwu_y,tuxiang[3]);
- // map_ram[renwu_x][renwu_y]=3;
- // }
- // else if(map_ram[renwu_x+sx][renwu_y+zy]==4)
- // {
- // print_onetitle(renwu_x,renwu_y,tuxiang[0]);
- // map_ram[renwu_x][renwu_y]=0;
- // renwu_x = renwu_x+sx;
- // renwu_y=renwu_y+zy;
- // print_onetitle(renwu_x,renwu_y,tuxiang[6]);
- // map_ram[renwu_x][renwu_y]=6;
- // print_onetitle(renwu_x,renwu_y,tuxiang[5]);
- // map_ram[renwu_x][renwu_y]=5;
- // }
- // }
- }
- // else if(map_ram[renwu_x+sx][renwu_y+zy]==6)
- // {
- // if(map_ram[renwu_x+sx][renwu_y+zy]==0)
- // { print_onetitle(renwu_x,renwu_y,tuxiang[0]);
- // map_ram[renwu_x][renwu_y]=0;
- // renwu_x = renwu_x+sx;
- // renwu_y=renwu_y+zy;
- // print_onetitle(renwu_x,renwu_y,tuxiang[4]);
- // map_ram[renwu_x][renwu_y]=4;
- // print_onetitle(renwu_x,renwu_y,tuxiang[1]);
- // map_ram[renwu_x][renwu_y]=1;
- // }
- // else if(map_ram[renwu_x+sx][renwu_y+zy]==4)
- // {
- // print_onetitle(renwu_x,renwu_y,tuxiang[4]);
- // map_ram[renwu_x][renwu_y]=4;
- // renwu_x = renwu_x+sx;
- // renwu_y=renwu_y+zy;
- // print_onetitle(renwu_x,renwu_y,tuxiang[6]);
- // map_ram[renwu_x][renwu_y]=6;
- // print_onetitle(renwu_x,renwu_y,tuxiang[6]);
- // map_ram[renwu_x][renwu_y]=6;
- // }
- // else if(map_ram[renwu_x+sx][renwu_y+zy]==3)
- // {
- // if(map_ram[renwu_x+sx][renwu_y+zy]==0)
- // { print_onetitle(renwu_x,renwu_y,tuxiang[4]);
- // map_ram[renwu_x][renwu_y]=4;
- // renwu_x = renwu_x+sx;
- // renwu_y=renwu_y+zy;
- // print_onetitle(renwu_x,renwu_y,tuxiang[1]);
- // map_ram[renwu_x][renwu_y]=1;
- // print_onetitle(renwu_x,renwu_y,tuxiang[3]);
- // map_ram[renwu_x][renwu_y]=3;
- // }
- // else if(map_ram[renwu_x+sx][renwu_y+zy]==4)
- // {
- // print_onetitle(renwu_x,renwu_y,tuxiang[4]);
- // map_ram[renwu_x][renwu_y]=4;
- // renwu_x = renwu_x+sx;
- // renwu_y=renwu_y+zy;
- // print_onetitle(renwu_x,renwu_y,tuxiang[1]);
- // map_ram[renwu_x][renwu_y]=1;
- // print_onetitle(renwu_x,renwu_y,tuxiang[5]);
- // map_ram[renwu_x][renwu_y]=5;
- // }
- // }
- // else if(map_ram[renwu_x+sx][renwu_y+zy]==5)
- // {
- // if(map_ram[renwu_x+sx][renwu_y+zy]==0)
- // { print_onetitle(renwu_x,renwu_y,tuxiang[4]);
- // map_ram[renwu_x][renwu_y]=4;
- // renwu_x = renwu_x+sx;
- // renwu_y=renwu_y+zy;
- // print_onetitle(renwu_x,renwu_y,tuxiang[6]);
- // map_ram[renwu_x][renwu_y]=6;
- // print_onetitle(renwu_x,renwu_y,tuxiang[3]);
- // map_ram[renwu_x][renwu_y]=3;
- // }
- // else if(map_ram[renwu_x+sx][renwu_y+zy]==4)
- // {
- // print_onetitle(renwu_x,renwu_y,tuxiang[4]);
- // map_ram[renwu_x][renwu_y]=4;
- // renwu_x = renwu_x+sx;
- // renwu_y=renwu_y+zy;
- // print_onetitle(renwu_x,renwu_y,tuxiang[6]);
- // map_ram[renwu_x][renwu_y]=6;
- // print_onetitle(renwu_x,renwu_y,tuxiang[5]);
- // map_ram[renwu_x][renwu_y]=5;
- // }
- // }
- // }
- }
- void Init_0(void) //初始化界面,等待进入游戏
- {
- uchar lala=0;
- Lcd_Init();
- delay_1ms(10);
- while(lala==0)
- {
- if(KEY_START==0)
- { delay_1ms(10);
- if(KEY_START==0)
- {
- Lcd_WriteCmd(0x01);
- // Lcd_WriteCmd(0x01);
- Lcd_ClearScreen();
- guoguan();
- lala=1;
- }
- }
- }
- }
- void busy(void) //忙标志位检查
- {
- LCD12864_RS=0;
- LCD12864_RW=1;
- LCD12864_E=1;
- P0=0xff;
- while((P0&0x80)==0x80)
- delay_1ms(5);
- LCD12864_E=0;
- }
- void Lcd_WriteCmd(cmd) //写入一个命令到12864
- {
- busy();
- LCD12864_E = 1; //使能
- LCD12864_RS = 0; //select command,选择命令
- LCD12864_RW = 0; //select write,选择写模式
- delay_1ms(5);
- DATA_PORT = cmd; //put command,放置命令
- LCD12864_E = 0;
-
- }
- void Lcd_WriteData(dat) //写入一个数据到12864
- {
- busy();
- LCD12864_E = 1; //disable read,读使能
- LCD12864_RS = 1; //select data,选择数据
- LCD12864_RW = 0; //select write,选择写模式
- delay_1ms(5);
- DATA_PORT = dat; //put data,放置数据
- LCD12864_E = 0;
-
- }
- void Lcd_Init() //LCD初始化
- {
- uchar i;
- uchar code *p;
- p=map0;
- Lcd_WriteCmd(0x30); //基本指令操作,地址归位
- delay_1ms(5);
- Lcd_WriteCmd(0x0C); //显示开,关光标
- delay_1ms(5);
- Lcd_WriteCmd(0x01); //清除LCD的显示
- delay_1ms(5);
- Lcd_WriteCmd(0x06); //指定在资料的读取及写入
- for(i=0;i<64;i++) //自动右移
- {
- Lcd_WriteData(*p);
- p++;
- }
- }
- void Lcd_ClearScreen(void)
- {
- uchar x,y;
- Lcd_WriteCmd(0x34); //使用扩充指令
- for(y=0;y<64;y++)
- {
- Lcd_WriteCmd(y+0x80); //读忙碌状态
- Lcd_WriteCmd(x+0x80);
- Lcd_WriteData(0x00); }
- }
- void guoguan(void) //过关后刷新界面
- {
- uchar i,j;
- Lcd_ClearScreen();
- for(i=0;i<8;i++)
- for(j=0;j<8;j++)
- {
- map_ram[i][j]=map[game][j][i];
- if(map_ram[i][j]==1)
- {
- renwu_x=i;
- renwu_y=j;
- }
- }
- for(i=0;i<4;i++)
- for(j=0;j<8;j++)
- {
- print_title(i,j,tuxiang[map_ram[2*i][j]],tuxiang[map_ram[2*i+1][j]]);
- }
- game++;
- }
- void print_title(uchar xx,uchar yy,uchar code*title1,uchar code*title2)
- {
- uchar j=0;
- uchar i=0;
- uchar y;
- if(yy>3)
- {
- xx=xx+8;
- yy=yy-4;
- }
- yy=yy*8;
- y=yy+8;
- Lcd_WriteCmd(0x36); //8bit控制,扩充指,开显示
- for(;yy<y;yy++) //上面32行
- {
- Lcd_WriteCmd(yy+0x80); //y行地址
- Lcd_WriteCmd(xx+0x80); //x行地址
- Lcd_WriteData(title1[i++]);
- Lcd_WriteData(title2[j++]);
- }
- }
- //在指定位置打印
- void print_onetitle(uchar xx,uchar yy,uchar code*title)
- {
- uchar j=0;
- uchar i=0;
- uchar code *title1;
- uchar x,y,z;
- x=xx%2;
- if(x==1)
- {
- z=map[xx-1][yy];
- title1=tuxiang[z];
- if(yy>3)
- {
- xx=xx+8;
- yy=yy-4;
- }
- yy=yy*8;
- y=yy+8;
- Lcd_WriteCmd(0x36); //8bit控制,扩充指,开显示
- for(;yy<y;yy++) //上面32行
- {
- Lcd_WriteCmd(yy+0x80); //y行地址
- Lcd_WriteCmd(xx+0x80); //x行地址
- Lcd_WriteData(title1[i++]);
- Lcd_WriteData(title[j++]);
- }
- }
- if(x==0)
- {
- z=map[xx+1][yy];
- title1=tuxiang[z];
- if(yy>3)
- {
- xx=xx+8;
- yy=yy-4;
- }
- yy=yy*8;
- y=yy+8;
- Lcd_WriteCmd(0x36); //8bit控制,扩充指,开显示
- for(;yy<y;yy++) //上面32行
- {
- Lcd_WriteCmd(yy+0x80); //y行地址
- Lcd_WriteCmd(xx+0x80); //x行地址
- Lcd_WriteData(title[i++]);
- Lcd_WriteData(title1[j++]);
- }
- }
- }
- void shuanxin(void)
- {
- uchar i,j;
- for(i=0;i<4;i++)
- for(j=0;j<8;j++)
- {
- print_title(i,j,tuxiang[map_ram[2*i][j]],tuxiang[map_ram[2*i+1][j]]);
- }
- }
- //主程序
- void main()
- {
- Lcd_Init();
- Init_0();
- Lcd_ClearScreen();
- while(1)
- {
- if(KEY_UP==0)
- {
- delay_1ms(20);
- if(KEY_UP==0)
- {key_scan(1,0); }
- }
- if(KEY_DOWN ==0)
- {
- delay_1ms(20);
- if(KEY_DOWN==0)
- {key_scan(-1,0); }
- }
- if(KEY_LEFT ==0)
- {
- delay_1ms(20);
- if(KEY_LEFT==0)
- {key_scan(0,-1); }
- }
- if(KEY_RIGHT ==0)
- {
- delay_1ms(20);
- if(KEY_RIGHT==0)
- {key_scan(0,-1); }
- }
- if(KEY_START ==0)
- {
- delay_1ms(20);
- if(KEY_LEFT==0)
- { Lcd_ClearScreen();
- shuaxin();
- }
- }
- }
- }
复制代码
|