📄 main.c
字号:
#include <absacc.h>
#include <reg52.h>
// #define FIRST_TIM
unsigned char code CharTab[] = {0x03,0x9F,0x25,0x0D,0x99,0x49,0x41,0x1F,0x01,0x09,0x11,0xC1,0x63,0x85,0x61,0x71};
unsigned char code LedSel[] = {0x10,0x30,0x50,0x70,0x90,0xB0};
extern void ReadTim(void);
extern void WriteTim(void);
bit xchg,update;
unsigned char DispBuf[6];
unsigned char data RTC_ARR[8] _at_ 0x20;
unsigned char data Minute,Second,Hour;
/*---------- Delay Time -----------*/
void delay(unsigned int t)
{
unsigned int i;
for(i=0;i<t;i++)
;
}
/*-------- calculate SEG value --------*/
void calculate()
{
DispBuf[0] = Second & 0x0F;
DispBuf[1] = (Second & 0xF0)>>4;
DispBuf[2] = Minute & 0x0F;
DispBuf[3] = (Minute & 0xF0)>>4;
DispBuf[4] = Hour & 0x0F;
DispBuf[5] = (Hour & 0xF0)>>4;
}
/*-------- Extern Interrupt ----------*/
void ex1(void) interrupt 2 using 1
{
xchg = 1;
Second++;
P1= ~P1;
if((Second & 0x0F)>=10)
{
Second += 6;
if(Second>=0x60) update = 1;
}
}
void main()
{
unsigned char i;
P1 = 0x55;
for(i=0;i<6;i++) DispBuf[i] = 0;
/*----------- Setup time and enable oscillator -----------*/
ReadTim();
RTC_ARR[0] = RTC_ARR[0] & 0x7F; // enable oscillator(bit 7=0)
#ifdef FIRST_TIM
RTC_ARR[0] = 0x00; // Second
RTC_ARR[1] = 0x10; // Minute
RTC_ARR[2] = 0x19; // Hour, 24-hour mode
RTC_ARR[3] = 0x06; // Day
RTC_ARR[4] = 0x12; // Date
RTC_ARR[5] = 0x11; // Month
RTC_ARR[6] = 0x05; // Year
#endif
RTC_ARR[7] = 0x90; // Control: OUT=1; SQWE=1,Square Wave Enable; RS1 RS0=00,1Hz Square Wave
Second = RTC_ARR[0];
Minute = RTC_ARR[1];
Hour = RTC_ARR[2];
WriteTim(); // Set RTC
INT1 = 1;
IT1 = 1;
EX1 = 1;
EA = 1;
xchg = 1;
update = 0;
while(1)
{
if(update)
{
ReadTim();
Second = RTC_ARR[0];
Minute = RTC_ARR[1];
Hour = RTC_ARR[2];
calculate();
update = 0;
}
if(xchg)
{
xchg = 0;
RTC_ARR[0] = Second;
calculate();
}
for(i=0;i<6;i++)
{
P2 = 0x0F;
P0 = CharTab[DispBuf[i]];
P2 = LedSel[i] | 0x0F;
delay(100);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -