EEPW首頁 > 嵌入式系統(tǒng) > 設(shè)計應(yīng)用 > 基于單片機(jī)的電子萬年歷
#include
#define uchar unsigned char
#define uint unsigned int
sbit dula=P3^7;
sbit wela=P2;
sbit rs=P2^5;
sbit rw=P2^6;
sbit s1=P1^0;
sbit s2=P1^1;
sbit s3=P1^2;
sbit rd=P1^7;
sbit lcden=P2^7;
uchar count,s1num;
char shi,fen,miao;
uchar code table[]=" 2013-4-19 FRI" ;
uchar code table1[]=" 00:00:00";
void delay(uint z) 延時函數(shù) delay(5)就是5ms
{
uint x,y;
for(x=z;x>0;x--)
for(y=110;y>0;y--);
}
void write_com(uchar com)
{
rs=0;
rw=0;
lcden=0;
P0=com;
delay(5);
lcden=1;
delay(5);
lcden=0;
}
void write_data(uchar date)
{
rs=1;
rw=0;
lcden=0;
P0=date;
delay(5);
lcden=1;
delay(5);
lcden=0;
}
void init()
{
uchar num;
dula=0;
lcden=0;
rd=0;
// fen=59;
// miao=53;
// shi=23;
write_com(0x38);
write_com(0x0c);
write_com(0x06);
write_com(0x01);
write_com(0x80);
for(num=0;num<15;num++)
{
write_data(table[num]);
delay(5);
}
write_com(0x80+0x40);
for(num=0;num<11;num++)
{
write_data(table1[num]);
delay(5);
}
TMOD=0x01;
TH0=0x4c;
TL0=0x00;
EA=1;
ET0=1;
TR0=1;
評論