|
單片機(jī)STC15W202S
sout,xout分別控制2路可控硅,實(shí)現(xiàn)加熱爐的強(qiáng)弱檔控制,強(qiáng)檔可控硅始終導(dǎo)通,弱檔可控硅斷續(xù)導(dǎo)通,定時(shí)器T0確定弱檔時(shí)的周期t0,T2確定占空比t1/t0,每路兩個(gè)按鈕,開關(guān)和強(qiáng)弱選擇
#include<reg52.h>
#define uint unsigned int
#define uchar unsigned char
sbit sqr=P1^3; //輸出強(qiáng)弱選擇按鍵1
sbit skg=P1^2; //輸出開關(guān)鍵1,打開進(jìn)入強(qiáng)輸出狀態(tài)
sbit xqr=P1^5; //輸出強(qiáng)弱選擇按鍵2
sbit xkg=P1^4; //輸出開關(guān)鍵2,同1
sbit sout=P1^1; //輸出1
sbit xout=P3^0; //輸出2
sbit sq=P3^7; //輸出1強(qiáng)發(fā)光二極管顯示
sbit sr=P3^6; //輸出1弱發(fā)光二極管顯示
sbit xq=P3^1; //輸出2強(qiáng)發(fā)光二極管顯示
sbit xr=P3^2; //輸出2弱發(fā)光二極管顯示
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;
}
}
|
|