单片机C语言LED广告灯程序
时间:10-17
来源:互联网
点击:
这是两块C51芯片控制的程序 第一块是闹钟计时器:
代码:
#include at89x51.h>unsigned char a[10]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};unsigned char b[6]={0x7e,0x7d,0x7b,0x77,0x6f,0x5f};unsigned char c[6]={5,5,9,5,8,0};unsigned char d[6]={0,0,0,0,9,0};unsigned char i,f,r,j=0x0f,k=0,x=0;unsigned char s=55,m=59,h=8;unsigned char ns=0,nm=0,nh=9;void main(void){TMOD=0x01;TH0=15536/256;TL0=15536%256;EA=0x01;ET0=0x01;TR0=0x01;while(1){if(P1_3==0){j=~j;while(P1_3==0);}switch(j){ case 0xf0:for(x=0;x6;x++){P3=b[x];P2=a[d[x]];for(i=0;i255;i++) ;switch(P1){ case 0xfe:ns=ns+1;if(ns==60) {ns=0;} while(P1_0==0);break;case 0xfd:nm=nm+1;if(nm==60) {nm=0;} while(P1_1==0);break;case 0xfb:nh=nh+1;if(nh==24) {nh=0;} while(P1_2==0);break;} }break;case 0x0f: for(x=0;x6;x++){ P3=b[x];P2=a[c[x]];for(i=0;i255;i++);switch(P1){ case 0xfe:s=s+1;if(s==60) {s=0;} while(P1_0==0);break;case 0xfd:m=m+1;if(m==60) {m=0;} while(P1_1==0);break;case 0xfb:h=h+1;if(h==24) {h=0;} while(P1_2==0);break;} }break; }}}void zd(void) interrupt 1{TH0=0x01;TL0=0x01;k=k+1;if(k==20) {k=0;s=s+1;if(s==60) {s=0;m=m+1;if(m==60){m=0;h=h+1;if(h==24){h=0;}}} }if(s==nsm==nmh==nh){P3_7=~P3_7; for(f=0;f80;f++){for(i=0;i255;i++);for(r=0;r255;r++);}} c[0]=s%10;c[1]=s/10;c[2]=m%10;c[3]=m/10;c[4]=h%10;c[5]=h/10;d[0]=ns%10;d[1]=ns/10;d[2]=nm%10;d[3]=nm/10; d[4]=nh%10;d[5]=nh/10;}第二块是加延时的LED灯程序:代码:#includeat89x51.h>#define uchar unsigned char#define uint unsigned intuchar code Pattern_P0[]={0xfc,0xf9,0xf3,0xe7,0xcf,0x9f,0x3f,0x7f,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xe7,0xdb,0xbd,0x7e,0xbd,0xdb,0xe7,0xff,0xe7,0xc3,0x81,0x00,0x81,0xc3,0xe7,0xff,0xaa,0x55,0x18,0xff,0xf0,0x0f,0x00,0xff,0xf8,0xf1,0xe3,0xc7,0x8f,0x1f,0x3f,0x7f,0x7f,0x3f,0x1f,0x8f,0xc7,0xe3,0xf1,0xf8,0xff,0x00,0x00,0xff,0xff,0x0f,0xf0,0xff,0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x7f,0xbf,0xdf,0xef,0xf7,0xfb,0xfd,0xfe,0xfe,0xfe,0xf8,0xf0,0xe0,0xc0,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0xc0,0xe0,0xf0,0xf8,0xfc,0xfe,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff};uchar code Pattern_P2[]={0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xfe,0xfc,0xf9,0xf3,0xe7,0xcf,0x9f,0x3f,0xff,0xe7,0xdb,0xbd,0x7e,0xbd,0xdb,0xe7,0xff,0xe7,0xc3,0x81,0x00,0x81,0xc3,0xe7,0xff,0xaa,0x55,0x18,0xff,0xf0,0x0f,0x00,0xff,0xf8,0xf1,0xe3,0xc7,0x8f,0x1f,0x3f,0x7f,0x7f,0x3f,0x1f,0x8f,0xc7,0xe3,0xf1,0xf8,0xff,0x00,0x00,0xff,0xff,0x0f,0xf0,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f,0x7f,0xbf,0xdf,0xef,0xf7,0xfb,0xfd,0xfe,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xfe,0xfc,0xf8,0xf0,0xe0,0xc0,0x80,0x00,0x00,0x80,0xc0,0xc0,0xf0,0xf8,0xfc,0xfe,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff};//延时void Delay(uint x){uchar i;while(x--){for(i=0;i120;i++);}}//主程序void main(){uchar i;while(1){//从数组中读取数据送至P0和P2口显示P2=0x00;while(P1_0==~P1_0){for(i=0;i136;i++){ P0=Pattern_P0[i];P2=Pattern_P2[i];Delay(100); }}}}
- FPGA的DSP性能揭秘(06-16)
- 基于单片机通用引脚的软件UART设计(10-16)
- 分时操作系统思想在单片机中的具体应用 (10-30)
- 基于AT89C51+DSP的双CPU伺服运动控制器的研究(05-26)
- 关于RTX51 TINY的分析与探讨(05-30)
- 基于MC9S12DGl28单片机的智能寻迹车设计(04-03)