Intel模式下驱动DS12C887.pdf
Designed byKunwin99Kunwin99DB0.7D0D1D2D3D4D5D6D7ENRW1RSASRW2DSCSDB0DB1DB2DB3DB4DB5DB6DB7RSRW1ENASRW2DSCSD0D1D2D3D4D5D6D7D0D1D2D3D4D5D6D7XTAL218XTAL119ALE30EA31PSEN29RST9P0.0/AD039P0.1/AD138P0.2/AD237P0.3/AD336P0.4/AD435P0.5/AD534P0.6/AD633P0.7/AD732P1.01P1.12P1.23P1.34P1.45P1.56P1.67P1.78P3.0/RXD10P3.1/TXD11P3.2/INT012P3.3/INT113P3.4/T014P3.7/RD17P3.6/WR16P3.5/T115P2.7/A1528P2.0/A821P2.1/A922P2.2/A1023P2.3/A1124P2.4/A1225P2.5/A1326P2.6/A1427U1AT89C51X1CRYSTALC122pFC222pFC310uFR110kR2100RESET18SQW23AS14R/W15DS17CS13IRQ19MOT1AD0.7VCC24GND12U2DS12C8872 3 4 5 6 7 8 91RP1RESPACK-8D714D613D512D411D310D29D18D07E6RW5RS4VSS1VDD2VEE3LCD1LM016L在在IntelIntel模式下模式下驱动驱动DS12887DS12887/*程序的功能:通过在 Intel 模式下驱动 ds12887,要求理解 Intel 模式总线读写的时序图;调试程序所发现的问题:1通过参照对比 Intel 模式下读写时序图和自己所编写的程序,深沉次的理解领悟Intel 模式;AS:在其下降沿会将数据总线上的地址数据锁存,DS:在写时序中一直为高电平,表示操作为禁止读;在读时序中上升沿会使 ds12887 将数据传送到总线上供单片机读取;RW:在读时序中一直为高电平,表示操作为禁止写;在写时序中上升沿会将总线上的数据写入 ds12887 对应的寄存器;*/#include#include#define uchar unsigned char#define uint unsigned int#define nop_nop_()sbit lcd_rs=P10;sbit lcd_rw=P11;sbit lcd_en=P25;sbit du=P26;sbit we=P27;sbit ds12887_as=P12;sbit ds12887_rw=P13;sbit ds12887_ds=P14;sbit ds12887_cs=P15;sbit sft=P20;sbit inc=P21;sbit dec=P22;sbit esc=P23;uchar second=10;uchar minute=30;uchar hour=17;uchar day=6;uchar month=12;uchar year=14;uchar week=6;bit modify_flag=0;uchar shift_point;uchar code week_table=SUNMONTUEWENTHRFIRSAT;uchar code num_table=0123456789;void delay(uint t)uint x,y;for(x=t;x0;x-)for(y=110;y0;y-);uchar lcd_read()uchar temp;lcd_rs=0;lcd_rw=1;delay(2);lcd_en=1;delay(2);P0=0 xff;delay(2);temp=P0&0 x80;return temp;void lcd_write(uchar date,uchar flag)uchar temp;temp=lcd_read();if(temp=0)if(flag=1)/如果 flag 为 1 这代表写入数据,反之则代表写入指令lcd_rs=1;;lcd_rw=0;lcd_en=1;delay(2);P0=date;delay(2);lcd_en=0;elselcd_rs=0;lcd_rw=0;lcd_en=1;delay(2);P0=date;delay(2);lcd_en=0;void lcd_init()lcd_en=0;lcd_write(0 x38,0);/初始化设置=16*2 显示,5*7 点阵,8 位数据接口lcd_write(0 x0c,0);/开显示,不显示光标,光标不闪烁;lcd_write(0 x06,0);/读写一个字符后地址指针加 1,且光标加 1,写字符时整屏不移动;lcd_write(0 x01,0);/数据指针清零,所有显示清零uchar ds12887_read(uchar add)/在此函数中去掉对应点的延时后 12887 还可以正常运行uchar temp_date;ds12887_as=1;ds12887_ds=1;ds12887_rw=1;ds12887_cs=0;P3=add;ds12887_as=0;ds12887_ds=0;P3=0 xff;temp_date=P3;ds12887_ds=1;ds12887_as=1;ds12887_cs=1;return temp_date;void ds12887_write(uchar add,uchar date)ds12887_cs=0;ds12887_as=1;ds12887_ds=1;ds12887_rw=1;P3=add;ds12887_as=0;ds12887_rw=0;P3=date;ds12887_rw=1;ds12887_as=1;ds12887_cs=1;void key_scan()if(sft=0)/功能位的调节delay(10);if(sft=0)shift_point+;if(shift_point=8)shift_point=0;if(shift_point!=0)modify_flag=1;elsemodify_flag=0;while(sft=0);if(inc=0)/加delay(10);if(inc=0)switch(shift_point)case 1:second+;if(second=60)second=0;break;case 2:minute+;if(minute=60)minute=0;break;case 3:hour+;if(hour=24)hour=0;break;case 4:day+;if(day=32)day=0;break;case 5:month+;if(month=13)month=0;break;case 6:year+;if(year=100)year=0;break;case 7:week+;if(week=7)week=0;break;while(inc=0);if(dec=0)/减delay(10);if(dec=0)switch(shift_point)case 1:if(second=0)second=60;second-;break;case 2:if(minute=0)minute=60;minute-;break;case 3:if(hour=-1)hour=23;hour-;break;case 4:day-;if(day=-1)day=31;break;case 5:month-;if(month=-1)month=12;break;case 6:year-;if(year=-1)year=99;break;case 7:week-;if(week=-1)week=6;break;while(dec=0);if(esc=0)delay(10);if(esc=0)shift_point=0;modify_flag=0;while(esc=0);void ds12887_init()ds12887_write(0 x0a,0 x20);/晶体振荡器开启且保持时钟运行ds12887_write(0 x0b,0 x06);/芯片更新禁止,设置时钟为 24 小时制,同时寄存器数据存储格式为二进制ds12887_write(0 x00,second);/向 DS12887 写入时间和日期ds12887_write(0 x02,minute);ds12887_write(0 x04,hour);ds12887_write(0 x06,week);ds12887_write(0 x07,day);ds12887_write(0 x08,month);ds12887_write(0 x09,year);void lcd_display()lcd_write(0 x80+1,0);/界面初始化lcd_write(num_table2,1);lcd_write(num_table0,1);lcd_write(num_tableyear/10,1);lcd_write(num_tableyear%10,1);lcd_write(-,1);lcd_write(num_tablemonth/10,1);lcd_write(num_tablemonth%10,1);lcd_write(-,1);lcd_write(num_tableday/10,1);lcd_write(num_tableday%10,1);lcd_write(,1);lcd_write(week_table3*week,1);lcd_write(week_table3*week+1,1);lcd_write(week_table3*week+2,1);lcd_write(0 x80+0 x40+4,0);lcd_write(num_tablehour/10,1);lcd_write(num_tablehour%10,1);lcd_write(:,1);lcd_write(num_tableminute/10,1);lcd_write(num_tableminute%10,1);lcd_write(:,1);lcd_write(num_tablesecond/10,1);lcd_write(num_tablesecond%10,1);void main()uchar K;we=1;P0=0 xff;we=0;du=1;P0=0 xff;du=0;lcd_init();ds12887_init();while(1)key_scan();lcd_display();K=ds12887_read(0 x0a);K=K&0 x80;if(modify_flag=0)&(K=0)second=ds12887_read(0);minute=ds12887_read(2);hour=ds12887_read(4);week=ds12887_read(6);day=ds12887_read(7);month=ds12887_read(8);year=ds12887_read(9);if(modify_flag=1)ds12887_write(0 x00,second);ds12887_write(0 x02,minute);ds12887_write(0 x04,hour);ds12887_write(0 x06,week);ds12887_write(0 x07,day);ds12887_write(0 x08,month);ds12887_write(0 x09,year);