实测通过6位数码管显示程序_第1页
实测通过6位数码管显示程序_第2页
实测通过6位数码管显示程序_第3页
实测通过6位数码管显示程序_第4页
实测通过6位数码管显示程序_第5页
已阅读5页,还剩13页未读 继续免费阅读

下载本文档

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

文档简介

1、0.110累加 控制数码管低2位显示从0.1到9.9累加,步进为0.1实验源程序:/*/主函数/*void main() /主函数 num=0; /初始化段码为0 while(1) /进入while死循环 scan(); /数码管扫描函数 /*/动态扫描函数/*scan() uchar i; for(i=0;i10;i+) /显示个位 P1=0xbf; /0xbf=1011 1111,即选通个位 LE1=1; /锁存位 LE1=0; /断开锁存,位选573的Q7Q0仍保持 wei=num*10; P1=diswei/10 | 0x80; /diswei/10为09的编码,0x80为小数点 LE

2、2=1; /锁存段码 LE2=0; /断开锁存,段选573的Q7Q0仍保持 delay(100); /延时保持一下,延时过大会闪动,延时过小会有重影 P1=0x00;LE2=1;LE2=0; /清除P1口数据,以免造重影 /显示十分位 P1=0x7f; /0xbf=0111 1111,即选通十分位 LE1=1; /锁存位 LE1=0; /断开锁存,位选573的Q7Q0仍保持 wei=num*10; P1=diswei%10; /09的编码 LE2=1; /锁存段码 LE2=0; /断开锁存,段选573的Q7Q0仍保持 delay(100); /延时保持一下,延时过大会闪动,延时过小会有重影 P

3、1=0x00;LE2=1;LE2=0; /清除P1口数据,以免造重影 if(num=9.9)num=0; /扫描到显示9.9时,重新开始扫描 num+=0.1; /num加0.1/*以下各个程序是实测通过的6位共阳数码管显示程序(c51) 2014.08.20.实测通过 仿TX-3C实验板 晶振为 11.0592M*/*共阴led数码管码表:()/*code uchar shu = 0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07, 0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71; /共阴数码管段选码(0-f) */ */* 高位(

4、7) - 低位(0) 位 0 0 0 0 0 0 0 0 共阳数码管段选码(0-f) 笔画 h g f e d c b a (小数点不亮码):0xc0, 0xf9, 0xa4, 0xb0, 0x99, 0x92, 0x82, 0xf8, 0x80, 0x90, 0x88, 0x83, 0xc6, 0xa1, 0x86, 0x8e; 0 1 2 3 4 5 6 7 8 9 a b c d e f /共阳数码管段选码(0-f) (高位减8即可,在段码中加上&0x7f 即:P0=tablege&0x7f;) (带小数点亮码): /P0=tablege&0x7f; 或 P0=tablege&0x80;

5、 该位小数点也亮。 注: 7f 与 80 互为反码。 0x40,0x79,0x24,0x30,0x19,0x12,0x02,0x78,0x00,0x10,0x08,0x03,0x46,0x21,0x06,0x0e; 0 1 2 3 4 5 6 7 8 9 a b c d e f */:静态方式显示6位数字#include /52单片机头文件sbit dula=P26; /单片机管脚位声明sbit wela=P27; /#define uint unsigned int /宏定义/#define uchar unsigned char /宏定义/#include /包含有左右循环移位子函数的库v

6、oid delay(unsigned int z) /延时函数 (z的取值为这个函数的延时ms数,如: delay(200);大约延时200ms). unsigned int x,y; /定义2个int型变量 for(x=z;x0;x-) for(y=110;y0;y-); void main() /主函数 /P1=0xff; /将单片机P1口清零while(1) /程序停止在这里(大循环) /*dula=1; P0=0xff; /送位数据前关闭所有显示,防止打开位选锁存后段选数据通过位选锁存器 /delay(500); P0=!P0; qdelay(500); /延时500毫秒 dula=0

7、; delay(2); /延时2毫秒 */ /* P0=0x00; delay(2); wela=1; P0=0x03; wela=0; delay(5); */dula=1; P0=0x99; /送段码 dula=0;delay(2); P0=0xff; /送位数据前关闭所有显示,防止打开位选锁存后段选数据通过位选锁存器wela=1; P0=0x01; /送位码/*0x00 0000 0000 6个数码管全部不亮0x01 0000 0001 从左往右第1位都亮0x03 0000 0011 前2位都亮 0x07 0000 0111 前3位都亮0x0f 0000 1111 前4位都亮 0x1f

8、0001 1111 前5位都亮0x3f 0011 1111 前6位都亮 /0x7f 0111 1111 前6位亮0x20 0010 0000 从左往右第6位亮 0x10 0001 0000 从左往右第5位亮 0x08 0000 1000 从左往右第4位亮 0x04 0000 0100 从左往右第3位亮 0x02 0000 0010 从左往右第2位亮 0x01 0000 0001 从左往右第1位亮 */wela=0; delay(2); /*delay(1000); P1=P1; */ :动态方式稳定显示6个数字:#include # define uint unsigned int # def

