用51單片機做的小旋磁美容儀
#include reg51.H>
#define uint unsigned int
#define uchar unsigned char
#define duan P0
#define ton 2
#define t 20
uchar code tab[]={0x09,0x5f,0x2a,0x1a,0x5c,0x98,0x88,0x1f,0x08,0x18};
sbit xsd_display=P0^3;//小數點的位顯示,根據實際情況決定
sbit shila=P2^4;
sbit gela=P2^5;
sbit hotla=P2^6;
sbit xuanla=P2^7;
sbit hotout=P2^0;
sbit xuanout=P2^1;
sbit fmqbit=P2^2;
bit openbit,xsd;//開關機、小數點、加熱、旋轉標志位
uchar time; //分鐘值
uint d; //計分鐘變量
bit fmq;
uchar hot,hot1,hotoff,hotoff1,hotled; //加熱波形處理相關變量
uchar xuan,xuan1,xuanoff,xuanoff1,xuanled; //旋轉相關變量
bit biaobit0,biaobit1,biaobit2,biaobit3;// 控制波形占空時的循環(huán)條件標志位//以下為延時子程序
void delay(uint a)
{
uchar c,d;
for(c=a;c>0;c--)
for(d=80;d>0;d--);
}
//以下為顯示函數
void display(uchar x,uchar y,uchar k)
{
uchar ge,shi; //對傳遞時間函數進行分解
shi=x/10;
ge=x%10; duan=tab[shi];
shila=0;
delay(2);
shila=1; duan=tab[ge];
gela=0;
xsd_display=xsd;
delay(2);
gela=1; duan=tab[y];
hotla=0;
delay(2);
hotla=1; duan=tab[k];
xuanla=0;
delay(2);
xuanla=1;// duan_display=0xff;
}//以下為變量改變處理程序
void bianlian(uchar xy)
{
switch(xy)
{
case 2: d=0; //有按鍵按動時即使計數值初始為0
if(time!=99)
{
time++;
}
break; case 3: d=0; //有按鍵按動時即使計數值初始為0
if(time!=0)
{
time--;
}
break; case 4: if(hotled!=8)
{
hotled++;
if(hotled==8)
biaobit0=1;
else
biaobit0=0;
if(hotled==0)
biaobit1=1;
else
biaobit1=0;
if(hotled5)
{
hot=hot+3;
}
else
{
hot=hot+ton;
} hot1=hot;
hotoff=t-hot;
hotoff1=hotoff;
}
break; case 5:if(hotled!=0)
{
hotled--; if(hotled==8)
biaobit0=1;
else
biaobit0=0; if(hotled==0)
biaobit1=1;
else
biaobit1=0; if(hotled4)
{
hot=hot-3;
}
else
{
hot=hot-ton;
} hot1=hot;
hotoff=t-hot;
hotoff1=hotoff;
}
break;
case 6:
if(xuanled!=8)
{
xuanled++; if(xuanled==8)
biaobit2=1;
else
biaobit2=0;
if(xuanled==0)
biaobit3=1;
else
biaobit3=0; if(xuanled==1)
xuan=xuan+6;
else
xuan=xuan+ton; xuan1=xuan;
xuanoff=t-xuan;
xuanoff1=xuanoff;
}
break;
case 7:
if(xuanled!=0)
{ if(xuanled==1)
xuan=xuan-6;
else
xuan=xuan-ton; xuan1=xuan;
xuanoff=t-xuan;
xuanoff1=xuanoff;
xuanled--; if(xuanled==8)
biaobit2=1;
else
biaobit2=0;
if(xuanled==0)
biaobit3=1;
else
biaobit3=0; }
default:break;
}
} 蜂鳴器相關文章:蜂鳴器原理
評論