S3C2440看門(mén)狗定時(shí)器
[cpp]view plaincopy
- #include"2440addr.h"
- #include"Option.h"
- #defineLED1_ON(rGPBDAT&=~(1<<5))
- #defineLED1_OFF(rGPBDAT|=(1<<5))
- #defineLED2_ON(rGPBDAT&=~(1<<6))
- #defineLED2_OFF(rGPBDAT|=(1<<6))
- #defineLED3_ON(rGPBDAT&=~(1<<7))
- #defineLED3_OFF(rGPBDAT|=(1<<7))
- #defineLED4_ON(rGPBDAT&=~(1<<8))
- #defineLED4_OFF(rGPBDAT|=(1<<8))
- void__irqWdt_Int(void);
- voidDelay(void)
- {
- inti;
- for(i=0;i<1000000;i++);
- }
- voidMain(void)
- {
- rGPBCON&=~((3<<10)|(3<<12)|(3<<14)|(3<<16));//對(duì)GPBCON[10:17]清零
- rGPBCON|=((1<<10)|(1<<12)|(1<<14)|(1<<16));//設(shè)置GPB5~8為輸出
- rGPBUP&=~((1<<5)|(1<<6)|(1<<7)|(1<<8));//設(shè)置GPB5~8的上拉功能
- rGPBDAT|=(1<<5)|(1<<6)|(1<<7)|(1<<8);//關(guān)閉LED
- rGPBCON|=1;//輸出
- rGPBUP|=0;
- rGPBDAT|=0;//關(guān)閉蜂鳴器
- rWTDAT=50000;//設(shè)置看門(mén)狗定時(shí)器超時(shí)時(shí)間為4秒(50÷12.5)
- rWTCNT=50000;
- rWTCON=(249<<8)|(1<<5)|(0<<3)|(1<<2);//預(yù)分頻值為249,使能看門(mén)狗,分頻系數(shù)為16,中斷使能
- rSRCPND|=BIT_WDT_AC97;
- rINTPND|=BIT_WDT_AC97;
- rSUBSRCPND|=BIT_SUB_WDT;//清除中斷標(biāo)志
- rINTMSK&=~(BIT_WDT_AC97);
- rINTSUBMSK&=~(BIT_SUB_WDT);//開(kāi)中斷
- pISR_WDT_AC97=(unsigned)Wdt_Int;//設(shè)置中斷程序入口
- while(1)
- {
- LED1_ON;Delay();LED1_OFF;
- LED2_ON;Delay();LED2_OFF;
- LED3_ON;Delay();LED3_OFF;
- LED4_ON;Delay();LED4_OFF;
- rWTCNT=50000;//喂狗沒(méi)喂狗蜂鳴器很響
- }
- }
- void__irqWdt_Int(void)
- {
- rSRCPND|=BIT_WDT_AC97;
- rINTPND|=BIT_WDT_AC97;
- rSUBSRCPND|=BIT_SUB_WDT;//清除中斷標(biāo)志
- rGPBDAT=1;
- Delay();
- rGPBDAT=0;//蜂鳴器響一段時(shí)間
- }
評(píng)論