#include <regx52.h>
#define SDI P2_1
#define CLK P2_0
#define STR P2_2
bit RS,EN,RW=0;
unsigned char Data;
void delay(unsigned int tre)
{while(tre--);}
void ghi(unsigned char ms)
{unsigned char i,Q;
Q=ms; for(i=0;i<8;i++){SDI=(Q&0x80)?1:0;CLK=1;CLK=0;Q<<=1; }
STR=0; STR=1;
}
//_________________________hàm tre LCD ____________________________________________________
void delayLCD()
{
unsigned int lcd;
for (lcd=0; lcd<100; lcd++);
}
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);
}
//_________________________Ham hien thi 1 xau ra lcd:___________________________________________
void hienthi_kt(unsigned char *s)
{
ghilenh(0x80);
while(*s)
ghikt(*s++);
}
//__________________________Ham khoi tao LCD:____________________________________________________
void khoitao()
{
ghilenh(0x33);
ghilenh(0x32);
ghilenh(0x28); // 4-bit, 2 hang, ma tran 5x7
ghilenh(0x0C); // bat hien thi, tat con tro
ghilenh(0x06); // dich con tro sang phai
ghilenh(0x01); // xoa man hinh
}
void main()
{ khoitao();
while(1)
{
ghilenh(0x80);
hienthi_kt("Connect.. \nCHIPKOOL.TK");
}
}
(38.89kb)
Khi nhấn nút "Tải Về Máy", bạn sẽ vào trang quảng cáo, vui lòng chờ 5 giây. Nút hiện ra ở góc phải phía trên, nhấn vào để đến trang download
Phạm Văn Ngọc Anh-01644326695
Nguồn PCBviet.com
Đăng nhận xét