急救,请高手协助
要求:
1、上电灯开始循环流水灯,
2、当按下按键K后灯全亮,且蜂鸣器开始唱生日快乐歌,放开按键后灯开始流水且蜂鸣器停止。
程序如下:
说明:P2.0接蜂鸣器,P2.1接按键K,P1口接8个灯
#include <reg52.h> #include <intrins.h> #define uchar unsigned char #define uint unsigned int sbit beep=P2^0; sbit down=P2^1; uchar code table[]={400,400,650,650,650,1200, 400,400,650,650,650,1200, 400,400,650,650,650,650,1200, 400,400,650,650,650,1200} ; uchar code table1[]={0xfd,0x79,0xfd,0x79,0xfd,0xc7,0xfd,0x79,0xfe,0x21,0xfe,0x05, 0xfd,0x79,0xfd,0x79,0xfd,0xc7,0xfd,0x79,0xfe,0x51,0xfe,0x21, 0xfd,0x79,0xfd,0x79,0xfe,0xc0,0xfe,0x84,0xfe,0x21,0xfe,0x05,0xfd,0xc7, 0xfe,0x99,0xfe,0x99,0xfe,0x90,0xfe,0x21,0xfe,0x51,0xfe,0x21 }; uchar temp,i,j,time1,time2; void delay(uint z) { uint t,y; for(t=z;t>0;t--) for(y=125;y>0;y--); } void main() { TMOD=0x01; TH0=0; TL0=0; EA=1; ET0=1; TR0=1; temp=0xfe; P1=temp; while(1) { temp=_crol_(temp,1); delay(500); P1=temp; if(down==0) { P1=~P1; beep=~beep; time1=table[i++]; time2=table[i++]; if(i==50) i=0; delay(table1[j++]); if(j==25) j=0; } } }
void timer0() interrupt 1 { TR0=0; TH0=time1; TL0=time2; TR0=1; }
|