请教大神关于足疗机程序的问题
时间:10-02
整理:3721RD
点击:
有关足疗机的程序:其中包括红外线接收、PWM产生、定时器扫描显示、间断运行模式程序、定位程序、主控子程序、主控程序。为何在KELL中调试出来,但烧到芯片里就没有任何反应了。这是啥原因?
#include "STC12C5620AD.H"
#include <stdio.h>
#include <intrins.h>
#define uchar unsigned char
#define uint unsigned int
#define ulint unsigned long int
//sbit P1M1=P1;
//sbit P1M0=P1;
//sbit P3M1=P3;
//sbit P3M0=P3;
uchar pgm_style,heat_var,fast_slow_var,need_position,virtual_key,keytag;
uchar tm;
uint speed,hot;
sbit S1=P3^0;
sbit S2=P3^3;
sbit S3=P3^4;
sbit S4=P3^5;
sbit SN2=P3^1;
sbit BELL=P3^7;
bit FAST_SLOW_I;
bit FAST_SLOW_II;
bit FAST_SLOW_III;
bit HOT_Lo;
bit HOT_Hi;
bit run_tag;
bit PGM_I;
bit PGM_II;
sbit MOTO=P1^6;
sbit HEAT=P1^5;
sbit P1_7=P1^7;
sbit P1_3=P1^3;
sbit P1_2=P1^2;
sbit P1_4=P1^4;
sbit P1_1=P1^1;
sbit P1_0=P1^0;
void clr()
{
P1_7=1;
P1_3=1;
P1_2=1;
P1_4=1;
P1_1=1;
P1_0=1;
}
void stop()
{
MOTO=1;
HEAT=1;
}
void delay(uint m)
{
uchar i,j;
for(i=0;i<m;i++)
{
for(j=0;j<124;j++);
}
}
void bell()
{
{
BELL=0;//蜂鸣器响
delay(20);
BELL=1;//蜂鸣器停
delay(20);
}
}
void longdelay(uchar m)
{
uint i;
for(i=0;i<m;i++)
{
_nop_();
}
}
/*定时扫描程序*/
void displ()
{
unsigned char cnt;
cnt++;
if(cnt==40)cnt=0;
switch(cnt)
{
case 10:
clr();
P1_7=0;
P1_2=FAST_SLOW_III?1:0;
P1_3=FAST_SLOW_II?1:0;
P1_4=FAST_SLOW_I?1:0;
break;
case 20:
clr();
P1_0=0;
P1_2=PGM_II?1:0;
P1_3=PGM_I?1:0;
P1_4=HOT_Hi?1:0;
break;
case 30:
clr();
P1_1=0;
P1_2=HOT_Lo?1:0;
if(run_tag==1)P1_3=1;
else
{
if(tm++>500)P1_3=1;
else P1_3=need_position;
}
break;
}
}
/*键盘处理程序*/
char keyscan()
{
unsigned char i;
if(virtual_key==0)
{
if((P3&0x39)!=0x39)
{
if(keytag==1) return-1;
}
else
{
keytag=0;
return-1;
}
for(i=0;i<250;i++);
for(i=0;i<250;i++);
if((P3&0x39)==0x39)
{
keytag=0;
return-1;
}
}
keytag=1;
if(keytag==1||virtual_key!=0)
{
if(S1==0||virtual_key==1)
{
if(pgm_style!=0)
need_position=1;
run_tag=0;
pgm_style=0;
heat_var=0;
}
if(S2==0||virtual_key==2)
{
heat_var=(heat_var+1)%3;
}
if(S3==0||virtual_key==3)
{
pgm_style=(pgm_style+1)%3;
if(pgm_style==0)
need_position=1;
}
if(S4==0||virtual_key==4)
{
fast_slow_var=(fast_slow_var+1)%3;
}
bell();
virtual_key=0;
}
}
/*间断运行模式程序*/
int running_mode_1()
{
char i,j,k;
unsigned int heat_var;
unsigned int speed_bak;
unsigned int speed;
speed_bak=speed;
for(k=0;k<10;k++)
{
for(j=0;j<6;j++)
{
for(i=0;i<7;i++)
{
speed=speed_bak;
delay(67);
speed=0;
delay(135);
}
for(i=0;i<13;i++)
{
speed=speed_bak;
delay(30);
speed=0;
delay(70);
}
}
for(i=0;i<9;i++)
{
const unsigned char tab[18]={30,80,30,80,30,80,30,160,30,70,10,20,10,20,30,10,30,0};
speed=0;
longdelay(tab[i*2]);
speed=speed_bak;
longdelay(tab[i*2+1]);
}
}
heat_var=0;
stop();
}
/*定位程序*/
void position()
{
unsigned int cnt=1;
speed=0;
TH0=0;
while(SN2==0)
{
if(TH0>120)
{
cnt+=1;
TH0=0;
}
if(cnt>150)break;
}
delay(70);
TH0=0;
cnt=1;
while(SN2==1)
{
if(TH0>120)
{
cnt+=1;
TH0=0;
}
if(cnt>150)
break;
}
}
/*主控子程序*/
int mysub()
{
keyscan();
if(run_tag==0)
{
hot=0;
speed=0;
}
switch(heat_var)
{
case 0:
hot=0;
HOT_Hi=0;
HOT_Lo=0;
if(pgm_style==0)
run_tag=0;
break;
case 1:
hot=1;
HOT_Hi=1;
HOT_Lo=0;
run_tag=1;
break;
case 2:
hot=2;
HOT_Hi=0;
HOT_Lo=1;
run_tag=1;
break;
}
switch(pgm_style)
{
case 0:
PGM_I=0;
PGM_II=0;
FAST_SLOW_I=0;
FAST_SLOW_II=0;
FAST_SLOW_III=0;
if(heat_var==0)
run_tag=0;
break;
case 1:
PGM_I=1;
PGM_II=0;
run_tag=1;
break;
case 2:
PGM_I=0;
PGM_II=1;
run_tag=1;
break;
}
if(pgm_style!=0)
{
switch(fast_slow_var)
{
case 0:
FAST_SLOW_I=1;
FAST_SLOW_II=0;
FAST_SLOW_III=0;
speed=0;
break;
case 1:
FAST_SLOW_I=0;
FAST_SLOW_II=1;
FAST_SLOW_III=0;
speed=1;
break;
case 2:
FAST_SLOW_I=0;
FAST_SLOW_II=0;
FAST_SLOW_III=1;
speed=2;
break;
}
}
}
/*主控函数*/
void main()
{
ulint i;
P1M1=0X0;
P1M0=0XFF;
P3M1=0X7B;
P3M0=0X80;
P1_7=0;
P1_4=1;
P1_3=1;
P1_2=1;
P1_1=0;
P1_0=0;
BELL=0;
for(i=0;i<60000;i++);
BELL=1;
speed=0;
TMOD=0X21;
TH1=0xEA;
TL1=0xD0;
TR1=1;
TR0=1;
TI=1;
ET1=1;
IT0=1;
EX0=1;
EA=1;
i=0;
while(1)
{
mysub();
if(need_position==1)
{
stop();
need_position=0;
}
switch(pgm_style)
{
case 0: break;
case 1: running_mode_1();
case 2: longdelay(100);//10s
i++;
if(i>97)
{
i=0;
heat_var=0;
stop();
}
break;
}
}
}
/*红外线接收程序*/
void INT0_Routine(void)interrupt 0 using 1
{
char i,j;
unsigned char infrared;
unsigned char mdata[8];
TH0=0;
TL0=0;
while(infrared!=1)
displ();
if(TH0>12)
{
TH0=0;
TL0=0;
}
else return;
while(infrared!=0)displ();
if(TH0>6)
{
TH0=0;
TL0=0;
}
else return;
for(i=0;i<4;i++)
{
mdata=0;
for(j=0;j<8;j++)
{
while(infrared!=1)displ();
TH0=0;TL0=0;
while(infrared!=0)displ();
if(TH0>1)
mdata|=0x1<<j;
}
}
if(mdata[0]!=0)return;
if(mdata[1]&0xff==0xff)return;
if((mdata[2]==0&&mdata[3])==0xff) virtual_key=1;
if((mdata[2]==4&&mdata[3])==0xfb) virtual_key=2;
if((mdata[2]==8&&mdata[3])==0xf7) virtual_key=3;
if((mdata[2]==0xc&&mdata[3])==0xf3) virtual_key=4;
}
/*PWM产生*/
void time1(void) interrupt 3 using 1
{
unsigned char MAX_VAL;
static unsigned char m_tmp=0;
static unsigned char btm_tmp=0;
if(m_tmp<=(MAX_VAL-speed)) MOTO=1;
else MOTO=0;
if(btm_tmp<=(MAX_VAL-hot)) HEAT=1;
else HEAT=0;
if(btm_tmp++>=MAX_VAL) btm_tmp=1;
if(m_tmp++>=MAX_VAL) m_tmp=1;
displ();
}
#include "STC12C5620AD.H"
#include <stdio.h>
#include <intrins.h>
#define uchar unsigned char
#define uint unsigned int
#define ulint unsigned long int
//sbit P1M1=P1;
//sbit P1M0=P1;
//sbit P3M1=P3;
//sbit P3M0=P3;
uchar pgm_style,heat_var,fast_slow_var,need_position,virtual_key,keytag;
uchar tm;
uint speed,hot;
sbit S1=P3^0;
sbit S2=P3^3;
sbit S3=P3^4;
sbit S4=P3^5;
sbit SN2=P3^1;
sbit BELL=P3^7;
bit FAST_SLOW_I;
bit FAST_SLOW_II;
bit FAST_SLOW_III;
bit HOT_Lo;
bit HOT_Hi;
bit run_tag;
bit PGM_I;
bit PGM_II;
sbit MOTO=P1^6;
sbit HEAT=P1^5;
sbit P1_7=P1^7;
sbit P1_3=P1^3;
sbit P1_2=P1^2;
sbit P1_4=P1^4;
sbit P1_1=P1^1;
sbit P1_0=P1^0;
void clr()
{
P1_7=1;
P1_3=1;
P1_2=1;
P1_4=1;
P1_1=1;
P1_0=1;
}
void stop()
{
MOTO=1;
HEAT=1;
}
void delay(uint m)
{
uchar i,j;
for(i=0;i<m;i++)
{
for(j=0;j<124;j++);
}
}
void bell()
{
{
BELL=0;//蜂鸣器响
delay(20);
BELL=1;//蜂鸣器停
delay(20);
}
}
void longdelay(uchar m)
{
uint i;
for(i=0;i<m;i++)
{
_nop_();
}
}
/*定时扫描程序*/
void displ()
{
unsigned char cnt;
cnt++;
if(cnt==40)cnt=0;
switch(cnt)
{
case 10:
clr();
P1_7=0;
P1_2=FAST_SLOW_III?1:0;
P1_3=FAST_SLOW_II?1:0;
P1_4=FAST_SLOW_I?1:0;
break;
case 20:
clr();
P1_0=0;
P1_2=PGM_II?1:0;
P1_3=PGM_I?1:0;
P1_4=HOT_Hi?1:0;
break;
case 30:
clr();
P1_1=0;
P1_2=HOT_Lo?1:0;
if(run_tag==1)P1_3=1;
else
{
if(tm++>500)P1_3=1;
else P1_3=need_position;
}
break;
}
}
/*键盘处理程序*/
char keyscan()
{
unsigned char i;
if(virtual_key==0)
{
if((P3&0x39)!=0x39)
{
if(keytag==1) return-1;
}
else
{
keytag=0;
return-1;
}
for(i=0;i<250;i++);
for(i=0;i<250;i++);
if((P3&0x39)==0x39)
{
keytag=0;
return-1;
}
}
keytag=1;
if(keytag==1||virtual_key!=0)
{
if(S1==0||virtual_key==1)
{
if(pgm_style!=0)
need_position=1;
run_tag=0;
pgm_style=0;
heat_var=0;
}
if(S2==0||virtual_key==2)
{
heat_var=(heat_var+1)%3;
}
if(S3==0||virtual_key==3)
{
pgm_style=(pgm_style+1)%3;
if(pgm_style==0)
need_position=1;
}
if(S4==0||virtual_key==4)
{
fast_slow_var=(fast_slow_var+1)%3;
}
bell();
virtual_key=0;
}
}
/*间断运行模式程序*/
int running_mode_1()
{
char i,j,k;
unsigned int heat_var;
unsigned int speed_bak;
unsigned int speed;
speed_bak=speed;
for(k=0;k<10;k++)
{
for(j=0;j<6;j++)
{
for(i=0;i<7;i++)
{
speed=speed_bak;
delay(67);
speed=0;
delay(135);
}
for(i=0;i<13;i++)
{
speed=speed_bak;
delay(30);
speed=0;
delay(70);
}
}
for(i=0;i<9;i++)
{
const unsigned char tab[18]={30,80,30,80,30,80,30,160,30,70,10,20,10,20,30,10,30,0};
speed=0;
longdelay(tab[i*2]);
speed=speed_bak;
longdelay(tab[i*2+1]);
}
}
heat_var=0;
stop();
}
/*定位程序*/
void position()
{
unsigned int cnt=1;
speed=0;
TH0=0;
while(SN2==0)
{
if(TH0>120)
{
cnt+=1;
TH0=0;
}
if(cnt>150)break;
}
delay(70);
TH0=0;
cnt=1;
while(SN2==1)
{
if(TH0>120)
{
cnt+=1;
TH0=0;
}
if(cnt>150)
break;
}
}
/*主控子程序*/
int mysub()
{
keyscan();
if(run_tag==0)
{
hot=0;
speed=0;
}
switch(heat_var)
{
case 0:
hot=0;
HOT_Hi=0;
HOT_Lo=0;
if(pgm_style==0)
run_tag=0;
break;
case 1:
hot=1;
HOT_Hi=1;
HOT_Lo=0;
run_tag=1;
break;
case 2:
hot=2;
HOT_Hi=0;
HOT_Lo=1;
run_tag=1;
break;
}
switch(pgm_style)
{
case 0:
PGM_I=0;
PGM_II=0;
FAST_SLOW_I=0;
FAST_SLOW_II=0;
FAST_SLOW_III=0;
if(heat_var==0)
run_tag=0;
break;
case 1:
PGM_I=1;
PGM_II=0;
run_tag=1;
break;
case 2:
PGM_I=0;
PGM_II=1;
run_tag=1;
break;
}
if(pgm_style!=0)
{
switch(fast_slow_var)
{
case 0:
FAST_SLOW_I=1;
FAST_SLOW_II=0;
FAST_SLOW_III=0;
speed=0;
break;
case 1:
FAST_SLOW_I=0;
FAST_SLOW_II=1;
FAST_SLOW_III=0;
speed=1;
break;
case 2:
FAST_SLOW_I=0;
FAST_SLOW_II=0;
FAST_SLOW_III=1;
speed=2;
break;
}
}
}
/*主控函数*/
void main()
{
ulint i;
P1M1=0X0;
P1M0=0XFF;
P3M1=0X7B;
P3M0=0X80;
P1_7=0;
P1_4=1;
P1_3=1;
P1_2=1;
P1_1=0;
P1_0=0;
BELL=0;
for(i=0;i<60000;i++);
BELL=1;
speed=0;
TMOD=0X21;
TH1=0xEA;
TL1=0xD0;
TR1=1;
TR0=1;
TI=1;
ET1=1;
IT0=1;
EX0=1;
EA=1;
i=0;
while(1)
{
mysub();
if(need_position==1)
{
stop();
need_position=0;
}
switch(pgm_style)
{
case 0: break;
case 1: running_mode_1();
case 2: longdelay(100);//10s
i++;
if(i>97)
{
i=0;
heat_var=0;
stop();
}
break;
}
}
}
/*红外线接收程序*/
void INT0_Routine(void)interrupt 0 using 1
{
char i,j;
unsigned char infrared;
unsigned char mdata[8];
TH0=0;
TL0=0;
while(infrared!=1)
displ();
if(TH0>12)
{
TH0=0;
TL0=0;
}
else return;
while(infrared!=0)displ();
if(TH0>6)
{
TH0=0;
TL0=0;
}
else return;
for(i=0;i<4;i++)
{
mdata=0;
for(j=0;j<8;j++)
{
while(infrared!=1)displ();
TH0=0;TL0=0;
while(infrared!=0)displ();
if(TH0>1)
mdata|=0x1<<j;
}
}
if(mdata[0]!=0)return;
if(mdata[1]&0xff==0xff)return;
if((mdata[2]==0&&mdata[3])==0xff) virtual_key=1;
if((mdata[2]==4&&mdata[3])==0xfb) virtual_key=2;
if((mdata[2]==8&&mdata[3])==0xf7) virtual_key=3;
if((mdata[2]==0xc&&mdata[3])==0xf3) virtual_key=4;
}
/*PWM产生*/
void time1(void) interrupt 3 using 1
{
unsigned char MAX_VAL;
static unsigned char m_tmp=0;
static unsigned char btm_tmp=0;
if(m_tmp<=(MAX_VAL-speed)) MOTO=1;
else MOTO=0;
if(btm_tmp<=(MAX_VAL-hot)) HEAT=1;
else HEAT=0;
if(btm_tmp++>=MAX_VAL) btm_tmp=1;
if(m_tmp++>=MAX_VAL) m_tmp=1;
displ();
}
足疗机 太叼了 谢谢分享
就你这写的程序我不敢恭维,BUG很多,程序跑飞很正常。
小编有没有硬件图!
上面我说错了,其实就是个设计一个足疗机控制器程序。有主控板原理图的
哎,这不是不会吗?所以来请大神们指导指导