资源描述
单击此处编辑母版标题样式,单击此处编辑母版文本样式,第二级,第三级,第四级,第五级,*,*,*,第5章 数码管显示程序,第5章 数码管显示程序,本章重要内容:,5.1 数码管显示代码,5.2 测定单个数码管显示代码,5.3 单个数码管显示0-9-F,5.4 数组的应用,重写一亮一灭程序,5.5 多种数码管串行显示图,5.6 数码管显示0000-9999,5.7 数码管显示时间格式为:20-35-46或20 35 46,5.1,数码管显示代码,5.1,数码管显示代码,程序:数码管显示代码,#include,main(),while(1),P1=0 xfe;,成果显示:数码管显示0,5.1,单个数码管显示代码,数码管显示代码,就是能让数码管显示正常数字的数据。,5.2 测定单个数码管显示代码数码管每次亮一种笔划,#include,void delay_1s(unsigned int x);,main(),while(1),P1=0 xfe;/11111110 =0 xfe,delay_1s(4);,P1=0 xfd;/11111101,delay_1s(4);,P1=0 xfb;/11111011,delay_1s(4);,P1=0 xf7;/11110111,delay_1s(4);,P1=0 xef;/11101111,delay_1s(4);,P1=0 xdf;/11011111,delay_1s(4);,P1=0 xbf;/10111111,delay_1s(4);,P1=0 x7f;/01111111,delay_1s(4);,void delay_1s(unsigned int x),while(x-);,成果显示:本来的8个LED变成流水灯,变成了数码管每次亮一种笔划,请记住亮一种笔划的次序。,5.2 测定单个数码管显示代码单步测试单个数码管笔划次序,#include,main(),while(1),P2=0 xfe;/1111 1110 第1个数据,记住亮笔划位置/P2=0 xfd;/1111 1101 第2个数据,记住亮笔划位置/P2=0 xfb;/1111 1011 第3个数据,记住亮笔划位置/P2=0 xf7;/1111 0111 第4个数据,记住亮笔划位置/P2=0 xef;/1110 1111 第5个数据,记住亮笔划位置/P2=0 xdf;/1101 1111 第6个数据,记住亮笔划位置/P2=0 xbf;/1011 1111 第7个数据,记住亮笔划位置/P2=0 x7f;/0111 1111 第8个数据,记住亮笔划位置,5.2 测定单个数码管显示代码单步测试单个数码管笔划次序,阐明:P2口接到数码管8个引脚上,每次只执行一种送数据语句,记住亮笔划位置;,变化注解行,执行另一种送数据语句,记住亮笔划位置;,问题提出:数码管怎样才能显示09数字,程序5-3 数码管显示09的数,#include,void delay_1s(unsigned int x);,main(),while(1),P1=0 xfe;/11111110 =0 xfe,delay_1s(4);,P1=0 xfd;/11111101,delay_1s(4);,P1=0 xfb;/11111011,delay_1s(4);,P1=0 xf7;/11110111,delay_1s(4);,P1=0 xef;/11101111,delay_1s(4);,P1=0 xdf;/11011111,delay_1s(4);,P1=0 xbf;/10111111,delay_1s(4);,P1=0 x7f;/01111111,delay_1s(4);,/延时函数void delay_1s(unsigned int x)while(x-);,阐明:P1口接到数码管8个引脚上;,注意观测到,全亮或全灭(时间比较长)之后,开始记录亮笔划位置的次序;,本程序把上一种例题的数数据改动的一下,5.4 多种数码管显示,数组应用,#include,void delay_1s(unsigned int x);,code char led_code12=,0 x00,0 xff,0 xff,0 xff,0 xfe,0 xfd,0 xfb,0 xf7,0 xef,0 xdf,0 xbf,0 x7f,;,/test code,main(),while(1),P2=led_code0,delay_1s(4);,P2=led_code1,delay_1s(4);,使用数组的措施实现,重写一亮一灭程序,或0-9数码管显示,5.5 多种数码管串行显示图,多种数码管显示接线图,假定接到P3口上,多种数码管显示原理图,5.6 数码管显示0000-9999,自动测试数码管笔划次序,#include,void delay_1s(unsigned int x);,void shift(unsigned char);,sbit sda=P00;/must modifysbit,scl=P01;/must modify,code char led_code12=,0 xff,0 xff,0 xff,0 xff,0 xfe,0 xfd,0 xfb,0 xf7,0 xef,0 xdf,0 xbf,0 x7f,;/test code /*code char led_code19=,0 x11,0 xd7,0 x32,0 x92,0 xd4,/0,1,2,3,4,0 x98,0 x18,0 xd3,0 x10,0 x90,/5,6,7,8,9,0 x50,0 x1c,0 x39,0 x16,0 x38,/a,b,c,d,e,0 x78,0 xfe,0 xef,0 xff;/f-dot dark*/,5.6 数码管显示0000-9999,main(),unsigned char i;,while(1),for(i=0;i10;i+),shift(j);,shift(i);,shift(i);,shift(i);,delay_1s(4);,delay_1s(4);,5.6 数码管显示0000-9999,void shift(unsigned char n),unsigned char m,i;,m=led_coden;,scl=0;,for(i=0;i8;i+),if(m,else sda=0;,scl=1;,scl=0;,m=1;,数码管显示0000-9999,void delay_1s(unsigned int x),while(x-),5.7 数码管显示时间,#include,void delay_1s(unsigned int x);,void shift(unsigned char);,sbit sda=P00;/must modifysbit,scl=P01;/must modify,/*code char led_code19=,0 x7E,0 x06,0 x5B,0 x4F,0 x27,0 x6D,0 x7D,0 x46,0 x7F,0 x6F,0 x77,0 x3D,0 x78,0 x1F,0 x79,0 x71,0 x01,0 x80;/0,1,2,3,4,5,6,7,8,9 a,b,c,d,e,f -dot,5.7 数码管显示时间,main(),unsigned char j0,j1,j2,j3;,unsigned int time=10000;,while(1),for(j3=0;j36;j3+),for(j2=0;j210;j2+),for(j1=0;j16;j1+),for(j0=0;j010;j0+),shift(j0);,shift(j1);,shift(j2);,shift(j3);,delay_1s(40000);,;,5.7 数码管显示时间,void shift(unsigned char n),unsigned char m,i;,m=led_coden;,scl=0;,for(i=0;i8;i+),if(m&0 x80),sda=1;,else,sda=0;,scl=1;,scl=0;,m=1;,5.7 数码管显示时间,void delay_1s(unsigned int x),while(x-);,本章总结,关键灵活应用:,数组,注意下标从,0,开始,SHIFT,函数,延时函数,
展开阅读全文