9、ine uchar unsigned char sbit dula = P26; sbit wela = P27;uchar code table = 0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8, 0x80,0x90,0x88,0x83,0xc6,0xa1,0x86,0x8e; void delayms(uint);void main()while(1)dula = 1;P0 = table1;dula = 0;P0 = 0xff;wela = 1;P0 = 0x01;wela = 0;delayms(500); /改小延时时间,即成为动态显示了。改到10m

10、s时仍有闪烁感,改成1ms5ms内较为合适。dula = 1;P0 = table2;dula = 0;P0 = 0xff;wela = 1;P0 = 0x02;wela = 0;delayms(500);dula = 1;P0 = table3;dula = 0;P0 = 0xff;wela = 1;P0 = 0x04;wela = 0;delayms(500);dula = 1;P0 = table4;dula = 0;P0 = 0xff;wela = 1;P0 = 0x08;wela = 0;delayms(500);dula = 1;P0 = table5;dula = 0;P0 =

11、0xff;wela = 1;P0 = 0x10;wela = 0;delayms(500);dula = 1;P0 = table6;dula = 0;P0 = 0xff;wela = 1;P0 = 0x20;wela = 0;delayms(500);void delayms(uint xms) uint i,j; for(i = xms; i0; i-) for(j = 110; j0; j-); /*void xianshi() /显示函数 uchar i; for(i = 0; i6; i+) P0=weni; /位选 wei=1; /开74HC573锁存 wei=0; /关74HC5

12、73锁存 P0=huancuni; /段选 duan=1; duan=0; P0=0xff; /消影 delay(5); void init() uchar i; TMOD=0x01; TH0=(65536-50000)/256; /10ms定时初值(T0计时用) TL0=(65536-50000)%256; TR0=1; /T0计时关断 ET0=1; /T0中断允许位关断 EA=1; /开总中断 for(i = 0; i6; i+) huancuni = shui; /段选送缓存 void main() init(); while(1) xianshi(); void time_intt0

13、(void) interrupt 1 /50ms中断 uchar t,i,j; TH0=(65536-50000)/256; /重置初值 TL0=(65536-50000)%256; t+; if(t = 20) /1秒到 50ms*20 = 1s t=0; j+; /j+1 for(i = 0; i9) /移到最后面 回到初始状态 (即显示第8位后的第9位就是回到原来的第1位循环) j = 0; */: 6位共阳数码管循环显示ABCDEF,六个数码管是连续不同的六个数#include # define uint unsigned int # define uchar unsigned cha

14、r code uchar shu = 0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8, 0x80,0x90,0x88,0x83,0xc6,0xa1,0x86,0x8e; /共阳数码管段选码(0-f) /uchar code DIS_BIT8=0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f; /数码管位选(8位)/*code uchar shu = 0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07, 0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71; /共阴数码管段选码(0

15、-f) */ code uchar wen = 0x01,0x02,0x04,0x08,0x10,0x20; /数码管位选(6位) uchar huancun = 0x00,0x00,0x00,0x00,0x00,0x00; /数码管段选缓存(即缓存需要显示的6位数码管段选码) sbit duan = P26; /段选sbit wei = P27; /位选 void delay(uchar x) /延时函数(延时函数在主函数前面的,则不需要子函数申明) uchar i,j; for(i = 0; ix; i-) for(j = 0; j250; j-); void xianshi() /显示函

