哪位大神能把我这个程序加个能在1602上显示星期的,搞了很久实在是搞不出来,希望有大神能点拨一下,十万分感谢
#include<reg51.h>
#define uchar unsigned char
#define uint unsigned int
#define DATA P0
sbit RS=P2^3;
sbit RW=P1^5;
sbit EN=P1^6;
uint year=2016,month,day,hour,min,sec,count;
uchar code table[]={0x30,0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39};//定义0-9字符。
/*--------------延时函数---------------------------------*/
void delay(uint num)
{
uint x,y;
for(x=num;x>0;x--)
for(y=110;y>0;y--);
}
/*--------------写指令---------------------------------*/
void write_comd(uchar comd)
{
RS=0;
RW=0;
DATA=comd;
delay(5);
EN=1;
delay(5);
EN=0;
}
/*--------------写数据---------------------------------*/
void write_dat(uchar dat)
{
RS=1;
RW=0;
DATA=dat;
delay(5);
EN=1;
delay(5);
EN=0;
}
/*--------------屏幕初始化---------------------------------*/
void lcd_init()
{
write_comd(0x02);//归位
write_comd(0x06);//设置输入方式
write_comd(0x0c);//控制显示开关
write_comd(0x3c);//功能设置?
write_comd(0x01);//清屏
}
/*--------------初值---------------------------------*/
void Init_
time()
{
EA=1;
ET0=1;
TMOD=0X01;
TH0=(65536-30000)/256;
TL0=(65535-30000)/256;
TR0=1;
}
/*---------------定义工作方式---------------------*/
void lcd_timer() interrupt 1
{
TH0=(65536-50000)/256;
TL0=(65535-50000)/256;
count++;
if(count==20)
{
count=0;
sec++;
if(sec==5) //秒计时
{
sec=0;
min++;
if(min==3)//分计时
{
min=0;
hour++;
if(hour==2)
{
hour=0;
day++;
if(day==10)
{
day=0;
month++;
if(month==12)
{
month=0;
year++;
}
}
}
}
}
}
}
/*--------------显示分秒---------------------------------*/
void lcd_display(uint miao,uint fen,uint shi)
{
write_comd(0xc0);//显示字母
write_dat(0x54);
write_dat(0x69);
write_dat(0x4d);
write_dat(0x45);
write_dat(':');
write_dat(table[shi/10]);
write_dat(table[shi%10]);
write_dat(':');
write_dat(table[fen/10]);
write_dat(table[fen%10]);
write_dat(':');
write_dat(table[miao/10]);
write_dat(table[miao%10]);
write_comd(0x80);
write_dat(table[year/1000]);
write_dat(table[year/100%10]);
write_dat(table[year/10%10]);
write_dat(table[year%10]);
write_dat(':');
write_dat(table[month/10]);
write_dat(table[month%10]);
write_dat(':');
write_dat(table[day/10]);
write_dat(table[day%10]);
write_dat(0x2d);
}
/*--------------主函数---------------------------------*/
void main()
{
RW=0;
RS=0;
EN=0;
Init_time();
lcd_init();
while(1)
{
lcd_display(sec,min,hour);
}
}
一周热门 更多>