📄 main.c
字号:
// 硬件连接:
// LCD D0~D7接IOA0~IOA7
// LCD_CS 接IOA8
// LCD_RE 接IOA9
// LCD_AO 接IOA10
// LCD_RW 接IOA11
// LCD_EP 接IOA12
//
// IO高电平:3.3V
#include "SPCE061A.h"
#include "LCD_Dis.h"
#include "text.h"
#include "SPLC501_LCD.h"
#include "DS1302Driver_IO.h"
unsigned int time_temp;
unsigned int temp1,temp2;
extern void timer_b_init(void);
extern void adjust_time(void);
unsigned int year0;
unsigned int year1;
unsigned int month0;
unsigned int month1;
unsigned int date0;
unsigned int date1;
unsigned int week;
unsigned int hour0;
unsigned int hour1;
unsigned int minute0;
unsigned int minute1;
unsigned int second0;
unsigned int second1;
unsigned int HEX_ASCII(unsigned int HEX)
{
unsigned int ASCII;
if((HEX >= 0) && (HEX <= 9))
ASCII = HEX + 48;
else if((HEX >= 10) && (HEX <= 15))
ASCII = HEX + 55;
return(ASCII);
}
void write_ds1302(void)
{
unsigned int temp;
// temp = F_DS1302_ReadByte(0xc1);
// if(temp!=0xAA) //读取RAM中的第一个单元数据,看是否已经设置过时间了?
// {
F_DS1302_WriteByte(0x8E,0x00); //enable Write
F_DS1302_WriteByte(0x80,0x00); //seconds 00(bit7=0,start clk)
F_DS1302_WriteByte(0x90,0xAA); //TCS=1010b DS=10b Rout=10b
F_DS1302_WriteByte(0x8C,0x09); //year 2007
F_DS1302_WriteByte(0x8A,0x07); //day 3
F_DS1302_WriteByte(0x88,0x03); //month 08
F_DS1302_WriteByte(0x86,0x08); //date 20
F_DS1302_WriteByte(0x84,0x12); //hour 18
F_DS1302_WriteByte(0x82,0x37); //minute 58
F_DS1302_WriteByte(0x80,0x00); //seconds 00(bit7=0,start clk)
F_DS1302_WriteByte(0xC0,0xAA); //write 0xAA to RAM for flag
// }
temp=F_DS1302_ReadByte(0xc1);
}
void read_time()
{
SetPaintMode(0,1);
FontSet(0,1);
PutChar(30,1, 0x32) ;
PutChar(38,1,0x30) ;
time_temp = F_DS1302_ReadByte(0x8d); //year
year1 = HEX_ASCII((time_temp&0xf0)>>4);
PutChar(46,1,year1);
year0 = HEX_ASCII(time_temp&0x0f);
PutChar(54,1,year0);
PutChar(62,1,45);
time_temp = F_DS1302_ReadByte(0x89); //Month
month1 = HEX_ASCII((time_temp &0xf0)>>4);
PutChar(70,1, month1) ;
month0 = HEX_ASCII(time_temp&0x0f);
PutChar(78,1,month0) ;
PutChar(86,1,45);
time_temp = F_DS1302_ReadByte(0x87); //Date
date1 = HEX_ASCII((time_temp&0xf0)>>4);
PutChar(94,1, date1);
date0 = HEX_ASCII(time_temp&0x0f);
PutChar(102,1, date0);
time_temp = F_DS1302_ReadByte(0x85); //Hour
hour1 = HEX_ASCII((time_temp&0xf0)>>4);
PutChar(32,20, hour1);
hour0 = HEX_ASCII(time_temp&0x0f);
PutChar(39,20, hour0);
PutChar(46,20,58);
time_temp = F_DS1302_ReadByte(0x83); //Minutes
minute1 = HEX_ASCII((time_temp &0xf0)>>4);
PutChar(52,20,minute1);
minute0 = HEX_ASCII(time_temp&0x0f);
PutChar(59,20,minute0);
PutChar(66,20,58);
time_temp = F_DS1302_ReadByte(0x81); //second
second1= HEX_ASCII((time_temp&0xf0)>>4);
PutChar(73,20,second1);
second0 = HEX_ASCII(time_temp&0x0f);
PutChar(80,20,second0);
time_temp = F_DS1302_ReadByte(0x8b);
week = HEX_ASCII(time_temp&0x0f);
PutChar(67,35,week);
time_temp= F_DS1302_ReadByte(0x8f);
time_temp= F_DS1302_ReadByte(0x91);
}
void IRQ5(void) __attribute__ ((ISR));
void IRQ5(void)
{
unsigned int Int_Temp;
Int_Temp=*P_INT_Ctrl;
if(Int_Temp==0x0004)
{ //IRQ5_2Hz
*P_Watchdog_Clear = C_WDTCLR; //清看门狗
*P_INT_Clear=0x0004;
}
if(Int_Temp==0x0008)
{ //IRQ5_4Hz
*P_Watchdog_Clear=0x0001; //清看门狗
*P_INT_Clear=0x0008;
}
}
int main(void)
{
*P_SystemClock = 0x0080; //设置高的CPU主频,可以操作得更快
LCD_Init(); //LCD初始化,该函数在LCD_Driver_User.c中定义
timer_b_init();
F_DS1302_Initial_IO(); //初始化DS1302
*P_INT_Ctrl |=C_IRQ5_2Hz; //开2HZ中断,用于清看门狗
__asm("INT IRQ");
*P_INT_Ctrl = *P_INT_Ctrl_New|C_IRQ3_EXT2; //Open IRQ3_EXT2 interrupt
__asm("INT IRQ");
write_ds1302();
SetPaintMode(0,1); //设置绘图模式及前景色(绘图模式没有意义在该驱动中)
FontSet(2,1);
Rectangle(0,0,126,63,0); //画矩形框
LCD501_Bitmap(35,35,(unsigned int *)encoding_07);//显示"星"
LCD501_Bitmap(51,35,(unsigned int *)encoding_08);//显示"期"
// FontSet(1,1); //设置字体类形为ASCII码(西文显示) ,字符色为1
// PutString(8,54,"www.Mzdesign.com.cn");
while(1)
{
read_time();
adjust_time();
*P_Watchdog_Clear = 1;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -