51单片机流水灯、数码管、定时器、秒表、计算器程序.doc_第1页
51单片机流水灯、数码管、定时器、秒表、计算器程序.doc_第2页
51单片机流水灯、数码管、定时器、秒表、计算器程序.doc_第3页
51单片机流水灯、数码管、定时器、秒表、计算器程序.doc_第4页
51单片机流水灯、数码管、定时器、秒表、计算器程序.doc_第5页
已阅读5页,还剩12页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

流水灯#includechar data_group=0x7e,0xbd,0xdb,0xe7,0xdb,0xbd,0x7e;unsigned int a;void delay(unsigned int time)int i,j;for(i=time;i0;i-)for(j=100;j0;j-);void move_mid_side(void) int m;for(m=0;m=0;a-)temp=temp;P1=temp;delay(500);temp=temp;temp=1;temp=0x80;delay(1000);void move_left_only(void)int a,temp;delay(500);temp=0x01;for(a=7;a=0;a-)temp=temp;P1=temp;delay(500);temp=temp;temp=0;a-)P1=temp;delay(500);temp=temp1;temp=temp;delay(1000);void move_left_hold(void)int a,temp;temp=0xfe;for(a=8;a=0;a-)P1=temp;delay(500);temp=1;temp=temp;delay(1000);void main()while(1)move_left_hold();move_mid_side();move_right_hlod();move_mid_side();move_left_only();move_right_only();数码管#include char data_duan=0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90;/09char data_wei=0xff,0x7f,0xbf,0xdf,0xef,0xf7,0xfb,0xfd,0xfe,0x00; /0xff全关,之后为第一个数码管到第八个数码管/char data_wei_add=0x7f,0x3f,0x1f,0x0f,0x07,0x03,0x01,0x00;void delay(unsigned int time) int i,j;for(i=time;i0;i-) for(j=0;j100;j+);void show_number_only(void)int i;P2=data_wei1; /P2为位选for(i=0;i10;i+)P0=data_duani;/P0为段选delay(500);/*数码管动态显示子程序*/void move_show1(void)int i;for(i=1;i2;i+)P2=data_weii;P0=data_duani;delay(1);void move_show2(void)int i;for(i=1;i3;i+)P2=data_weii;P0=data_duani;delay(1);void move_show3(void)int i;for(i=1;i4;i+)P2=data_weii;P0=data_duani;delay(1);void move_show4(void)int i;for(i=0;i5;i+)P2=data_weii;P0=data_duani;delay(1);void move_show5(void)int i;for(i=0;i6;i+)P2=data_weii;P0=data_duani;delay(1);void move_show6(void)int i;for(i=0;i7;i+)P2=data_weii;P0=data_duani;delay(1);void move_show7(void)int i;for(i=0;i8;i+)P2=data_weii;P0=data_duani;delay(1);void move_show8(void)int i;for(i=0;i0;i-) move_show1();temp=600;for(i=temp;i0;i-)move_show2();temp=400;for(i=temp;i0;i-)move_show3();temp=200;for(i=temp;i0;i-)move_show4();temp=200;for(i=temp;i0;i-)move_show5();temp=200;for(i=temp;i0;i-)move_show6();temp=100;for(i=temp;i0;i-)move_show7();temp=100;for(i=temp;i0;i-)move_show8(); void show_all(void) /将所有的位选端口打开,变化段选,显示整体变化19int i;P2=data_wei9;for(i=0;i10;i+)P0=data_duani;delay(500); int main(void)while(1)/show_number_only();move_show8();/move_show_hold();/show_all();独立按键#include sbit key1=P30;sbit d2=P10;int temp,number=0;void delay(unsigned int time)int i,j;for(i=time;i0;i-)for(j=100;j0;j-) ;int main(void)temp=0xfe;while(1)d2=1;key1=1;P1=temp;if(key1=0)delay(100);if(key1=0) number+; if(number=7) temp=temp; temp=temp1; temp=temp; P1=temp;elsetemp=0xfe;number=0;矩阵按键#includechar data_duan=0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0x88,0x80,0xc6,0xc0,0x86,0x8e,;/09char data_wei=0xff,0x7f,0xbf,0xdf,0xef,0xf7,0xfb,0xfd,0xfe,0x00; int number=0;void delay(unsigned int time) int i,j;for(i=time;i0;i-) for(j=0;j100;j+);/void move_show1(void)/int i;/for(i=1;i2;i+)/P2=data_weii;/P0=data_duani;/delay(1);/void move_show2(void)/int i;/for(i=1;i3;i+)/P2=data_weii;/P0=data_duani;/delay(1);/void scan_key(void)int temp;P1=0xfe;temp=P1;temp=temp&0xf0;while(temp!=0xf0) delay(1);temp=P1;temp=temp&0xf0;while(temp!=0xf0) switch(temp)case 0xe0:number=12;break;case 0xd0:number=13;break;case 0xb0:number=14;break; case 0x70:number=15;break;while(temp!=0xf0) temp=P1; temp=temp&0xf0;P1=0xfd;temp=P1;temp=temp&0xf0;while(temp!=0xf0) delay(1);temp=P1;temp=temp&0xf0;while(temp!=0xf0)switch(temp)case 0xe0:number=8;break;case 0xd0:number=9;break;case 0xb0:number=10;break; case 0x70:number=11;break;while(temp!=0xf0) temp=P1; temp=temp&0xf0;P1=0xfb;temp=P1;temp=temp&0xf0;while(temp!=0xf0) delay(1);temp=P1;temp=temp&0xf0;while(temp!=0xf0)switch(temp)case 0xe0:number=4;break;case 0xd0:number=5;break;case 0xb0:number=6;break; case 0x70:number=7;break;while(temp!=0xf0) temp=P1; temp=temp&0xf0;P1=0xf7;temp=P1;temp=temp&0xf0;while(temp!=0xf0) delay(1);temp=P1;temp=temp&0xf0;while(temp!=0xf0)switch(temp)case 0xe0:number=0;break;case 0xd0:number=1;break;case 0xb0:number=2;break; case 0x70:number=3;break;while(temp!=0xf0) temp=P1; temp=temp&0xf0;/return number;int main(void)/int num=0;while(1)/num=scan_key(num);scan_key(); P2=data_wei1; P0=data_duannumber;定时器中断#include char data_duan=0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90;/09char data_wei=0xff,0x7f,0xbf,0xdf,0xef,0xf7,0xfb,0xfd,0xfe,0x00; /0xff全关,之后为第一个数码管到第八个数码管int number=0,time=0;int main(void)/TMOD=0x01;/设置工作方式定时器0/TH0=(65536-50000)/256; /给计数器装初值/TL0=(65535-50000)%256;/EA=1; /开总中断/ET0=1; /定时器T0中断允许/TR0=1; /启动定时器0TMOD=0x10;/设置工作方式定时器1TH1=(65536-50000)/256; /给计数器装初值TL1=(65535-50000)%256;EA=1; /开总中断ET1=1; /定时器T1中断允许TR1=1; /启动定时器1while(1)if(number=20) P2=data_wei2;P0=data_duan4; if(time=40) P2=data_wei0;number=0;time=0; void exter3() interrupt 3TH1=(65536-50000)/256; /给计数器装初值TL1=(65535-50000)%256;time+;number+;/void exter1() interrupt 1/TH0=(65536-50000)/256; /给计数器装初值/TL0=(65535-50000)%256;/time+;/number+;/时钟#include char data_duan=0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90;/09char data_wei=0xff,0x7f,0xbf,0xdf,0xef,0xf7,0xfb,0xfd,0xfe,0x00; unsigned long int second=0,minute=0,hour=0,point=0,tip=0;unsigned long int time=0,sign=0,number=0,key=0,variable=0;unsigned long int S1=0,S2=0,M1=0,M2=0,H1=0;H2=0;void delay(unsigned int time) int i,j;for(i=time;i0;i-) for(j=0;jvariable) ; void alarm_show_s(void)int sign2;for(sign2=1;sign22;sign2+) /数码管动态显示 S1=second%10; P2=data_weisign2; P0=data_duanS1; delay(1); for(sign2=2;sign23;sign2+) S2=second/10; P2=data_weisign2; P0=data_duanS2; delay(1); for(sign2=3;sign24;sign2+) P2=data_weisign2; P0=0xbf; delay(1); for(sign2=4;sign25;sign2+) M1=minute%10; P2=data_weisign2; P0=data_duanM1; delay(1); for(sign2=5;sign26;sign2+) M2=minute/10; P2=data_weisign2; P0=data_duanM2; delay(1); for(sign2=6;sign27;sign2+) P2=data_weisign2; P0=0xbf; delay(1); for(sign2=7;sign28;sign2+) H1=hour%10

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论