ARM9基礎教程lessen2—定時器
? S3C2440定時器操作
? S3C2440定時器初始化
- void Timer0_init()
- {
TCFG0 = 119; //配置定時器0,1的預分頻值 TCFG1 = 0x03; //配置定時器0分頻值 TCNTB0 = 3125; //計數(shù)緩存寄存器 TCMPB0 = 0; //比較緩存寄存器 TCON |= (1<<1); //手動更新位且配置反相器位(開/關)(手動更行位將TCNTBn和TCMPBn的值分別給TCNTn和TCMPn寄存器) TCON = 0x09; //定時器使能并自動重載 - }
- void
DelayMS(U32 dly) - {
U32 time_val; rTCFG0 = 3; //配置定時器0,1的預分頻值 rTCFG1 = 0<<4; //配置定時器1分頻值 time_val = PCLK/ (3+1) / 2 / 1000 - 1; // 1ms = PCLK / prescaler / divider / 1000 rTCNTB1 = time_val; //計數(shù)緩存寄存器 rTCMPB1 = time_val>>1; // 50% rTCON &= ~(0xf<<8); //手動更新位且配置反相器位(開/關) rTCON |= 0xb<<8; //定時器使能并自動重載 rTCON &= ~(2<<8); //clear manual update bit while(dly--) { while(rTCNTO1>=time_val>>1); while(rTCNTO1 >1); } - }
- void Main(void)
- {
//----------------添加自己的代碼------------------- rGPACON &= ~(1<<16); while (1) { rGPADAT |= (1<<16); DelayMS(1000); rGPADAT &= ~(1<<16); DelayMS(500); } - }
評論