|
100黑币
各位大神 小弟最近在学习DS1302和12864时遇到一个问题实在解决不了 经过测试12864能够正常使用 但是1302读数却不对 转换成十进制数 显示的第一秒是1 第二秒是0 第三秒是3 第四秒是0然后我又将二进制代码显示在12864上 第一秒是00000001 第二秒是00000000 第三秒是00000011 第四秒是00000000 所以我怀疑是1302根本就没读对 然后换了个1302芯片 但是结果是一样的 查了半天资料 就是不知道是怎么回事 希望大神们不吝赐教 万分感谢 以下是代码
这是1302的驱动
这是各种定义- #define uchar unsigned char
- #define uint unsigned int
- sbit LCD_RS=P3^1;
- sbit LCD_RW=P3^6;
- sbit LCD_E=P3^5;
- //1302管脚定义
- sbit SCK=P3^4;
- sbit SDA=P3^3;
- sbit RST=P3^2;
- code uchar table1[]={"2018年07月12日"};
- code uchar table2[]={" 21: 45: 45"};
- code uchar table3[]={"星期四 ,28.9℃"};
- code uchar table4[][7]={"一","二","三","四","五","六","日"};
- code uchar table5[][2]={"-","."};
- code uchar num_tab[][10]={"0","1","2","3","4","5","6","7","8","9"};
- code uchar write_rtc_address[7]={0x80,0x82,0x84,0x86,0x88,0x8a,0x8c}; //1302写入地址
- code uchar read_rtc_address[7]={0x81,0x83,0x85,0x87,0x89,0x8b,0x8d}; //1302读取地址
- uchar l_tmpdate[7]={0,0,23,3,8,11,20};//秒分时日月周年2011-07-14 12:00:00
- uchar l_tmpdisplay[8];
复制代码 这是main函数
- #include "reg52.h"
- #include "defin.h"
- #include "lcd.h"
- #include "intrins.h"
- #include "ds1302.h"
- #include "18b02.h"
- void main()
- {
- uint i=0,j=0;
- delay(400);
-
- LED_init();
- Set_RTC();
-
- LED_wldate(0,0,table1);
- LED_wldate(1,0,table2);
- LED_wldate(2,0,table3);
- LED_wldate(3,0,table4);
- delay(1000);
- LED_wshi(23);
- LED_wfen(23);
- LED_wmiao(23);
- LED_wnian(23);
- LED_wyue(23);
- LED_wri(23);
- LED_wday(0);
- while(1)
-
- {
-
- Read_RTC();
- //显示秒的个位
- /* setpos(1,5);
- j=l_tmpdate[0]%16;
-
- LED_wldate(1,5,num_tab[j]);*/
- //显示秒的二进制
- for(i=0;i<8;i++)
- {
- j=l_tmpdate[0]&0x01;
- l_tmpdate[0]>>=1;
- setpos(3,7-i);
- delay(2);
- LED_wdate(j+0x30);
- delay(2);
- }
-
- delay(5);
-
- }
-
- }
复制代码
这是12864驱动
- void delay(unsigned int time)
- {
- unsigned int i,j;
- for(i=0;i<time;i++)
- for(j=0;j<111;j++);
- }
- void LED_wcmd(uchar cmd)
- {
- LCD_RS=0;
- delay(1);
- LCD_RW=0;
- delay(1);
- LCD_E=1;
- delay(1);
- P2=cmd;
- delay(1);
- LCD_E=0;
- delay(1);
- }
- void LED_wdate(uchar date)
- {
- LCD_RS=1;
- delay(1);
- LCD_RW=0;
- delay(1);
- LCD_E=1;
- delay(1);
- P2=date;
- delay(1);
- LCD_E=0;
- delay(1);
- }
- void setpos(uchar x,uchar y)
- {
- uchar x1;
- switch (x)
- {
- case 0:x1=0x80;break;
- case 1:x1=0x90;break;
- case 2:x1=0x88;break;
- case 3:x1=0x98;break;
- }
- x1=x1+y;
- LED_wcmd(x1);
- }
- void LED_wldate(uchar x,uchar y,uchar code *date)
- {
- uchar i=0;
- setpos(x,y);
- while(date[i]>=0x20)
- {
- LED_wdate(date[i]);
- delay(3) ;
- i++;
-
- }
- }
- void LED_wday(uchar x)
- {
- uchar i=0;
- setpos(2,2);
- while(table4[x][i]>=0x20)
- {
- LED_wdate(table4[x][i]);
- delay(3) ;
- i++;
-
- }
- }
- void LED_init()
- {
- LED_wcmd(0x30);
- delay (5);
-
- LED_wcmd(0x0c);
- delay (5);
- LED_wcmd(0x01);
- delay (5);
- LED_wcmd(0x06);
- delay (5);
-
- delay (5);
-
- delay (5);
- }
- void LED_wmiao(uchar date)
- {
- uchar shi,ge;
- shi=date/10;
- ge=date%10;
- setpos(1,5);
- LED_wdate(shi+0x30);
- LED_wdate(ge+0x30);
- }
- void LED_wfen(uchar date)
- {
- uchar shi,ge;
- shi=date/10;
- ge=date%10;
- setpos(1,3);
- LED_wdate(shi+0x30);
- LED_wdate(ge+0x30);
- }
- void LED_wshi(uchar date)
- {
- uchar shi,ge;
- shi=date/10;
- ge=date%10;
- setpos(1,1);
- LED_wdate(shi+0x30);
-
- LED_wdate(ge+0x30);
- }
- void LED_wnian(uchar date)
- {
- uchar shi,ge;
- shi=date/10;
- ge=date%10;
- setpos(0,1);
- LED_wdate(shi+0x30);
-
- LED_wdate(ge+0x30);
- }
- void LED_wyue(uchar date)
- {
- uchar shi,ge;
- shi=date/10;
- ge=date%10;
- setpos(0,3);
- LED_wdate(shi+0x30);
-
- LED_wdate(ge+0x30);
- }
- void LED_wri(uchar date)
- {
- uchar shi,ge;
- shi=date/10;
- ge=date%10;
- setpos(0,5);
- LED_wdate(shi+0x30);
-
- LED_wdate(ge+0x30);
- }
复制代码
|
|