題目:在LCD1602顯示屏上顯示滿足條件: 1、在第一行顯示“000-999 CLOCK”
本文引用地址:http://m.butianyuan.cn/article/201611/320190.htm 2、在第二行末尾顯示“BY XIAO WU”
3、在第二行起首用三位顯示000-999跑表
4、循環(huán)下去
解決方案:(C語言編程)
#include
#define uchar unsigned char
#define uint unsigned int
uchar code table[]="000-999 CLOCK";
uchar code table1[]="BY XIAO WU";
uchar code tabledu[]={0x30,0x31,0x32,0x33,0x34,0x35,0x36,
0x37,0x38,0x39}; //數(shù)據(jù)0~9
uchar bai,shi,ge,num,flag;
uint shu;
sbit lcdrs=P1^7; //端口定義
sbit lcdrw=P1^6;
sbit lcde=P2^4;
sbit le=P3^6;
sbit leden=P2^5;
sbit dkle=P3^7;
void delay(uint a) ;//函數(shù)聲明
void display();
void write_com(uchar com) //寫命令子函數(shù)
{
lcde=0;
lcdrw=0;
lcdrs=0;
delay(1);
lcde=1;
delay(1);
P0=com;
delay(1);
lcde=0;
}
void write_data(uchar dat)//寫數(shù)據(jù)子函數(shù)
{
lcde=0;
lcdrw=0;
lcdrs=1;
delay(1);
lcde=1;
delay(1);
P0=dat;
delay(1);
lcde=0;
}
void init()
{
shu=0; //計數(shù)值初始化
bai=0;
shi=0;
ge=0;
TMOD=0x01;//定時器初始化
TH0=0xd8;
TL0=0xf0;
EA=1;
ET0=1;
TR0=1;
lcde=0; //LCD1602初始化
le=0;
leden=0;
write_com(0x38);
write_com(0x0c);
write_com(0x01);
write_com(0x80);
for(num=0;num<13;num++) //在第一行顯示“000-999 CLOCK”
{
write_data(table[num]);
}
write_com(0x80+0x45);
for(num=0;num<10;num++) //在第二行末尾顯示“BY XIAO WU”
{
write_data(table1[num]);
}
}
void main() //main函數(shù)
{
init();
write_com(0x80+0x40);
delay(100);//延時1s
while(1)
{
if(flag==1)
{
flag=0;
display();
}
}
}
void time0() interrupt 1//中斷子函數(shù)
{
TH0=0xd8;
TL0=0xf0;
flag=1;
}
void display()//顯示子函數(shù)
{
shu++;
if(shu==999)
shu=0;
bai=shu/100;
shi=shu%100/10;
ge=shu%10;
write_data(tabledu[bai]);
write_data(tabledu[shi]);
write_data(tabledu[ge]);
write_com(0x80+0x40);
}
void delay(uint a) { //延時子函數(shù)
uint i,j;
for(j=a;j>0;j--)
for(i=2500;i>0;i--) ;
}
評論