单片机STC15W202S
sout,xout分别控制2路可控硅,实现加热炉的强弱档控制,强档可控硅始终导通,弱档可控硅断续导通,定时器T0确定弱档时的周期t0,T2确定占空比t1/t0,每路两个按钮,开关和强弱选择
#include<reg52.h>
#define uint unsigned int
#define uchar unsigned char
sbit sqr=P1^3; //输出强弱选择按键1
sbit skg=P1^2; //输出开关键1,打开进入强输出状态
sbit xqr=P1^5; //输出强弱选择按键2
sbit xkg=P1^4; //输出开关键2,同1
sbit sout=P1^1; //输出1
sbit xout=P3^0; //输出2
sbit sq=P3^7; //输出1强发光二极管显示
sbit sr=P3^6; //输出1弱发光二极管显示
sbit xq=P3^1; //输出2强发光二极管显示
sbit xr=P3^2; //输出2弱发光二极管显示
uchar t0=20;
uchar t1=10;
uchar num1;
uchar num2;
uchar led1;
uchar led2;
uchar scan;
uchar xcan;
void delayms(uint xms)
{
uint i,j;
for(i=xms;i>0;i--)
for(j=110;j>0;j--);
}
void ledcan()
{
if((skg==0)&&(scan==1))
{
delayms(10);
if((skg==0)&&(scan==1))
{
TR0=0;
AUXR&=0x00;
while(!skg);
TR0=1;
AUXR|=0x10;
scan=0;
sout=0;
sq=0;
sr=1;
}
delayms(10);
}
if((skg==0)&&(scan==0))
{
delayms(10);
if((skg==0)&&(scan==0))
{
TR0=0;
AUXR&=0x00;
while(!skg);
TR0=1;
AUXR|=0x10;
scan=1;
sout=1;
sq=1;
sr=1;
}
delayms(10);
}
if((xkg==0)&&(xcan==1))
{
delayms(10);
if((xkg==0)&&(xcan==1))
{
TR0=0;
AUXR&=0x00;
while(!xkg);
TR0=1;
AUXR|=0x10;
xcan=0;
xout=0;
xq=0;
xr=1;
}
delayms(10);
}
if((xkg==0)&&(xcan==0))
{
delayms(10);
if((xkg==0)&&(xcan==0))
{
TR0=0;
AUXR&=0x00;
while(!xkg);
TR0=1;
AUXR|=0x10;
xcan=1;
xout=1;
xq=1;
xr=1;
}
delayms(10);
}
/*******************************************/
if((sqr==0)&&(scan==0)&&(sq==0))
{
delayms(10);
if((sqr==0)&&(scan==0)&&(sq==0))
{
TR0=0;
AUXR&=0x00;
while(!sqr);
TR0=1;
AUXR|=0x10;
sout=led2;
sq=1;
sr=0;
}
delayms(10);
}
if(sr==0)
{
sout=led2;
}
if((sqr==0)&&(scan==0)&&(sr==0))
{
delayms(10);
if((sqr==0)&&(scan==0)&&(sr==0))
{
TR0=0;
AUXR&=0x00;
while(!sqr);
TR0=1;
AUXR|=0x10;
sout=0;
sq=0;
sr=1;
}
delayms(10);
}
if((xqr==0)&&(xcan==0)&&(xq==0))
{
delayms(10);
if((xqr==0)&&(xcan==0)&&(xq==0))
{
TR0=0;
AUXR&=0x00;
while(!xqr);
TR0=1;
AUXR|=0x10;
xout=led2;
xq=1;
xr=0;
}
delayms(10);
}
if(xr==0)
{
xout=led2;
}
if((xqr==0)&&(xcan==0)&&(xr==0))
{
delayms(10);
if((xqr==0)&&(xcan==0)&&(xr==0))
{
TR0=0;
AUXR&=0x00;
while(!xqr);
TR0=1;
AUXR|=0x10;
xout=0;
xq=0;
xr=1;
}
delayms(10);
}
}
void main()
{
sqr=1;
skg=1;
xqr=1;
xkg=1;
sout=1;
xout=1;
sq=1;
sr=1;
xq=1;
xr=1;
num1=0;
num2=0;
led1=0;
led2=0;
scan=1;
xcan=1;
TMOD=0x11;
TH0=(65535-45872)/256;
TL0=(65535-45872)%256;
T2H=(65535-45872)/256;
T2L=(65535-45872)%256;
EA=1;
ET0=1;
TR0=1;
IE2|=0x04;
AUXR|=0x10;
while(1)
{
ledcan();
}
}
void T0time() interrupt 1
{
TH0=(65535-45872)/256; //50ms初值
TL0=(65535-45872)%256;
num1++;
if(num1==t0)
{
TR0=0;
AUXR&=0x00;
led1=1;
delayms(5);
TR0=1;
AUXR|=0x10;
led1=0;
num1=0;
}
}
void T2time() interrupt 12
{
T2H=(65535-45872)/256;
T2L=(65535-45872)%256;
num2++;
if(num2==t1)
{
AUXR&=0x00;
led2=1;
}
if(led1==1)
{
AUXR|=0x10;
num2=0;
led2=0;
}
}
|