error属于数组table0[],应该不显示才对,求解
主程序:
- #include <reg52.h>
- #define uchar unsigned char
- sbit ledg=P1^0;
- sbit ledr=P1^7;
- sbit buzz=P1^4;
- char table0[]="error";
- char table1[]="open";
- char table2[]="password:****";
- extern void InitLcd1602();
- extern void LcdShowStr(unsigned char x, unsigned char y, unsigned char *str);
- unsigned char shuzi;
- unsigned char shuzi1[4];char mima[4]="0000";
- extern void KeyScan();
- extern unsigned char key_scan(void);
- void main()
- {
- int biaozhi=0;
- int i=0;
- InitLcd1602();
- LcdShowStr(0,0,table2);
- while(1)
- {
- shuzi=key_scan();
- if(shuzi>='0'&&shuzi<='9')
- {
- shuzi1[i]=shuzi;
- i++;
- if(i>=4)
- {
- i=0;
- }
- }
- if(shuzi=='g')
- {
- biaozhi=1;
- }
- if(shuzi=='f')
- {
- biaozhi=0;
- }
- if(biaozhi==1)
- {
- mima[0]=shuzi1[0];
- mima[1]=shuzi1[1];
- mima[2]=shuzi1[2];
- mima[3]=shuzi1[3];
- }
- LcdShowStr(0,1,mima);
- LcdShowStr(9,0,shuzi1);
- }
- }
- lcd程序:
- #include <reg52.h>
- #define LCD1602_DB P0
- sbit LCD1602_RS = P2^0;
- sbit LCD1602_RW = P2^1;
- sbit LCD1602_E = P2^2;
- /* μè′yòo¾§×¼±¸oà */
- void LcdWaitReady()
- {
- unsigned char sta;
- LCD1602_DB = 0xFF;
- LCD1602_RS = 0;
- LCD1602_RW = 1;
- do {
- LCD1602_E = 1;
- sta = LCD1602_DB;
- LCD1602_E = 0;
- } while (sta & 0x80);
- }
- void LcdWriteCmd(unsigned char cmd)
- {
- LcdWaitReady();
- LCD1602_RS = 0;
- LCD1602_RW = 0;
- LCD1602_DB = cmd;
- LCD1602_E = 1;
- LCD1602_E = 0;
- }
- void LcdWriteDat(unsigned char dat)
- {
- LcdWaitReady();
- LCD1602_RS = 1;
- LCD1602_RW = 0;
- LCD1602_DB = dat;
- LCD1602_E = 1;
- LCD1602_E = 0;
- }
- void LcdSetCursor(unsigned char x, unsigned char y)
- {
- unsigned char addr;
- if (y == 0)
- addr = 0x00 + x;
- else
- addr = 0x40 + x;
- LcdWriteCmd(addr | 0x80);
- }
- void LcdShowStr(unsigned char x, unsigned char y, unsigned char *str)
- {
- LcdSetCursor(x, y);
- while (*str != '\0')
- {
- LcdWriteDat(*str++);
- }
- }
- /* 3õê¼»ˉ1602òo¾§ */
- void InitLcd1602()
- {
- LcdWriteCmd(0x38);
- LcdWriteCmd(0x0C);
- LcdWriteCmd(0x06);
- LcdWriteCmd(0x01);
- }
复制代码
|