CODE C
Các bạn chú ý biên dịch bằng phần mềm Keil C nhé.
/*****WWW.ChipKool.Net*****Simple Is The Best********/
#include "reg52.h"
#include "stdio.h"
sbit RS_LCD = P3^0;
sbit RW_LCD = P3^1;
sbit E_LCD = P3^2;
unsigned int i,a=0;
//---------------
void delay_short()
{
unsigned int i;
for(i=0;i<3;i++){}
}
//--------------
void delay(unsigned int ms)// delay 1ms
{
unsigned int x,y;
for(x=0;x<ms;x++) {
for(y=0;y<125;y++) {
}
}
}
//--------------
void kt_ban(){
unsigned char x;
P2 = 0xff;
RS_LCD = 0;
RW_LCD = 1;
do {
E_LCD = 1;
delay_short();
E_LCD = 0;
x=P2;
x=x&0x80;
}
while(x!=0x80);
}
//----------------
void ghi_lenh(unsigned char commant){
kt_ban();
delay(50);
P2 = commant;
RS_LCD = 0; // chon thanh ghi lenh
RW_LCD = 0; // write to LCD
E_LCD = 1;
delay_short();
E_LCD = 0;
}
//-----------------
void ghi_kytu(unsigned char kytu){
kt_ban();
delay(30);
P2 = kytu;
RS_LCD = 1;
RW_LCD = 0;
E_LCD =1;
delay_short();
E_LCD = 0;
}
/*/------------------
void ghi_nhanh ( unsigned char kytu){
delay_short();
P1 = kytu;
RS_LCD = 1;
RW_LCD = 0;
E_LCD = 1;
delay_short();
E_LCD = 0;
}
*///-------------------
void ghi_chuoi(char *str){
while(*str){
ghi_kytu(*str);
str++;
}
}
/*/-------------------
void ghi_nhanh_chuoi(char *str){
while(*str){
ghi_nhanh(*str);
str++;
}
} */
//-------------------
void setting(){
ghi_lenh(0x38);
ghi_lenh(0x01); //Xoa man hinh
ghi_lenh(0x0f); //Co dich hien thi
ghi_lenh(0x0c); //Bat hien thi ,tat con tro
}
void hienthi()
{
if(P1==0xee){
a=1;
ghi_lenh(0x01);
ghi_lenh(0x80+3);
ghi_chuoi("Phim so 1");
}
if(P1==0xde){
a=2;
ghi_lenh(0x01);
ghi_lenh(0x80+3);
ghi_chuoi("Phim so 2");
}
if(P1==0xbe){
ghi_lenh(0x01);
ghi_lenh(0x80+3);
ghi_chuoi("Phim so 3");
}
if(P1==0x7e){
ghi_lenh(0x01);
ghi_lenh(0x80+3);
ghi_chuoi("Phim so 4");
}
if(P1==0xed){
ghi_lenh(0x01);
ghi_lenh(0x80+3);
ghi_chuoi("Phim so 5");
}
if(P1==0xdd){
ghi_lenh(0x01);
ghi_lenh(0x80+3);
ghi_chuoi("Phim so 6");
}
if(P1==0xbd){
ghi_lenh(0x01);
ghi_lenh(0x80+3);
ghi_chuoi("Phim so 7");
}
if(P1==0x7d){
ghi_lenh(0x01);
ghi_lenh(0x80+3);
ghi_chuoi("Phim so 8");
}
if(P1==0xeb){
ghi_lenh(0x01);
ghi_lenh(0x80+3);
ghi_chuoi("Phim so 9");
}
if(P1==0xdb){
ghi_lenh(0x01);
ghi_lenh(0x80+3);
ghi_chuoi("Phim so 10");
}
if(P1==0xbb){
ghi_lenh(0x01);
ghi_lenh(0x80+3);
ghi_chuoi("Phim so 11");
}
if(P1==0x7b){
ghi_lenh(0x01);
ghi_lenh(0x80+3);
ghi_chuoi("Phim so 12");
}
if(P1==0xe7){
ghi_lenh(0x01);
ghi_lenh(0x80+3);
ghi_chuoi("Phim so 13");
}
if(P1==0xd7){
ghi_lenh(0x01);
ghi_lenh(0x80+3);
ghi_chuoi("Phim so 14");
}
if(P1==0xb7){
ghi_lenh(0x01);
ghi_lenh(0x80+3);
ghi_chuoi("Phim so 15");
}
if(P1==0x77){
ghi_lenh(0x01);
ghi_lenh(0x80+3);
ghi_chuoi("Phim so 16");
}
}
void quetphim(void)
{
int n[5] = {0xfe,0xfd,0xfb,0xf7};
for (i=0; i<5;i++)
{
P1 = n[i];
hienthi();
}
}
void main()
{ setting();
ghi_lenh(0x01);
ghi_lenh(0x80);
ghi_chuoi("http://");
ghi_lenh(0xc0);
ghi_chuoi("www.Chipkool.net");
delay(300);
ghi_lenh(0x01);
ghi_lenh(0x80);
ghi_chuoi("Moi ban chon phim ??");
while(1)
{
quetphim();
}
}
Nguồn: Blog Điện Tử | Tin Học - Chia sẻ kiến Thức - Kết nối đam mê điện tử
Đăng nhận xét