TA的每日心情 | 无聊 2015-12-14 11:43 |
---|
签到天数: 556 天 连续签到: 1 天 [LV.9]以坛为家II
|
本帖最后由 ┗SKY┛ 于 2013-5-8 23:32 编辑
- #include "include.h"
- unsigned char const MONTH_Table[12]={31,28,31,30,31,30,31,31,30,31,30,31};
- unsigned char Time[7]={13,2,1,16,13,0,0};
- void TA_Init()
- {
- BCSCTL3 |= LFXT1S_2; // Set LFXT1为vol时钟即12kHZ
- TACTL |= TASSEL_0 + MC_1+TACLR;
- CCTL0 = CCIE; // CCR0 interrupt enabled
- TACCR0 = 12000;
- }
-
- void Clock_OnTimer()
- {
- unsigned char Days;
-
- DSEC++;
- if(DSEC >=16) {SECOND++;DSEC=0;} //1秒一次
-
- if(SECOND>=60) {MINUTE++;SECOND=0;} //60秒一次
- if(MINUTE>=60) {HOUR++;MINUTE=0;} //60分一次
- if(HOUR >=24) {DATE++;HOUR=0;} //24小时一次
-
-
- if(MONTH==2) //处理润年2月份问题
- {
- if(YEAR%4==0) Days=29; //逢4润
- else Days=28;
- if(YEAR%400==0) Days=28; //逢400不润
- }
- else
- Days=MONTH_Table[MONTH-1]; //正常月份,查表得到当月天数
-
- if(DATE >Days) {MONTH++;DATE=1;} //一个月一次
- if(MONTH >12) {YEAR++;MONTH=1;} //一年一次
- if(YEAR>=100) {YEAR=0;} //100年一次
-
-
- LCD_Disp_BNum(6,1,HOUR/10);
- LCD_Disp_BNum(21,1,HOUR%10);
- LCD_Disp_BNum(48,1,MINUTE/10);
- LCD_Disp_BNum(63,1,MINUTE%10);
- LCD_Disp_Num(72,0,SECOND/10);
- LCD_Disp_Num(78,0,SECOND%10);
-
- if((DSEC/8)%2==0){LCD_Disp_clkdot();} //0.5秒一次,间隔点闪烁
- else {LCD_Disp_clkdot_blank();}
-
- if(SECOND%10==0)
- {
-
- lcd_write_stringxy(18,5," 20 - - ");
- LCD_Disp_Num(36,5,YEAR/10);
- LCD_Disp_Num(42,5,YEAR%10);
- LCD_Disp_Num(54,5,MONTH/10);
- LCD_Disp_Num(60,5,MONTH%10);
- LCD_Disp_Num(72,5,DATE/10);
- LCD_Disp_Num(78,5,DATE%10);
- lcd_write_stringxy(0,0," ");}
-
- else if(SECOND%5==0)
- {
- lcd_write_stringxy(18,5,"hello world!");
- // switch weekday
- lcd_write_stringxy(0,0,"Sunday");
- }
-
-
- }
-
- // Timer A0 interrupt service routine
- #pragma vector=TIMER0_A0_VECTOR//G2452
- //#pragma vector=TIMERA0_VECTOR//G2231
- __interrupt void Timer_A (void)//1/32秒一次中断(由Timer_A所产生)
- {
- __low_power_mode_off_on_exit(); //唤醒CPU
-
- P1OUT ^= BIT6;
- }
-
-
复制代码- #include "include.h"
- void io_initial(void)
- {
- P1DIR |= BIT0+BIT1+BIT2+BIT3+BIT4+BIT5+BIT6;
- P2DIR |= BIT0;
- P1OUT &= ~BIT5;
- }
- void board_initial(void)
- {
- io_initial();
- lcd_init();
- TA_Init();
- _EINT();
- }
- int main( void )
- {
- WDTCTL = WDTPW + WDTHOLD;
- board_initial();
- while(1)
- {
- Clock_OnTimer();
- }
- }
复制代码 在main()中的while(1)中,一直执行的是Clock_OnTimer();但是不明白Clock_OnTimer();是怎么工作的,难道是一直都在执行那个DSEC++; 但是结果是正确的, 已经下载到了板子上了。不知道计时器是怎么工作的,求大神解释
|
|