[導(dǎo)讀]#include #define uchar unsigned char#define uint unsigned int__CONFIG(0X3B32);#define LED PORTDchar Counter = 0; // 1S計(jì)數(shù)變量清零/********定時(shí)器0初始化函數(shù)********/void timer0_init(){ OPTION_R
#include #define uchar unsigned char#define uint unsigned int__CONFIG(0X3B32);#define LED PORTDchar Counter = 0; // 1S計(jì)數(shù)變量清零/********定時(shí)器0初始化函數(shù)********/void timer0_init(){ OPTION_REG=0b00000111; //TMR0對內(nèi)部時(shí)鐘計(jì)數(shù),預(yù)分頻器給TMR0,分頻比為1:256INTCON=0b10100000; //允許TMR0溢出中斷TMR0=61; //TMR0賦初值,定時(shí)10ms}/********主函數(shù)********/void main(void){TRISD=0x00; //設(shè)PORTD為輸出timer0_init();LED=0x00; while(1); //原地等待}/********中斷服務(wù)程序********/void interrupt ISR(void){ if (T0IF==1){T0IF=0; //清TMR0溢出中斷標(biāo)志位TMR0=61; //TMR0賦初值,必須!if(++Counter >= 100) //定時(shí)時(shí)間到1S嗎?定時(shí)中斷溢出100次為1S{LED=~LED;Counter = 0; //1S計(jì)時(shí)變量清零}}}
本站聲明: 本文章由作者或相關(guān)機(jī)構(gòu)授權(quán)發(fā)布,目的在于傳遞更多信息,并不代表本站贊同其觀點(diǎn),本站亦不保證或承諾內(nèi)容真實(shí)性等。需要轉(zhuǎn)載請聯(lián)系該專欄作者,如若文章內(nèi)容侵犯您的權(quán)益,請及時(shí)聯(lián)系本站刪除( 郵箱:macysun@21ic.com )。