void mahoa(unsigned char d1,bit d2,bit d3,bit d4)
{
Data=0x00;
Data=Data|(d1>>4);
// ghi EN
Data<<=1;
Data|=d2;
// ghi RW
Data<<=1;
Data|=d3;
Data<<=1;
Data|=d4;
ghi(Data);
}
//_________________________Ham ghi lenh ra LCD:______________________________________________
void ghilenh(unsigned char lenh)
{ unsigned char tg;
// ghi 4 bit cao
RS = 0;
tg=lenh & 0xF0;
EN=0;
mahoa(tg,EN,RW,RS);
delayLCD();
EN=1;
mahoa(tg,EN,RW,RS);
//ghi 4 bit thap
tg=(lenh<<4)&0xf0;
EN=0;
mahoa(tg,EN,RW,RS);
delayLCD();
EN=1;
mahoa(tg,EN,RW,RS);
}
//__________________________ham ghi ki tu ra LCD:_____________________________________________
void ghikt(unsigned char kt)
{ unsigned char tg;
RS = 1;
if(kt=='\n'){ghilenh(0xC0);return;}
tg=kt & 0xF0;
EN=0;
mahoa(tg,EN,RW,RS);
delayLCD();
EN=1;
mahoa(tg,EN,RW,RS);
//ghi 4 bit thap
tg=(kt<<4)&0xf0;
EN=0;
mahoa(tg,EN,RW,RS);
delayLCD();
EN=1;
mahoa(tg,EN,RW,RS);
}
Không có nhận xét nào:
Đăng nhận xét