void wait(void) { long n = 0; EN=1;// Dua chan cho fep len cao RS=0;// Chon thanh ghi lenh RW=1;// Doc tu LCD
LCD_PORT=0xFF;// Gia tri 0xFF while(1){n++; if(n>100) break;}// Kiem tra co ban // Neu ban dem n den 100 roi thoat khoi while EN=0;// Dua xung cao xuong thap de chot RW=0;// Doc tu LCD } void delay(long time) /* ham delay */ { long n; for(n=0;n{;} } void delay_5ms(){ int i,j; for(i=0;i<250;i++) for(j=0;j<4;j++){} } void delay_15ms(){ int i,j; for(i=0;i<250;i++) for(j=0;j<100;j++){} } void LCDWriteCmd(unsigned char c) { RS=0; RW=0; LCD_PORT=c; EN=1; EN=0; delay_5ms();
LCDWriteCmd(0x30); //che do 8 bit LCDWriteCmd(0x30); LCDWriteCmd(0x30); LCDWriteCmd(0x38); //hien thi 2 dong LCDWriteCmd(0x0C); //bat con tro // LCDWriteCmd(0x06); //dich con tro sang ben phai LCDWriteCmd(0x01); // Xoa man hinh LCD } void LCD_clear() { LCDWriteCmd(0x01); } void LCD_home() { LCDWriteCmd(0x80); //ep con tro ve dau dong
} void LCD_putstr(unsigned char *s) { while (*s) { LCDWriteData(*s); s++; } } void LCDwritei(long d) { unsigned int i,j; unsigned char a[7]; a[6]=d%10; d=d/10; a[5]=d%10; d=d/10; a[4]=d%10; d=d/10; a[3]=d%10;// Chia lay phan du, duoc chu so hang don vi d=d/10;// Chia lay phan nguyen, duoc nhung chu so da bo hang don vi a[2]=d%10;// Duoc chu so hang chuc d=d/10;// Nhung chu so da bo hang don vi va hang chuc a[1]=d%10;// Duoc hang tram d=d/10;// Duoc chu so da bo hang don vi, chuc, tram a[0]=d%10;// Duoc hang ngan for(i=0;i<7;i++) { if(a!=0) break; }
for(j=i;j<7;j++) { LCDWriteData(48+a[j]); } }
/***************************Ham quet phim************************/ void quetphim() { int y; P2=0x0f; if((!cot0)|(!cot1)|(!cot2)|(!cot3)) { for(y=0;y<5000;y++){ if(cot0==0) //neu la hang 0 { hang0=1; hang1=1; hang2=1; hang3=1; cot0=0; if(!hang0) sttphim=0; if(!hang1) sttphim=1; if(!hang2) sttphim=2; if(!hang3) sttphim=3; } else if(cot1==0) //neu la hang 1 { hang0=1; hang1=1;