本帖最后由 dong_abc 于 2013-12-14 01:14 编辑
- #include "systick.h"
- #include "NUC1xx.h"
- systick_t::systick_t (void)
- {
- SysTickInit();
- }
- void systick_t::SysTickInit(void)
- {
- UNLOCKREG();
- SYSCLK->PWRCON.XTL12M_EN = 1;
- SysTick_Config(12000000/(100*2)); //5ms节拍中断
- LOCKREG();
- __disable_irq();
- }
- /*系统节拍中断不在向量表中,所以将他单独出来*/
- extern "C" void __irq SysTick_Handler(void)
- {
- volatile static unsigned char SysTickCnt = 0;
- SysTickCnt++;
- if(SysTickCnt%100==0)
- {
- SysTickCnt=0;
- systick_tt.SysTick_Timer_Flag.T_500ms=1;
- }
- if(SysTickCnt%20==0)
- {
- systick_tt.SysTick_Timer_Flag.T_100ms=1;
- }
- if(SysTickCnt%4==0)
- {
- systick_tt.SysTick_Timer_Flag.T_20ms=1;
- }
- systick_tt.SysTick_Timer_Flag.T_5ms=1;
- }
- #ifndef __NUC1xxSysTick_H__
- #define __NUC1xxSysTick_H__
- #ifdef __cplusplus
- extern "C" {
- #endif
- typedef volatile struct
- {
- unsigned char T_5ms :1;
- unsigned char T_20ms :1;
- unsigned char T_100ms :1;
- unsigned char T_500ms :1;
- }SysTick_Timer;
- class systick_t {//系统类
- public:
- systick_t();
- private:
- inline void SysTickInit(void);
- public:
- SysTick_Timer SysTick_Timer_Flag;
- private:
- };
- extern systick_t systick_tt;
- #ifdef __cplusplus
- }
- #endif
- #endif /* __NUC1xxSysTick_H__ */
|