|
这样可以吗?
#include "at89x52.h"
#include
#define uchar unsigned char
#define nop _nop_()
uchar s_oneSecondFlag=0x00; /*定义全局变量*/
uchar shiftCounter;
void main(void)
{
TMOD=0x10; /*Timer1工作在MODE1,16位定时器*/
TH1=(65536-10000)/256; /*设定Timer1每10ms中断一次*/
TL1=(65536-10000)%256;
IE=0x88; /*使能Timer1周期中断*/
P2=0x00; /*点亮8个发光二极管*/
shiftCounter=0x00; /*发光二极管移位计数器清零*/
TR1=1; /*启动Timer1*/
while(1)
{
if(s_oneSecondFlag==0x01) /*判断1秒到否*/
{
s_oneSecondFlag=0x00; /*1秒标志清零*/
P2=~(0x01<
if(++shiftCounter>=8) /*8个发光二极管都循环亮过了吗?*/
{
shiftCounter=0x00; /*都亮过了则重新循环*/
}
}
}
}
void Timer1Int() interrupt 3 using 3
{
static uchar s_oneSecondCounter;
TH1=(65536-10000)/256; /*设定Timer1每10ms中断一次*/
TL1=(65536-10000)%256;
if(++s_oneSecondCounter>=100) /*中断100次即为1秒*/
{
s_oneSecondCounter=0x00;
s_oneSecondFlag=0x01; /*置1秒到达标志*/
}
} |
赞赏
-
1
查看全部赞赏
-
|