新闻中心

EEPW首页 > 嵌入式系统 > 设计应用 > 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;  }}


评论


技术专区

关闭