找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 170|回复: 0
收起左侧

直流电机控制程序

[复制链接]
ID:1098920 发表于 2024-2-21 20:54 | 显示全部楼层 |阅读模式
#include <REGX51.H>
#include "Delay.h"
#include "Key.h"
#include "Timer0.h"
#include "Nixie.h"

sbit Motor=P1^0;

unsigned char Counter,Compare;
unsigned char Keynumber,Speed;

void main ()
{
        Timer0_Init();
        
   while (1)
   {
                 Keynumber=Key();
                 if (Keynumber==2)
                 {
                         Speed++;
                         Speed%=4;
                         if(Speed==0){Compare=0;}
                         if(Speed==1){Compare=25;}
                         if(Speed==2){Compare=50;}
                         if(Speed==3){Compare=100;}
                 }
                 Nixie(1,Speed);
   }
}
void Timer0_Routine () interrupt 1
{
  TL0 = 0x9C;               
        TH0 = 0xFF;
  Counter++;
        Counter%=100;

        if (Counter<Compare)
  {
                  Motor=1;
  }
  else
  {
                  Motor=0;
  }
}


回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

手机版|小黑屋|51黑电子论坛 |51黑电子论坛6群 QQ 管理员QQ:125739409;技术交流QQ群281945664

Powered by 单片机教程网

快速回复 返回顶部 返回列表