新聞中心

EEPW首頁 > 嵌入式系統(tǒng) > 設計應用 > 52單片機定時器2實現1s中斷

52單片機定時器2實現1s中斷

作者: 時間:2012-10-08 來源:網絡 收藏
include    // 要寫,不能寫//--------默認為16位自動重載方式------------//void main(){/* T2定時器溢出預載值,溢出16次就是1s65536-62500=3036,即0x0bdc */RCAP2H=0x0B;RCAP2L=0xDC; ET2=1;    //  允許T2中斷EA=1;     // 開總中斷TR2=1;    // 啟動T2while(1);  //等待溢出中斷}void t2 ( ) interrupt 5{static unsigned char count;            TF2=0;   // 溢出標志必須軟件清0count++;if(count==16) {count=0;P1=~P1;  }}


評論


技術專區(qū)

關閉