⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 1.c

📁 本人采用89S52设计的汽车电磁离合器的控制驱动程序
💻 C
字号:
#include <REG52.H>
#include<stdio.h>
#include<intrins.h>
#include<string.h>
#include<IOKEY.h>

#define uint unsigned int
#define uchar unsigned char


extern void ShowNum(unsigned long int number);
extern void key(void);


extern bit  keyflag;  //有无按键按下标志0--无1--有
bit  keyflag1; //停止启动判断标志位0--停止1--启动   
bit  flag;  //离合器吸合判断位
bit  flag1; //判断是否进入正常循环标志位
bit  keynet1;

extern uchar keydata1;
extern uchar ch0;//正转切换标志
extern uchar ch1; //反转切换标志
uchar keydata;


uint time;



unsigned long int keynum;  //预设循环次数
unsigned long int station1;//循环次数显示



void delay(uint t)
{
	while(t--)
	{
		_nop_();
		_nop_();
		_nop_();
		_nop_();
	}
}



main()
{
	TMOD=0x11;
	TH0=0xd8;	//10ms定时
	TL0=0xf0;
//    TH0=0x3c;   //50ms
//	TL0=0xb0;
	time=0;
	flag=1;
	flag1=0;
	ch0=0;
	ch1=0;
	station1=0;
	motaA=1;
	motaB=1;
	motaC=1;
    keyflag1=1;
	keydata=0;
	keydata1=0;
	keynet1=0;
	keynum=5000;
   	EA=1;
	ET0=1;
	ET1=1;
	TR0=1;

		while(1){
	         TR0=0;
             ShowNum(keynum);
			 key();
             if(keydata1==4&&flag1==0){
			                keydata1=0;
			                keynum=keynum+5000;
			                if(keynum>95000&&keynum<100001)keynum=99999;
                            if(keynum>100005){keynum=5000;}
							}
			 if(keydata1==1){keydata1=0;TR0=1;break;}
			     }
    flag1=1;
	while(1)
	{
	key();
	if(keyflag1==1&&station1<100005)  //SW open
	      {
		       if(keydata1==2)//正转
                    {
					if(time<=2){
				                 motaA=0;
								 motaB=1;
						         motaC=1;
							   }
					else if(time>=3&&time<=5)
					           {
				                 motaA=1;
								 motaB=0;
						         motaC=1;
							   }
					else if(time>=6&&time<=8)
					           {
				                 motaA=1;
								 motaB=1;
						         motaC=0;
								 
							   }
					 if(time==8&&station1>10)ch0++;
					 if(ch0>30){ch0=0;ch1=0;				                 
					             motaA=1;
								 motaB=1;
						         motaC=1;
                                 keydata1=3;}

					 }
					else if(keydata1==3)//反转
                    {
					if(time<=2){
				                 motaA=0;
								 motaB=1;
						         motaC=1;
							  }
					else if(time>=3&&time<=5)
					          {
				                 motaA=1;
								 motaB=1;
						         motaC=0;
							  }
					else if(time>=6&&time<=8)
					          {
				                 motaA=1;
								 motaB=0;
						         motaC=1;
								
							  }
                     if(time==8)ch1++;
					 if(ch1>30){ch0=0;ch1=0;				                
				                 motaA=1;
								 motaB=1;
						         motaC=1;
								 keydata1=2;}
					}
						
	      }
	 else {
		   motaA=1;
		   motaB=1;
		   motaC=1;
		   }
 		   if(flag==0){clutch=0;}
           else       {clutch=1;}
           if(station1>=keynum){
		                       keyflag1=0;
		                       motaA=1;
		                       motaB=1;
		                       motaC=1;
							   time=0;
				               flag=1;
				               clutch=1;
				               ch0=0;
				               ch1=0;
                              }	
		   ShowNum(station1);
	}
}

void t0(void) interrupt 1 using 2
{
	TH0=0xd8;	//10ms定时
	TL0=0xf0;
//  TH0=0x3c;   //50ms
//	TL0=0xb0;
if(keydata1==3||keydata1==2)time++;
if(time>8){if(keydata1==3||keydata1==2)station1++;time=0;}
}
////////////////////////////////////////////////////////////

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -