请问为什么用的51单片机定时器在Proteus仿真时,慢了10多s,不是说定时器精确吗
单片机源程序如下:
#include <reg51.h>
typedef unsigned int u16;
sbit B_RED = P0^0;
sbit B_GRN = P0^1;
sbit B_YLW = P0^2;
sbit N_RED = P3^3;
sbit N_GRN = P3^4;
sbit N_YLW = P3^5;
sbit D_RED = P0^3;
sbit D_GRN = P0^4;
sbit D_YLW = P0^5;
sbit X_RED = P3^0;
sbit X_GRN = P3^1;
sbit X_YLW = P3^2;
u16 RED,YLW,GRN;
void main(void)
{
// Write your code here
/*初始状态*/
B_RED = 0; N_RED = 0;
D_RED = 1;
X_RED = 1;
/*定时器*/
TMOD = 0x01; //设置定时器0为工作方式1
TH0 = (65536-50000)/256; //单片机晶振为12MHz,产生50ms的中断
TL0 = (65536-50000)%256;
EA = 1; //开总中断
ET0 = 1; //开定时器0中断
TR0 = 1; //启动定时器0
while(1) //等待中断
{
/*南北红灯和东西红灯的运作方式*/
if(RED==600)
{
RED = 0;
B_RED = ~B_RED;
N_RED = ~N_RED;
D_RED = ~D_RED;
X_RED = ~X_RED;
}
/*南北绿灯和东西绿灯的运作方式*/
}
}
void T0_time() interrupt 1
{
TH0 = (65536-50000)/256;
TL0 = (65536-50000)%256;
RED++;
}
|