完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
proteus 仿真程序,结果1602 只亮不显示,数据端全处于高位。 ![]() LCD子程序如下(仿真proteus文件在附件): #include"LCD1602.h" #include"delay.h" xdata LCD_Type LCD; static void LCD_CheckBusy(void) { do { LCD_EN=0; LCD_RS=0; LCD_RW=1; LCDIO=0xff; LCD_EN=1; } while(LCD_BUSY==1); LCD_EN=LOW; } static void LCD_SendCommand(unsigned char command) { LCD_CheckBusy(); LCD_RS=LOW; LCD_RW=LOW; LCD_EN=HIGH; LCDIO=command; LCD_EN=LOW; } static void LCD_SendData(unsigned char dat) { LCD_CheckBusy(); LCD_RS=HIGH; LCD_RW=LOW; LCD_EN=HIGH; LCDIO=dat; LCD_EN=LOW; } static void LCD_Pos(unsigned char pos) { if(pos>31) return; if(pos<16) { LCD_SendCommand(0x80+pos); } else { LCD_SendCommand(0xC0+pos-16); } } void LCD_DisplayString(unsigned char add,unsigned char *str) { unsigned char i; LCD.RefFlag=0; i=0; while(*str) { LCD.Buf[add+i]=*str; str++; i++; } LCD.RefFlag=1; } void LCD_ScreenClear(void) { unsigned char i = 0; LCD.RefFlag=0; for(i=0;i<32;i++) { LCD.Buf=' '; } LCD.RefFlag=1; } void LCD_Init(void) { LCD_SendCommand(0x38); LCD_SendCommand(0x38); LCD_SendCommand(0x38); LCD_SendCommand(0x06); LCD_SendCommand(0x0c); LCD_SendCommand(0x01); LCD.BlinkEN =0; LCD.BlinkAdd =0; LCD.BlinkLen =1; LCD.BlinkCon =0; LCD_ScreenClear(); } void LCD_Refresh(void) { unsigned char i = 0; if(LCD.BlinkEN) { LCD.BlinkCon++; if(LCD.BlinkCon==1) { LCD_Pos(LCD.BlinkAdd); for(i=0;i { if(LCD.BlinkAdd+i==16) LCD_Pos(16); LCD_SendData(0x20); } } else if(LCD.BlinkCon==10) { LCD_Pos(LCD.BlinkAdd); for(i=0;i { if(LCD.BlinkAdd+i==16) LCD_Pos(16); LCD_SendData(LCD.Buf[LCD.BlinkAdd+i]); } } else if(LCD.BlinkCon>=20) { LCD.BlinkCon=0; LCD.RefFlag =1; } } if(LCD.RefFlag == 1) { LCD_Pos(0); for(i=0;i<32;i++) { if(i==16) LCD_Pos(16); if((LCD.BlinkEN)&&(i==LCD.BlinkAdd)) { do { i++; } while(i<(LCD.BlinkAdd+LCD.BlinkLen)); LCD_Pos(LCD.BlinkAdd+LCD.BlinkLen+1); } else { LCD_SendData(LCD.Buf); } } LCD.RefFlag=0; } } //时分秒 void LCD_DisplayTime(unsigned char add,unsigned char *time) { LCD.RefFlag = 0; LCD.Buf[add+0] = time[0]/10+'0'; LCD.Buf[add+1] = time[0]%10+'0'; LCD.Buf[add+2] = ':'; LCD.Buf[add+3] = time[1]/10+'0'; LCD.Buf[add+4] = time[1]%10+'0'; LCD.Buf[add+5] = ':'; LCD.Buf[add+6] = time[2]/10+'0'; LCD.Buf[add+7] = time[2]%10+'0'; LCD.RefFlag = 1; } //年月日 void LCD_DisplayDate(unsigned char add,unsigned char *date) { LCD.RefFlag = 0; LCD.Buf[add+0] = '2'; LCD.Buf[add+1] = '0'; LCD.Buf[add+2] = date[0]/10+'0'; LCD.Buf[add+3] = date[0]%10+'0'; LCD.Buf[add+4] = '-'; LCD.Buf[add+5] = date[1]/10+'0'; LCD.Buf[add+6] = date[1]%10+'0'; LCD.Buf[add+7] = '-'; LCD.Buf[add+8] = date[2]/10+'0'; LCD.Buf[add+9] = date[2]%10+'0'; LCD.Buf[add+10]= 0x20; switch(date[3]) { case 1: {LCD_DisplayString(add+11,"Mon");}break; case 2: {LCD_DisplayString(add+11,"Tue");}break; case 3: {LCD_DisplayString(add+11,"Wed");}break; case 4: {LCD_DisplayString(add+11,"Thu");}break; case 5: {LCD_DisplayString(add+11,"Fri");}break; case 6: {LCD_DisplayString(add+11,"Sat");}break; case 7: {LCD_DisplayString(add+11,"Sun");}break; default:break; } LCD.RefFlag = 1; } void DisplayU16(unsigned char add,unsigned int num,unsigned char hide) { xdata unsigned char temp[6]={0}; unsigned char i =0; for(i=0;i<5;i++) { temp[4-i] = num %10 +'0'; num= num/10; } temp[5]=' |