本帖最后由 113263875 于 2013-10-15 20:10 编辑
定时1S,蜂鸣器的间隔明显没有1S;
代码没问题,跟教材一样的.
#include <reg52.h>
sbit fm = P2^3; //蜂鸣器
sbit led = P1^0;
typedef unsigned char uint8;
//typedef unsigned int uint16;
//unsigned int counter ;
//uint8 counter = 0;
void main()
{
uint8 counter =0;
TCON=0x1; // 12(65536-X)/11059200
TH0 = 0xb8;
TL0 = 0x00;
TR0 = 1;
while(1)
{
if (TF0 == 1) //20ms延时
{
counter++;
TH0 = 0xb8;
TL0 = 0x00;
TF0 = 0;
}
if(counter == 50) //重复50次,得到1S延时
{
fm = ~fm;
led = ~led;
counter = 0;
}
}
}
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
一周热门 更多>