weixin_50697999
2021-10-11 21:06
采纳率: 75%
浏览 39

C51单片机,定时器1,流水灯!为啥定时器不启动?代码哪里有问题呢?


#include "reg52.h"
#define LED P1 

typedef unsigned int u16;

void Timer1Init(void)
{
    TMOD = 0x10;   
    TH1 = (65536-50000)/256;
    TL1 = (65536-50000)%256;
    ET1 = 1;
    EA = 1;
    TR1 = 1;
}

int main(void)
{
    Timer1Init();
    LED = 0x80;
    while(1);
    return 0;
}

void Timer1(void) interrupt 1
{    
    static u16 count = 0;
    TH1 = (65536-50000)/256;
    TL1 = (65536-50000)%256;
    count++;
    if(count==2)
    {
        LED = LED>>1;
        count = 0;
        if(LED == 0x01);LED = 0x80;
    }
}
  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • qq_708907433 2021-10-11 23:15
    已采纳

    35行改成
    if(LED == 0x01) LED = 0x80;
    中间多了一个;

    评论
    解决 无用
    打赏 举报
查看更多回答(1条)

相关推荐 更多相似问题