用C語(yǔ)言實(shí)現(xiàn)鍵控彩燈系統(tǒng)
源程序:
#include "reg51.h"#define uchar unsigned charuchar flag;uchar light,assum;void delay05s(){unsigned char i,j,k;for(i=5;i>0;i--)for(j=200;j>0;j--)for(k=250;k>0;k--);}void delay10ms(void){unsigned char i,j;for(i=20;i>0;i--)for(j=250;j>0;j--)} void left(){light=light1;if(light==1) light=0x01;P2=~light;}void right(){light=light>>1;if(light==0) light=0x80;P2=~light;}void assum(){uchar code dispcode[8]={0x7e,0xbd.0xdb,0xe7,0xdb,0xbd,0x7e,0xff};if(assum==7) assum=0;elseassum++;}void main(){IT0=1;EX0=1;EA==1;flag=1;light=0x01;assum=0;while(1){switch(flag){case 1: left(); break;case 2: right(); break;case 3: assum() break;}delay05s();}}void int-0() interrupt 0{delay10ms();if(INT0==0){flag++;if(flag>3) flag=1;}}
評(píng)論