|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区
您需要 登录 才可以下载或查看,没有账号?立即注册
×
[paragraph]
51单片机“呼吸灯”程序
#include | #define uchar unsigned char | #define uint unsigned int | uint f=100; /*????????f????????????1~10khz*/ | uint H=6;/*????????·§????????0~10000/f????H>L*/ | uint L=0;/*????????·§????????0~10000/f????H>L*/ | uchar code wela[]={0xfe,0xfd,0xfb,0xf7}; | uchar code dula[]={0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xD8,0x80,0x90}; | uint m=0,t; | uchar amp=0,frequency=100; | sbit pwm=P1^7; | sbit pwm_=P1^6; | sbit hkey=P3^5; | sbit lkey=P3^3; | void diskey(); | void delay(uint z); | void display(); | void xunhuan(); | void main() | { | EA=1; | ET0=1; | TMOD=0x02; | TH0=146; | t=10000/f; | TR0=1; | while(1) | { | if(hkey==0)diskey(); | if(lkey==0)diskey(); | display(); | xunhuan(); | } | } | void TRT0() interrupt 1 | { | m++; | if(m>=t)m=0; | if(m==L){pwm=0;} | if(m==H){pwm=1;pwm_=0;} | } | void diskey() | { | display(); | if(hkey==0&&H<100)H++; | delay(10); | if(lkey==0&&H>0)H--; | display(); | } | void xunhuan() | { | if(amp==1)H++; | if(H>99)amp=0; | if(amp==0)H--; | if(H<1)amp=1; | delay(frequency); | } | void delay(uint z) | { | uint x,y; | for(y=z;y>0;y--) | for(x=12;x>0;x--); | } | void display() | { | delay(2); | P2=dula[H/1000]; | P0=wela[0]; | delay(5); | P0=0xff; | P2=dula[H00/100]; | P0=wela[1]; | delay(5); | P0=0xff; | P2=dula[H0/10]; | P0=wela[2]; | delay(5); | P0=0xff; | P2=dula[H]; | P0=wela[3]; | delay(5); | P0=0xff; | } |
|
|