6.6444 2022-06-22 14:41 采纳率: 50%
浏览 28
已结题

速来!单片机题,有没有会的

假设系统的晶振频率为12MHz,使用定时器T0采用方式1定时,在P1.0端口输出频率为1HZ,占空比为2:5的矩形脉冲。

  • 写回答

1条回答 默认 最新

  • 乐观的study123 2022-06-22 15:30
    关注

    #include "reg51.h"

    unsigned char BYTE;
    unsigned int WORD;

    //-----------------------------------------------

    /* define constants */
    #define FOSC 11059200L

    #define T1MS (65536-FOSC/12/1000) //1ms timer calculation method in 12T mode

    /* define SFR */
    sbit TEST_LED = P1^0; //work LED, flash once per second

    /* define variables */
    unsigned int count,count_h=0; //1000 times counter

    //-----------------------------------------------

    /* Timer0 interrupt routine /
    void tm0_isr() interrupt 1
    {
    unsigned int j=500;
    TL0 = T1MS; //reload timer0 low byte
    TH0 = T1MS >> 8; //reload timer0 high byte
    j=1000
    2/7;
    if(count_h<j) /////占空比值
    count_h++;
    else
    TEST_LED=0;
    if (count-- == 0) //1ms * 1000 -> 1s
    {
    count = 1000; //reset counter
    count_h=0;
    TEST_LED =1; //work LED flash
    }
    }

    //-----------------------------------------------

    /* main program */
    void main()
    {
    TMOD = 0x01; //set timer0 as mode1 (16-bit)
    TL0 = T1MS; //initial timer0 low byte
    TH0 = T1MS >> 8; //initial timer0 high byte
    TR0 = 1; //timer0 start running
    ET0 = 1; //enable timer0 interrupt
    EA = 1; //open global interrupt switch
    count =1000; //initial counter
    count_h=0;
    TEST_LED =1;
    while (1); //loop
    }

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

问题事件

  • 系统已结题 6月30日
  • 已采纳回答 6月22日
  • 创建了问题 6月22日

悬赏问题

  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记