我BCD转十进制,十进制转成BCD都对了,我用的1602显示!我特意看区别,我就在下一行显示,是可以的啊!但是在DS1302那个时钟没有反应,不知道为什么了啊!时钟还是在那里动,但是我调分钟,分钟就是不加起来!
我的程序代码如下
unsigned char cur_time[7] = {0x30,0x30,0x12,0x01,0x01,0x05,0x10};
Singal_SPI(CMD_CONTROL | CMD_WRITE,CFG_UNPROTECT);//写允许
Burst_SPI(CMD_CLOCK_BURST | CMD_WRITE,7,cur_time,0);
Singal_SPI(CMD_CONTROL | CMD_WRITE,CFG_PROTECT);//写保护
if(Singal_SPI(CMD_SECOND | CMD_READ,0xFF) != cur_time[0])
{
Burst_SPI(CMD_CLOCK_BURST | CMD_READ,7,0,cur_time);
lcd1602_disp_char(6,0,(cur_time[2] >>4) +'0');
lcd1602_disp_char(7,0, (cur_time[2] & 0x0f)+'0');
lcd1602_disp_char(8,0,':');
lcd1602_disp_char(10,0, (cur_time[1] & 0x0f)+'0');
lcd1602_disp_char(9,0,(cur_time[1] >>4) +'0');
lcd1602_disp_char(11,0, ':');
lcd1602_disp_char(13,0, (cur_time[0] & 0x0f)+'0');
lcd1602_disp_char(12,0,(cur_time[0] >>4) +'0');
}
case 15:
{
a=cur_time[1]>>4;
fen=cur_time[1]&0x0f;
cur_time[1]=a*10+fen;
cur_time[1]++;
shi=cur_time[1]/10;
miao=cur_time[1]%10;
cur_time[1]=shi*16+miao;
break;
}// 就是这里调时间没起到作用
下面是我对DS1302的初始的文件
#include<reg52.h>
#include<absacc.h>
#include"spi.h"
#include"ds1302.h"
unsigned char ds1302_rw(unsigned char wdata)
{
unsigned char rdata;
unsigned char i;
for(i = 0;i < 8;i ++)
{
clr_spi(SCK);//时钟线拉低,产生下降沿
rdata >>= 1;
set_spi(MISO);//向MISO写1准备读
if(read_spi(MISO))
{
rdata |= (1 << 7);//最高位置1
}
if(wdata & 0x01)
{
set_spi(MISO);//输出1
}
else
{
clr_spi(MISO);//输出0
}
wdata >>= 1;//右移一位
set_spi(SCK);//时钟线拉高,产生上升沿
}
clr_spi(SCK);
return rdata;
}
unsigned char Singal_SPI(unsigned char commond,unsigned char wdata)
{
unsigned char rdata;
en_ds1302();//DS1302使能
ds1302_rw(commond);//传送命令到DS1302
rdata = ds1302_rw(wdata);//写入或读出一字节数据
dis_ds1302();//DS1302关断
return rdata;
}
void Burst_SPI(unsigned char CMD,unsigned char len,
unsigned char *pwdata,unsigned char *prdata)
{
en_ds1302();//DS1302使能
ds1302_rw(CMD);//传送命令到DS1302
while(len --)
{
*prdata ++ = ds1302_rw(*pwdata ++);
}
dis_ds1302();//DS1302关断
}
只有用独立按键调时间不对!其他都是好的 |