標(biāo)題: 直流電機(jī)控制程序 [打印本頁(yè)]

作者: 吃苦小白    時(shí)間: 2024-2-21 20:54
標(biāo)題: 直流電機(jī)控制程序
#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;
  }
}







歡迎光臨 (http://www.torrancerestoration.com/bbs/) Powered by Discuz! X3.1