自己搞了半天,也沒出來,求大佬幫我看看 顯示三個數(shù)字,lcd只能顯示三個方塊,其他的顯示都沒問題,哪里出現(xiàn)問題了嗎??
if(set==3)
{
write_com(0x38);
write_com(0x01);
Display_data();
write_com(0x80+0x40+4);
write_data(bj1);
write_data(bj2);
write_data(bj3);
FENG=1;
}//按鍵三次時lcd顯示的內(nèi)容
uchar bj1=0,bj2=0,bj3=0;
void time0_int(void) interrupt 1 //bj1-3在中斷里賦值了
{
uchar count;
TL0=0xb0;
TH0=0x3c;
count++;
if(count==10)
{
count=0;
if(flag2==0)
LED_Y=1;
else
LED_Y=0;
if(flag7==0)
LED_R=1;
else
LED_R=0;
if(flag2==1&&flag7==0)
{
FENG=!FENG;
jdq1=1;
jdq2=0;
bj1=1;
}
if(flag2==0&&flag7==1)
{
FENG=!FENG;
jdq1=1;
jdq2=0;
bj2=1;
}
if(flag2==1&&flag7==1)
{
FENG=!FENG;
jdq1=1;
jdq2=0;
bj3=1 ;
}
if(flag2==0&&flag7==0)
{
FENG=1;
jdq1=0;
jdq2=1;
}
}
}
****************display.h頭文件*****************
- //宏定義
- #define uint unsigned int
- #define uchar unsigned char
- //LCD管腳聲明
- sbit LCDRS = P1^0;
- sbit LCDEN = P1^1;
- //初始畫時顯示的內(nèi)容
- uchar code Init1[]="HY : YW: ";
- uchar code Init2[]="HH : HY: ";
- uchar code Init3[]=" ALARM RECORDS ";
- //LCD延時
- void LCDdelay(uint z)
- {
- uint x,y;
- for(x=z;x>0;x--)
- for(y=10;y>0;y--);
- }
- //寫命令
- void write_com(uchar com)
- {
- LCDRS=0;
- P0=com;
- LCDdelay(5);
- LCDEN=1;
- LCDdelay(5);
- LCDEN=0;
- }
- //寫數(shù)據(jù)
- void write_data(uchar date)
- {
- LCDRS=1;
- P0=date;
- LCDdelay(5);
- LCDEN=1;
- LCDdelay(5);
- LCDEN=0;
- }
- //1602初始化
- void Init1602()
- {
- write_com(0x38);//屏幕初始化
- write_com(0x0c);//打開顯示 無光標 無光標閃爍
- write_com(0x06);//當讀或?qū)懸粋字符是指針后一一位
- write_com(0x01);//清屏
- }
- void Display_1602(uchar NOW_GAS,uchar NOW_CO,uchar SET_GAS,uchar SET_CO)
- {
- uchar i=0;
- write_com(0x80);//設(shè)置位置
- for(i=0;i<16;i++)
- {
- write_data(Init1[i]);
- }
- write_com(0x80+0x40);//設(shè)置位置
- for(i=0;i<16;i++)
- {
- write_data(Init2[i]);
- }
- write_com(0x80+4);
- write_data('0'+NOW_GAS/100);
- write_data('0'+NOW_GAS/10%10);
- write_data('0'+NOW_GAS%10);
- write_com(0x80+0x40+4);
- write_data('0'+SET_GAS/100);
- write_data('0'+SET_GAS/10%10);
- write_data('0'+SET_GAS%10);
- write_com(0x80+13);
- write_data('0'+NOW_CO/100);
- write_data('0'+NOW_CO/10%10);
- write_data('0'+NOW_CO%10);
- write_com(0x80+0x40+13);
- write_data('0'+SET_CO/100);
- write_data('0'+SET_CO/10%10);
- write_data('0'+SET_CO%10);
- }
- void Display_data()
- {
- uchar j=0;
- write_com(0x80);//設(shè)置位置
- for(j=0;j<16;j++)
- {
- write_data(Init3[j]);
- }
- }
復(fù)制代碼
|