E=0;
P0=cmd;
delay_us(5);
E=1;
E=0;
}
void write_data(uchar dat)
{
busy_wait();
RS=1;
RW=0;
E=0;
P0=dat;
delay_us(5);
E=1;
E=0;
}
void initial_lcd(void)
{
write_command(0x01); //清空led
write_command(0x10); //字符进入模式,屏幕不动,字符右移06、10,14,1c和16没区别,18不显示
write_command(0x0c); //显示器打开
write_command(0x38); //8位数据传输,双行显示,5*7
}
void lcd_show_string(uchar r,uchar c,uchar *str)
{
uchar i=0;
uchar code ddram[]={0x80,0xc0,0x94,0xd4}; //LM044L的
write_command(ddram[r] | c); //显示地址
for(i=0;str[i] && i<16;i++) //LM044L的
write_data(str[i]);
for(;i<16;i++) //不足一行用空格补齐
write_data(' ');
}
//PCF8583时钟芯片配置和初始化
char week[][4]={"SUN","MON","TUS","WEN","THU","FRI","SAT"};
uchar PCF8583_DATA[5],DateTime[7];
uchar second=8,minuter=8,hour=8,date=2,month=4,year=2017;
uchar flag=1;
/*从PCF8583内部寄存器addr处开始,读取n个字符型数存到buf缓冲区中*/
void Read_PCF8583(uchar addr,uchar *buf,uchar n)
{
uchar i;
iic_start();
send_bayte(PCF8583_ADDR_WR);
send_bayte(addr);
iic_start();
send_bayte(PCF8583_ADDR_RD);
for(i=0;i<n-1;i++)
{
buf[i]=read_bayte();
send_ack(0);
}论文网
buf[n-1]=read_bayte();
send_ack(1);
iic_stop();
}
/************** 10进制转BCD ***************************/
unsigned char bcd_10_dec(unsigned char bat)
{
unsigned char temp1, temp2, temp3, temp4, tol;
temp3 = bat / 10; //分离十位
temp4 = bat % 10; //分离个位
temp1 = (temp3 << 4) & 0xf0; //移到高4位
temp2 = (temp4 & 0x0f);
tol = temp1 | temp2;
return tol;
}
void Write_PCF8583(uchar addr,uchar val)
{
iic_start();
send_bayte(PCF8583_ADDR_WR);
send_bayte(addr);
send_bayte(val);
iic_stop();
}
/*void GetDateTime(void)将读取到的数据处理后发到DateTime[]*/
void GetDateTime()
{
// uchar send1,send2,send3,send4,send5,send6;
// send1=bcd_10_dec(second);
// send2=bcd_10_dec(minuter);
// send3=bcd_10_dec(hour);
// send4=bcd_10_dec(date);
// send5=bcd_10_dec(month);
// 51单片机电子万年历系统的设计+PCB电路图(5):http://www.youerw.com/zidonghua/lunwen_202275.html