您现在的位置是:首页 > 单片机

直流电机调速源程序示例

2020-06-30 05:01:16

直流电机可控硅调速源程序,望大家看后提出意见。

#i nclude <AT89X51.h>
#define uchar unsigned char
#define uint unsigned int
uchar zhishi[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90}; /*显示码*/
uint a,b;
bit mod=1;
uchar i,j;
void jianpan(void)                  /*键盘扫描程序*/
{
if(P2_1==0)              /*P21为加速键*/
    if(a<49900)
        a=a+100;
                  
if(P2_5==0)              /*P25为减速键*/
    if(a>100)
        a=a-100;
           
}
void waite(void)             /*显示用延时程序*/
{
  for(i=0;i<3;i++)
    for(j=0;j<10;j++);
}
void xianshiqi(void)       /*显示程序*/
{
if(a>=45000)
    P0=zhishi[9];
    waite();
if(a>=40000&&a<45000)
    P0=zhishi[8];
    waite();
if(a>=35000&&a<40000)
    P0=zhishi[7];
    waite();
if(a>=30000&&a<35000)
    P0=zhishi[6];
    waite();
if(a>=25000&&a<30000)
    P0=zhishi[5];
    waite();
if(a>=20000&&a<25000)
    P0=zhishi[4];
    waite();
if(a>=15000&&a<20000)
    P0=zhishi[3];
    waite();
if(a>=10000&&a<15000)
    P0=zhishi[2];
    waite();
if(a>=5000&&a<10000)
    P0=zhishi[1];
    waite();
if(a<5000)
    P0=zhishi[0];
    waite();
}
void inTIe0(void) interrupt 0       /*用于测试停止开关*/
{
mod=0;
}
void intt0(void) interrupt 1        /*T0中断服务,用于输出占空比可调的脉冲*/
{
b=50000-a;
if(P1_0==1)
    {
      TH0=(65536-a)/256;
      TL0=(65536-a)%256;
      P1_0=0; P1_3=0;
                      }
else
    {
      TH0=(65536-b)/256;
      TL0=(65536-b)%256;
      P1_0=1; P1_3=1;
                      }
}
void inTIe1(void) interrupt 2    /*用于可控硅关断*/
{
  P3_1=0;
  waite();
  for(i=0;i<150;i++)
     for(j=0;j<3;j++);
  P3_1=1;
}
void main(void)
{
        TMOD=0x01;
        TH0=0xff;
        TL0=0xff;
        TCON=0x05;
        IE=0x87;
     cx:while(P2_6);
        while(P2_6==0);
        a=100;
        TR0=1;
        while(mod)
           {
             jianpan();
             xianshiqi();
            }
        TR0=0;
        P1_0=1;
        P1_3=1;
        P3_1=0;
        waite();
        P3_1=1;
                P0=0xff;
        if(mod==0)mod=1;
                goto cx;
}