- //1602
- #define uchar unsigned char
- #define uint unsigned int
- sbit RW=P2^5;
- sbit RS=P2^6;
- sbit LE=P2^7;
- uchar code mun_to_char[] = {"0123456789ABCDEF"}; /*定义数字跟ASCII码的关系*/
- uchar data time_data_buff[7]={0x00,0x00,0x09,0x01,0x01,0x04,0x09};/*格式为: 秒 分 时 日 月 星期 年 */
- uchar data lcd1602_line1[]={"2000-00-00 000"};
- uchar data lcd1602_line2[]={" 00:00:00 00.0"};
- uchar code Weeks[][3]={{"SUN"},{"MON"},{"TUE"},{"WED"},{"THU"},{"FRI"},{"SAT"},{"SUN"}};
- void delay(uint z)
- {
- uint x,y;
- for(x=z;x>0;x--)
- for(y=110;y>0;y--);
- }
- void write_com(uchar date)
- {
- RS=0;
- RW=0;
- P0=date;
- delay(5);
- LE=1;
- // delay(5);
- LE=0;
- }
- void write_date(uchar date)
- {
- RS=1;
- RW=0;
- P0=date;
- delay(5);
- LE=1;
- // delay(5);
- LE=0;
- }
- void RST1602()
- {
- // LE=0;
- write_com(0x38);
- write_com(0x0C);
- write_com(0x01);
- write_com(0x06);
- // write_com(0x80);
- }
- void write_add(uchar x_pos,y_pos,date)
- {
- x_pos&=0x0F;
- y_pos&=0x01;
- if(y_pos==1)x_pos+=0x40;
- x_pos+=0x80;
- write_com(x_pos);
- write_date(date);
- }
- //12887
- sbit DScs=P3^0;
- sbit DSas=P3^1;
- sbit DSrw=P3^2;
- sbit DSds=P3^3;
- sbit DSirq=P3^4;
- sbit beep=P3^5;
- void write_ds12887(uchar add,uchar date)//写12887
- {
- DScs=0;
- DSas=1;
- DSds=1;
- DSrw=1;
- P1=add;
- DSas=0;
- DSrw=0;
- P1=date;
- DSrw=1;
- DSas=1;
- DScs=1;
- }
- uchar read_ds12887(uchar add) //读12887
- {
- uchar date;
- //P1=0xFF;
- DScs=0;
- DSas=1;
- DSds=1;
- DSrw=1;
- P1=add;
- DSas=0;
- DSds=0;
- date=P1;
- DSds=1;
- DSas=1;
- DScs=1;
- return date;
- }
- void SET_12887()
- {
- write_ds12887(0,0x00);//second
- write_ds12887(2,0x00);//minutes
- write_ds12887(4,0x20);//hours
- write_ds12887(6,0x03);//day
- write_ds12887(7,0x25);//date
- write_ds12887(8,0x09);//month
- write_ds12887(9,0x13);//year
- }
- //主函数
- void main()
- {
- uchar i;
- RST1602();
- write_ds12887(0x0B,0x63);
- // SET_12887();
- while(1)
- {
- lcd1602_line1[2] = mun_to_char[read_ds12887(9)/0x10];
- lcd1602_line1[3] = mun_to_char[read_ds12887(9)%0x10]; /*年*/
- lcd1602_line1[5] = mun_to_char[read_ds12887(8)/0x10];
- lcd1602_line1[6] = mun_to_char[read_ds12887(8)%0x10]; /*月*/
- lcd1602_line1[8] = mun_to_char[read_ds12887(7)/0x10];
- lcd1602_line1[9] = mun_to_char[read_ds12887(7)%0x10]; /*日*/
- for(i=0;i<3;i++) lcd1602_line1[i+13]=Weeks[read_ds12887(6)&0x07][i]; /*星期*/
- lcd1602_line2[2] = mun_to_char[read_ds12887(4)/0x10];
- lcd1602_line2[3] = mun_to_char[read_ds12887(4)%0x10]; /*时*/
- lcd1602_line2[5] = mun_to_char[read_ds12887(2)/0x10];
- lcd1602_line2[6] = mun_to_char[read_ds12887(2)%0x10]; /*分*/
- lcd1602_line2[8] = mun_to_char[read_ds12887(0)/0x10];
- lcd1602_line2[9] = mun_to_char[read_ds12887(0)%0x10]; /*秒*/
- for(i=0;i<16;i++) write_add(i,0,lcd1602_line1[i]);
- for(i=0;i<16;i++) write_add(i,1,lcd1602_line2[i]);
- }
- }
复制代码
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
一周热门 更多>