/*立式不锈钢波纹管机控制板2021 2 26 pcb PAST******/
#include <REG52.H>
#include <intrins.H>
#define uint unsigned int
#define uchar unsigned char
#define FOSC 11059200L
#define T1MS (65536-FOSC/1000) //1T模式
uchar val;
uchar Speed;
sbit OUT1=P1^6;
sbit OUT2=P1^7;
sbit P_WM1=P3^5;
sbit P_WM2=P3^7;
bit MOTORX_RUN; //X轴启动标志
bit MotorX_LowFlag; //电机X轴低电平计数标志
uint MotorX_LowCounter; //电机X轴低电平计数器
uint MotorX_HighCounter; //电机X轴高电平计数器
/*---------------延时子程序----------------*/
void delay1 (uint ms)
{
uint i,j;
for(i=0;i<ms;i++)
for(j=0;j<2000;j++)
;
}
/****************************************/
void timer0() interrupt 1
{
val++;
if(val>2)
{
val=0;
OUT1=~OUT1; //将测试口取反
if(MOTORX_RUN==1) //X轴电机开启标志
{
P_WM1=0; //开X轴输出
if(MotorX_LowFlag==1) //低电平计数标志等于1
{
MotorX_LowCounter++;
if(MotorX_LowCounter>=Speed) //
{
MotorX_LowFlag=0; //低电平计数标志等于0高电平开始计数
MotorX_HighCounter=102-Speed; //赋高电平占空比值
}
}
else
{
P_WM1=1; //关X轴输出
MotorX_HighCounter++;
if(MotorX_HighCounter>=Speed) //
{
MotorX_LowFlag=1; //低电平计数标志等于1低电平开始计数
MotorX_LowCounter=Speed; //低电平计数器
}
}
}
}
}
/*------------------主循环程序----------------*/
void main( ) /*主程序开始*/
{
P1M0=0XC3; //
P1M1=0X00;
P3M0=0XF0; //
P3M1=0X00;
Speed=60;
MOTORX_RUN=1;
TMOD = 0x00; //设置定时器为模式0(16位自动重装载)
TL0 = T1MS; //初始化计时值
TH0 = T1MS >> 8;
TR0 = 1; //定时器0开始计时
ET0 = 1; //使能定时器0中断
EA=1;
while(1)
{
OUT2=0;
delay1 (100);
OUT2=1;
delay1 (100);
}
} //2024 6 13 L81 CODE196 PAST