加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
1302.c 2.74 KB
一键复制 编辑 原始数据 按行查看 历史
leonard 提交于 2016-04-29 23:24 .
#include"1302.h"
#include"12232.h"
#include"keynew.h"
#include"delay.h"
#include "warning.h"
#define uchar unsigned char
#define uint unsigned int
void Write1302 ( uchar addr,dat )
{
uchar i,temp;
CE=0;
SCLK=0;
CE=1;
for ( i=8; i>0; i-- )
{
SCLK = 0;
temp = addr;
DIO = (bit)(temp&0x01);
addr >>= 1;
SCLK = 1;
}
for ( i=8; i>0; i-- )
{
SCLK = 0;
temp = dat;
DIO = (bit)(temp&0x01);
dat >>= 1;
SCLK = 1;
}
CE = 0;
}
uchar Read1302 ( uchar addr )
{
uchar i,temp,dat1,dat2;
CE=0;
SCLK=0;
CE = 1;
for ( i=8; i>0; i-- )
{
SCLK = 0;
temp = addr;
DIO = (bit)(temp&0x01);
addr >>= 1;
SCLK = 1;
}
for ( i=8; i>0; i-- )
{
ACC_7=DIO;
SCLK = 0;
ACC>>=1;
SCLK = 1;
}
CE=0;
dat1=ACC;
dat2=dat1/16;
dat1=dat1%16;
dat1=dat1+dat2*10;
return (dat1);
}
void Initial(void)
{
Write1302 (WRITE_PROTECT,0X00);
Write1302 (WRITE_SECOND,0x00);
Write1302 (WRITE_MINUTE,0x00);
Write1302 (WRITE_HOUR,0x12);
Write1302 (WRITE_PROTECT,0x80);
}
uchar Hex_To_ASCII(uchar bHex)
{
if((bHex>=0)&&(bHex<=9))
bHex += 0x30;
else if((bHex>=10)&&(bHex<=15))
bHex += 0x37;
else bHex = 0xff;
return bHex;
}
/***********************************************************/
uchar ASCII_To_Hex(uchar bChar)
{
if((bChar>=0x30)&&(bChar<=0x39))
bChar -= 0x30;
else if((bChar>=0x41)&&(bChar<=0x46))
bChar -= 0x37;
else if((bChar>=0x61)&&(bChar<=0x66))
bChar -= 0x57;
else bChar = 0xff;
return bChar;
}
void tadj()
{uchar h,m,pq,s;
LCD_clear();
LCD_write_com(0x80);
LCD_write_zfc("õǰʱ");
LCD_write_com(0x91);
h=Read1302 (READ_HOUR);
timeb(h);
LCD_write_zfc("");
m=Read1302 (READ_MINUTE);
timeb(m);
LCD_write_zfc("");
s=Read1302 (READ_SECOND);
timeb(s);
do{
LCD_write_com(0x91);
timeb(h);
LCD_write_com(0x91);
LCD_write_com(0x0f);
if(key_scan()==1)
{h+=1;if(h>24)h=1;}
if(key_scan()==2)
{h-=1;if(h>24)h=24;}
delay_ms(130);
}while(key_scan()!=4);
do
{LCD_write_com(0x93);
timeb(m);
LCD_write_com(0x93);
LCD_write_com(0x0f);
if(key_scan()==1)
{m+=1;if(m>59)m=1;}
if(key_scan()==2)
{m-=1;if(m>59)m=59;}
delay_ms(130);
}while(key_scan()!=4);
do
{LCD_write_com(0x95);
timeb(s);
LCD_write_com(0x95);
LCD_write_com(0x0f);
if(key_scan()==1)
{s+=1;if(s>59)s=1;}
if(key_scan()==2)
{s-=1;if(s>59)s=59;}
delay_ms(130);
}while(key_scan()!=4);
LCD_write_com(0x0c);
Write1302 (WRITE_PROTECT,0X00);
pq=h/10;
h=h%10;
h=(pq<<4)|h;
Write1302 (WRITE_HOUR,h);
pq=m/10;
m=m%10;
m=(pq<<4)|m;
Write1302 (WRITE_MINUTE,m);
pq=s/10;
s=s%10;
s=(pq<<4)|s;
Write1302 (WRITE_SECOND,s);
Write1302 (WRITE_PROTECT,0x80);
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化