#include
#include
#define uchar unsigned char
#define uint unsigned int
#define ds1302_rst PE4 //界说1302的RST接在PE4
#define ds1302_io PE3 //界说1302的IO接在PE3
#define ds1302_sclk PE2 //界说1302的时钟接在PE2
#define set_ds1302_rst_ddr() DDRE|=1< //复位端置为输出
#define set_ds1302_rst() PORTE|=1< //复位端置1
#define clr_ds1302_rst() PORTE&=~(1< //复位端清0
#define set_ds1302_io_ddr() DDRE|=1< //数据端置为输出
#define set_ds1302_io() PORTE|=1< //数据端置1
#define clr_ds1302_io() PORTE&=~(1< //数据端清0
#define clr_ds1302_io_ddr() DDRE&=~(1< //数据端置为输入
#define in_ds1302_io() PINE&(1< //数据端输入数据
#define set_ds1302_sclk_ddr() DDRE|=1< //时钟端置为输出
#define set_ds1302_sclk() PORTE|=1< //时钟端置1
#define clr_ds1302_sclk() PORTE &=~(1< //时钟端清0
#define ds1302_sec_add 0x80 //秒数据地址
#define ds1302_min_add 0x82 //分数据地址
#define ds1302_hr_add 0x84 //时数据地址
#define ds1302_date_add 0x86 //日数据地址
#define ds1302_month_add 0x88 //月数据地址
#define ds1302_day_add 0x8a //星期数据地址
#define ds1302_year_add 0x8c //年数据地址
#define ds1302_control_add 0x8e //操控数据地址
#define ds1302_charger_add 0x90
#define ds1302_clkburst_add 0xbe
uchar TempData[8];
uchar timer[7]={12,2,8,20,31,50,3};
uchar WeiMa[8] = {0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80};
uchar led_discode[11]={0xc0,0xf9,0xa4,0xb0,0x99,
void smg_io_init(void)
{
PORTA=0XFF;
DDRE=0xff;
DDRC=0XFF;
PORTC=0XFF;
DDRF|=0X0E;
PORTF|=0X0E;
PORTF&=0xF7;
DDRB |=0X10;
PORTB|=0X10;
}
void display(uchar FirstBit,uchar Num)
{
for(i=0;i
{
PORTC=led_discode[10];
Delayms(2);
}
}
void Delayms(uint MS)
{
}
void shi_BCD(void)
{
for(i=0;i<7;i++)
{
timer[i]=timer[i];
timer[i]=timer[i]+k*16;
}
}
void ds1302_init(void)
{
set_ds1302_rst_ddr();
set_ds1302_sclk_ddr();
clr_ds1302_rst();
}
void ds1302_write(uchar add,uchar data)
{
set_ds1302_io_ddr(); //装备IO为输出
add = add & 0xFE;
}
uchar ds1302_read(uchar add)
{
}
void ds1302_write_time(void)
{
}
void ds1302_read_time(void)
{
}
void time_Process(void)
{
TempData[1] = led_discode[timer[3]];
TempData[2] = 0XBF;
TempData[3] = led_discode[timer[4]/16];
TempData[4] = led_discode[timer[4]];
TempData[5] = 0XBF;
TempData[6] = led_discode[timer[5]/16];
TempData[7] = led_discode[timer[5]];
}
void main(void)
{
smg_io_init();
shi_BCD();
ds1302_init();
}
}
声明:本文内容来自网络转载或用户投稿,文章版权归原作者和原出处所有。文中观点,不代表本站立场。若有侵权请联系本站删除(kf@86ic.com)https://www.86ic.net/zhishi/jichu/262333.html