空气净化装置主函数.docx
- 文档编号:29527998
- 上传时间:2023-07-24
- 格式:DOCX
- 页数:35
- 大小:22.52KB
空气净化装置主函数.docx
《空气净化装置主函数.docx》由会员分享,可在线阅读,更多相关《空气净化装置主函数.docx(35页珍藏版)》请在冰豆网上搜索。
空气净化装置主函数
/************************************************************************/
/*SC5708ADCDemo*/
/*检测方式:
查询方式+中断扫描(中断号:
13)*/
/*AD入口:
ADC0P1.0
*/
#include"MCU_0908.H"
#include"PubFunc.H"
#include"DataType.h"
#include
voidPWM_Init(void);
voidT0_initial(void);
voidINT1_Init(void);
externU16GETADCRESULT(U8i);
U16ADCResult;//ADC结果
voidADC_Init_temp(U8tongdao);
voiddelay();
voiddelay_ms();
#defineWDT_CLRdo{WDTCLR0=0x00;WDTCLR1=0x00;WDTCLR0=0x53;WDTCLR1=0xac;}while(0);
////////////////////////////////////////////////////
bitkey1_b=0,key2_b=0,key3_b=0,zhuanb,aab;
bitkey_check_b=0,kjb,laba_flag,hebi_b,kkb;
U8lcd1,lcd2,lcd3,qianc;
U8laba_ct,fengshanc1,fengshanc2,bba,aac,qiweid,fengshancd;
U16fenchengNC;
U16aaa1,aaa2,aaa3,aaa4,aaa5;
U8LED_ct;//LED半秒计数
bitsb30,qiweidb,fenchengdb,qiweidb1,fenchengdb1;
U8lcd_ct,lcd_ct_1,lcd_ct_2,key_chk_ct,timer,zhengb;
U8qiwei_ct,qiwei,fencheng,zhengct,fengshanc,LED_ct_1,su1b,sb30b,ccct,fenchengg,qiweigg;
U16LED_ct_4,min1,min2;
bitqiwei_b,key_chk_flag,huanyao_flag,timerb,shijianb;
bitPIN1,PIN2,PIN3,fenchengbz;
bitfengshanb1,fanb,ganb,fanb1,ganb1,twominb;
U16fenchengcc,twominct;
U8adii,fengshancAA,fenchengd,aaci;
U16ADCCT,ADCCB,ADCCA,ADCCC,ADCC,ADCCD,ADBJ,ADBB,iadbb,ADCCE,min3,min4,jishikd;
voidwr16(unsignedcharaa)
{
unsignedchariI=0,bb=0;
for(iI=0;iI<8;iI++)
{bb=aa&0x80;
if(bb==0x80){P05=1;}elseP05=0;
P04=0;
aa=aa<<1;
P04=1;
P04=0;
}
}
//////////////////
voidmmmin()
{
min1=0;fengshancAA=0;
fencheng=1;qiwei=1;
twominb=1;twominct=0;
fengshanc1=0;fengshanc2=0;
fengshanc=0;
fengshancd=0;
}
/***********************************************/
/*T0中断服务程序*/
voidirq_timer0(void)interrupt1
{
WDT_CLR;
key_chk_ct++;
if(sb30==1){
if(P02==0){
if(fencheng<3)
aaa5++;
if(fencheng==3){aaa1=0;aaa2=0;aaa3=0;aaa4=0;aaa5=0;}
if(aaa5>400)aaa5=0;}}
fenchengcc++;
qiwei_ct++;
lcd_ct_2++;
if(lcd_ct_2>50){lcd_ct_2=0;qiwei_b=1;lcd_ct_1++;if(twominb==1){twominct++;}}
if(qiwei_ct>100){qiwei_ct=0;
if(su1b==1){PWM1DH=0x00;if(PWM1DL>39)PWM1DL--;if(PWM1DL<39)PWM1DL++;}
if(su1b==2){PWM1DH=0x00;if(PWM1DL>0)PWM1DL--;}
if(su1b==0){PWM1DH=0x00;if(PWM1DL<57)PWM1DL++;if(PWM1DL>57){PWM1DL=57;}}
if(aab==1){ccct++;
if(ccct>5){
ccct=0;
aab=0;
}}
}
if(key_chk_ct>10){key_chk_ct=0;key_chk_flag=1;
if(laba_flag==1){laba_ct++;
if(laba_ct>5){
laba_ct=0;
laba_flag=0;
xIOMUX3=xIOMUX3&0xf7;
P12=0;
xPWMPH=0x00;//PWM周期高4位
xPWMPL=0x4F;
}}
}
if(LED_ct_4>300){LED_ct_4=0;if(kjb==1){sb30b++;if(sb30b>80){sb30b=0;sb30=1;
}}}elseLED_ct_4++;
if(fenchengcc>400){jishikd++;
fenchengbz=1;
fenchengcc=0;}
if(timerb==1){timer++;if(timer>200){min1++;if(shijianb==1){
min2++;
min3++;
min4++;}timer=0;}}
///////////////////////////////
/////////////////////////////////////////////////
if(P16==0){//guan
if(zhengb==2){
zhengb=0;
P14=0;
P13=0;P30=0;P10=0;zhengb=0;
fanb=1;
ganb=0;
ganb1=0;
fanb1=1;}}
if(P17==0){//kaimen
if(zhengb==1){
zhengb=0;
ganb=1;
ganb1=1;
fanb=0;
fanb1=0;
P14=0;P13=0;P30=0;P10=0;zhengb=0;zhengct=0;
}}
if(fengshanc==0){
fengshanb1=0;min1=0;min3=0;timer=0;timerb=0;min4=0;
P15=0;xIOMUX3&=0xf7;PWM1DH=0x00;PWM1DL=79;
fengshanc=0;fengshanc1=0;fengshanc2=0;fengshancAA=0;LED_ct=0;
fencheng=1;qiwei=1;qiweid=1;qiweidb=0;ganb1=0;
if(kjb==1){
if(fanb1==0)
{if(twominb==1)
zhengb=2;}}
}
if(fengshanc==1){
fengshanb1=1;
lcd2&=0x3f;
lcd2|=0x40;
su1b=0;xIOMUX3|=0x08;
min3=0;
min4=0;
timerb=1;fanb1=0;
if(twominb==1){if(ganb1==0)zhengb=1;}
if(min1>2400){mmmin();shijianb=0;//2400
}
if(LED_ct>60){LED_ct=0;lcd_ct++;}elseLED_ct++;
}
if(fengshanc==2){
fengshanb1=1;
lcd2&=0x3f;
lcd2|=0x40;
xIOMUX3|=0x08;
su1b=1;
timerb=1;fanb1=0;
if(twominb==1){if(ganb1==0)zhengb=1;}
if(shijianb==1){min1=0;
if(min3>480){min3=0;
fengshancAA=0;
if(fenchengd==2){
fenchengd=1;
fenchengdb1=1;}
}//480
if(min4>480){min4=0;
fengshancAA=0;
if(qiweid==2){
qiweid=1;
qiweidb1=1;}}//480
}
if(shijianb==0){min3=0;
min4=0;
if(min1>2400){mmmin();//2400
}}
if(LED_ct>40){LED_ct=0;lcd_ct++;}elseLED_ct++;
}
if(fengshanc==3){
fengshanb1=1;lcd2&=0x3f;
lcd2|=0x40;xIOMUX3|=0x08;
su1b=2;timerb=1;fanb1=0;
if(twominb==1){if(ganb1==0)zhengb=1;}
if(shijianb==1){min1=0;
if(min3>480){//480
fengshancAA=0;
if(fenchengd==2){
min3=0;
fenchengd=1;
fenchengdb1=1;}
if(fenchengd==3){
if(min3>720){
fenchengd=2;
fenchengdb=1;
min3=0;}}
}
if(min4>480){
fengshancAA=0;
if(qiweid==2){
min4=0;
qiweid=1;
qiweidb1=1;}
if(qiweid==3){
if(min4>720){
qiweid=2;
qiweidb=1;
min4=0;}}//720
}
}
if(shijianb==0){min3=0;
min4=0;
if(min1>2400){mmmin();}///2400
}
if(LED_ct>20){LED_ct=0;lcd_ct++;}elseLED_ct++;
}
if(twominct>960){twominct=0;
twominb=0;
P14=0;P13=0;P30=0;P10=0;
zhengb=0;zhengct=0;
}
if(zhengb==1){//kaimen
zhengct++;
if(zhengct>4){zhengct=1;}
if(zhengct==1){P14=0;P13=1;P30=1;P10=0;}
if(zhengct==2){P14=0;P13=1;P30=0;P10=1;}
if(zhengct==3){P14=1;P13=0;P30=0;P10=1;}
if(zhengct==4){P14=1;P13=0;P30=1;P10=0;}
}
if(zhengb==2){//guanmen
zhengct++;
if(zhengct>4){zhengct=1;}
if(zhengct==1){P14=0;P13=1;P30=0;P10=1;}
if(zhengct==2){P14=0;P13=1;P30=1;P10=0;}
if(zhengct==3){P14=1;P13=0;P30=1;P10=0;}
if(zhengct==4){P14=1;P13=0;P30=0;P10=1;}
}
}
///////////////////////////////////////
voidADC_Init_temp(U8tongdao)
{
WPKEY=0x37;
SPMC0=0x00;//打开内部AD基准2v
WPKEY=0x37;
xADCFG=0x26;//[bit6]参考电压选择内部参考,[bit1,bit0]AD转换时钟为Mclk/8
xADTRG=0x00;//[bit6,bit5,bit4]触发有效时,延时一个Tmclk启动ADC;[bit1,bit0]触发源选择软件触发,写ADGO启动ADC
ADRH=0x00;
ADRL=0x00;//数据寄存器清零
ADCON=tongdao;//[bit7,bit6,bit5,bit4]ADC通道选择ADC0(P1.0)
ADFM=1;//右对齐,高2位放在ADRH[1:
0]
ADEN=1;//AD模块使能
ADCResult=GETADCRESULT
(2);
}
/***********************************************/
voidT0_initial(void)
{
TMOD=0x12;//T0设置为8bit自动重载定时器。
xTIMPRS=0x07;//T0时钟分频为FCLK/256分频=Mclk/256=4M/256=15625HZ
TL0=256-38;//预定时5ms
TH0=256-38;
ET0=1;//允许T0溢出中断;
TR0=1;
}
////////////////////////int
/***********************************************/
voidlabadda()
{
//if(fengshanb1==0)xIOMUX3=0x01;
//if(fengshanb1==1)xIOMUX3=0x09;
xIOMUX3=xIOMUX3|0x01;
xPWMPH=0x01;//PWM周期高4位
xPWMPL=0xD4;
PWM0DH=0x00;//PWM0占空比高4位
PWM0DL=0XEA;//PWM0占空比低8位,PWM0占空比=(PWM0D+1)/(xPWMP+1)=25%
laba_flag=1;
}
///////////////////////////////
U8AA,BB;
voiddelay()
{
unsignedcharI=0;
for(I=0;I<2;I++);
}
voiddelay_ms()
{
unsignedcharI=0;
for(I=0;I<240;I++);
}
voidjisuan()
{
iadbb=0;
//if(ADBJ<400){ADBJ=400;}
/*ADCCE=ADBJ/100;
ADCCB=ADCCE*99;
ADCCE=ADBJ/100;
ADCCC=ADCCE*95;//*/
ADCCE=ADBJ*49;
ADCCB=ADCCE/50;
ADCCE=ADBJ*46;
ADCCC=ADCCE/50;
}
voidkey_test()
{
wr16(0xff);
P0MDL=0x45;
P03=1;//hong+dengq203
P00=1;//fengshanqiweifencheng
P01=1;
delay();
PIN1=P00;
PIN2=P01;
PIN3=P03;
//P0MDL=0xcf;
P0MDL=0x8a;
P03=1;//hong+dengq203
P00=1;//fengshanqiweifencheng
P01=1;
}
/***********************************************/
voidPWM_Init()
{
P12=0;
P15=0;
xIOMUX3=0x00;//PWM00,PWM01,PWM10,PWM11分别复用到P1.2,P1.3,P1.4,P1.5
P15=0;
/*PWM模块初始化*/
xPWMPSC=0x10;//PWM时钟源为系统时钟(不是MCLK),=SysClk/(xPWMPSC+1)
xPWMPS=0x00;//占空比期间输出低电平,见注1
PWMMOD=0x3f;//PWM00,PWM01输出正S反相波形
xPWM0DT=0x01;//PWM0死区设定值为1个PLL时钟,即1个SysClk,见注2。
死区设置只对PWM正反相输出时有效
xPWM1DT=0x02;//PWM1死区为2个PLL时钟
xPWM2DT=0x03;//PWM2死区为3个PLL时钟
xPWMPH=0x00;//PWM周期高4位
xPWMPL=0x4f;//PWM周期低8位;PWM0,PWM1,PWM2共用一个周期,周期=(xPWMP+1)*(1/SysClk)4fD4
PWM0DH=0x00;//PWM0占空比高4位
PWM0DL=0XEA;//PWM0占空比低8位,PWM0占空比=(PWM0D+1)/(xPWMP+1)=25%
PWM1DH=0x00;//PWM1占空比高4位
PWM1DL=79;//PWM1占空比低8位,PWM0占空比=(PWM1D+1)/(xPWMP+1)=50%7139
xPWMIE=0x00;//0x1F;//PWM0,PWM1,PWM2占空比中断使能,PWM周期中断使能
EIE2=0x02;//0x08;//T6中断使能(即PWM中断总使能位)
EA=1;//CPU中断总使能
xPWMCON=0x80;//T6边沿计数模式,T6使能
}
/////////////////////////////////////////////////
voidshouqing1()
{
fengshancd=0;
fengshanc=0;fengshanc1=0;fengshanc2=0;fengshancAA=0;
PWM1DH=0x00;PWM1DL=79;
aaa1=0;aaa2=0;aaa3=0;aaa4=0;aaa5=0;fenchengbz=0;
fenchengdb=0;min3=0;fenchengd=0;fenchengdb1=0;
min4=0;
qiweid=0;qiweidb1=0;
iadbb=0;ADBJ=0;ADCCE=0;ADCCB=0;ADCCA=0;ADCCC=0;ADCCD=0;ADCCT=0;ADCC=0;
}
/***********************************************/
voidmain()
{
/*端口初始化*/
P0MDL=0x8a;
P0MDH=0x2a;
xP0AE
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 空气净化 装置 函数