16、数 uchar i; for(i = 0; i6; i+) P0=weni; /位选 wei=1; /开74HC573锁存 wei=0; /关74HC573锁存 P0=huancuni; /段选 duan=1; duan=0; P0=0xff; /消影 delay(5); /延时5ms void init() uchar i; TMOD=0x01; TH0=(65536-50000)/256; /10ms定时初值(T0计时用) TL0=(65536-50000)%256; TR0=1; /T0计时关断 ET0=1; /T0中断允许位关断 EA=1; /开总中断 for(i = 0; i6; i

17、+) huancuni = shui; /段选送缓存 void main() init(); while(1) xianshi(); void time_intt0 (void) interrupt 1 /50ms中断 uchar t,i,j; TH0=(65536-50000)/256; /重置初值 TL0=(65536-50000)%256; t+; if(t = 20) /1秒时间到。 (50ms*20=1s) t=0; j+; /j+1 for(i = 0; i9) /移到最后面 回到初始状态 (即显示第8位后的第9位就是回到原来的第1位循环) j = 0; 秒计时00至59秒 动态显

18、示最后2个数码管/* 高位(7) - 低位(0) 位 0 0 0 0 0 0 0 0 共阳数码管段选码(0-f) 笔画 h g f e d c b a (小数点不亮码):0xc0, 0xf9, 0xa4, 0xb0, 0x99, 0x92, 0x82, 0xf8, 0x80, 0x90, 0x88, 0x83, 0xc6, 0xa1, 0x86, 0x8e; 0 1 2 3 4 5 6 7 8 9 a b c d e f 共阳数码管段选码(0-f) (高位减8即可) (带小数点亮码): 0x40,0x79,0x24,0x30,0x19,0x12,0x02,0x78,0x00,0x10,0x08

19、,0x03,0x46,0x21,0x06,0x0e; 0 1 2 3 4 5 6 7 8 9 a b c d e f */*0x00 0000 0000 6个数码管全部不亮0x01 0000 0001 从左往右第1位都亮0x03 0000 0011 前2位都亮 0x07 0000 0111 前3位都亮0x0f 0000 1111 前4位都亮 0x1f 0001 1111 前5位都亮0x3f 0011 1111 前6位都亮 /0x7f 0111 1111 前6位亮0x20 0010 0000 从左往右第6位亮 0x10 0001 0000 从左往右第5位亮 0x08 0000 1000 从左往右

20、第4位亮 0x04 0000 0100 从左往右第3位亮 0x02 0000 0010 从左往右第2位亮 0x01 0000 0001 从左往右第1位亮 */*动态显示59秒 2014.09.20.*/#include # define uchar unsigned char /# define uint unsigned intuchar j,i,a,A1,A2,A3,second;/*uchar j,i,a,A1,A2,A3;uint second;*/sbit dula = P26; sbit wela = P27;uchar code table = 0xc0,0xf9,0xa4,0x

21、b0,0x99,0x92,0x82,0xf8, 0x80,0x90,0x88,0x83,0xc6,0xa1,0x86,0x8e; /共阳段码void delay(uchar i) /延时函数for(j=i;j0;j-)for(i=125;i0;i-);void display(uchar sh_c,uchar g_c) /显示函数/void display(uchar ba_c,uchar sh_c,uchar g_c) /显示函数dula=1;/*P0=tableba_c; /显示个位数码管的值dula=1; /产生一个下降沿将数据锁存dula=0;wela=0;P0=0x08;/送位码点亮

22、十位数码管wela=1;wela=0;delay(5);/调用延时函数,数码管亮5ms*/P0=tablesh_c&0x7f; /段码送至P0口,显示十位数码管的值,并在十位数码管上显示小数点。dula=1; /产生一个下降沿将数据锁存dula=0;wela=0;P0=0x10;/送位码点亮个位数码管wela=1;wela=0;delay(5);/调用延时函数,数码管亮5msP0=tableg_c; /显示个位数码管的值dula=1; /产生一个下降沿将数据锁存dula=0;wela=0;P0=0x20;/送位码点亮十位数码管wela=1;wela=0;delay(5);/调用延时函数,数码管

23、亮5msvoid main()while(1)second+; /计数,秒加一if(second=60) /判断是否加到了60秒second=0;/若到了60则清零A1=second/10; /否则分离出百位和十位及个位的值A2=second%10;/*second+; /计数自加一if(second=1000)second=0; /判断是否加到了1000,若到了1000则清零.A1=second/100; /否则分离出百位和十位及个位的值A2=second%100/10;A3=second%10;*/for(a=225;a0;a-) / 1秒延时display(A1,A2); /display(A1,A2,A3);

温馨提示

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

评论

0/150

提交评论