版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、第八章:第八章:5151系列单片机键盘系列单片机键盘/ /显示器接口技显示器接口技术术 常用的显示设备:常用的显示设备: 发光二极管、八段发光二极管、八段LEDLED显示器、点阵显示器、点阵LEDLED,液晶显示器(液晶显示器(LCDLCD)、屏幕显示器()、屏幕显示器(CRTCRT)等。)等。 8.1 LED8.1 LED显示器接口技术显示器接口技术 8.2 8.2 键盘接口技术键盘接口技术 8.3 8.3 点阵接口技术点阵接口技术 8.4 8.4 液晶显示器接口技术液晶显示器接口技术8.1 518.1 51单片机显示器接口技术单片机显示器接口技术1 1、LEDLED显示器结构与原理显示器结
2、构与原理: (1 1)结构:)结构:LEDLED封装图封装图共阴极共阴极LEDLED共阳极共阳极LEDLED(2 2)LEDLED显示器的基本问题显示器的基本问题 a.a.七段码问题七段码问题 共阳极、共阴极七段码共阳极、共阴极七段码 如显示如显示“0”,0”,共阴极七段码:共阴极七段码: dp g f e d c b a dp g f e d c b a 0 0 1 1 1 1 1 1 0 0 1 1 1 1 1 1 3FH3FH 共阳极七段码:共阳极七段码: dp g f e d c b a dp g f e d c b a 1 1 0 0 0 0 0 0 1 1 0 0 0 0 0 0
3、0C0H0C0H 共阴极七段码表共阴极七段码表:unsigned char code daima16=unsigned char code daima16= 0 x3F,0 x06,0 x5B,0 x4F,0 x66,0 x6D,0 x7D,0 x27,0 x7F,0 x3F,0 x06,0 x5B,0 x4F,0 x66,0 x6D,0 x7D,0 x27,0 x7F,0 x6F,0 x77,0 x7C,0 x39,0 x5E,0 x79,0 x71;0 x6F,0 x77,0 x7C,0 x39,0 x5E,0 x79,0 x71; b.b.驱动问题驱动问题 LEDLED显示器的每一个段显
4、示器的每一个段通常需要通常需要1 15mA电流。电流。 段驱动、位驱动;段驱动、位驱动; 段口、位口段口、位口 c.c.显示方式问题显示方式问题 静态显示、动态显示静态显示、动态显示 d.d.译码方式问题译码方式问题 硬件译码:硬件译码:采用专用译码器芯片实现,如采用专用译码器芯片实现,如CD4511CD4511、74477447等芯片等芯片 软件译码:软件译码:采用软件查表的方法,如显示采用软件查表的方法,如显示“3”3”: unsigned char code table16=unsigned char code table16= 0 x3F,0 x06,0 x5B,0 x4F,0 x66
5、,0 x6D,0 x7D,0 x27,0 x3F,0 x06,0 x5B,0 x4F,0 x66,0 x6D,0 x7D,0 x27,0 x7F,0 x6F,0 x77,0 x7C,0 x39,0 x5E,0 x79,0 x71;0 x7F,0 x6F,0 x77,0 x7C,0 x39,0 x5E,0 x79,0 x71; unsigned char i,j;unsigned char i,j; i=0 x03; /i=0 x03; / j=tablei; /j=tablei; /查表,转换成查表,转换成7 7段码段码 (3) (3) 显示函数的编写问题显示函数的编写问题 a.a.建立建立7
6、 7段码表段码表 b.b.建立显示缓冲区建立显示缓冲区 通常,显示缓冲区中存放要显示的内容,对应通常,显示缓冲区中存放要显示的内容,对应于每个显示器,显示缓冲区的数据由其他函数于每个显示器,显示缓冲区的数据由其他函数或主函数来修改。或主函数来修改。 c.c.编制显示函数编制显示函数 显示函数只完成将显示缓冲区中的数据通过查显示函数只完成将显示缓冲区中的数据通过查表转换成表转换成7 7段码送显示器显示。段码送显示器显示。 d.d.显示函数的调用显示函数的调用 在主函数或其他函数中调用显示函数。在主函数或其他函数中调用显示函数。 例如:例如:2 2位显示器显示函数的编写位显示器显示函数的编写 un
7、signed char dis_buf2;unsigned char dis_buf2;/显示缓冲区显示缓冲区 unsigned char code table16=unsigned char code table16=0 x3F,0 x06,0 x5B,0 x4F,0 x66,0 x6D,0 x7D,0 x27,0 x7F,0 x6F,0 x77,0 x3F,0 x06,0 x5B,0 x4F,0 x66,0 x6D,0 x7D,0 x27,0 x7F,0 x6F,0 x77,0 x7C,0 x39,0 x5E,0 x79,0 x71;0 x7C,0 x39,0 x5E,0 x79,0 x7
8、1; void Disp(void)void Disp(void) /2 /2位数码管显示函数位数码管显示函数 unsigned char unsigned char i i; ; i=dis_buf0; / i=dis_buf0; /取显示内容取显示内容 P1=tablei; /7 P1=tablei; /7段码送显示器段码送显示器 i=dis_buf1; i=dis_buf1; P3=tablei; P3=tablei; (4 4)LEDLED显示器静态显示显示器静态显示 1 1、一个、一个8 8位端口位端口控制控制1 1位位LEDLED显示显示器;器; 2 2、不改变显示内、不改变显示内
9、容,显示器一直容,显示器一直显示不变;显示不变; 3 3、硬件复杂,软、硬件复杂,软件控制简单。件控制简单。例例1 1:利用:利用P2P2、P3P3口进行静态显示:轮流显口进行静态显示:轮流显示示“12”12”、“-”-”、“AB”AB”ahabcdefgbcdefghR1A02B018A13B117A24B216A35B315A46B414A57B513A68B612A79B711CE19AB/BA1U274LS245A02B018A13B117A24B216A35B315A46B414A57B513A68B612A79B711CE19AB/BA1U374LS245XTAL218XTAL11
10、9ALE30EA31PSEN29RST9P0.0/AD039P0.1/AD138P0.2/AD237P0.3/AD336P0.4/AD435P0.5/AD534P0.6/AD633P0.7/AD732P1.0/T21P1.1/T2EX2P1.23P1.34P1.45P1.56P1.67P1.78P3.0/RXD10P3.1/TXD11P3.2/INT012P3.3/INT113P3.4/T014P3.7/RD17P3.6/WR16P3.5/T115P2.7/A1528P2.0/A821P2.1/A922P2.2/A1023P2.3/A1124P2.4/A1225P2.5/A1326P2.6/A
11、1427U1AT89C52 #include #include unsigned char dis_buf2;unsigned char dis_buf2; / /显示缓冲区显示缓冲区 unsigned char code table18=unsigned char code table18= 0 x3F,0 x06,0 x5B,0 x4F,0 x66,0 x6D,0 x7D,0 x27,0 x7F,0 x6F,0 x0 x3F,0 x06,0 x5B,0 x4F,0 x66,0 x6D,0 x7D,0 x27,0 x7F,0 x6F,0 x77,0 x7C,0 x39,0 x5E,0 x79
12、,0 x71,0 x40,0 x00;77,0 x7C,0 x39,0 x5E,0 x79,0 x71,0 x40,0 x00; void dl(unsigned int x)void dl(unsigned int x) / /延时延时xmsxms unsigned int t1,t2;unsigned int t1,t2;for (t1=0;t1x;t1+)for (t1=0;t1x;t1+)for (t2=0;t2120;t2+) ;for (t2=0;t2120;t2+) ; void display(void) /void display(void) /显示函数显示函数 P2=tab
13、ledis_buf0; /P2=tabledis_buf0; /静态显示静态显示1 1P3=tabledis_buf1; /P3=tabledis_buf1; /静态显示静态显示2 2 void main(void)void main(void) while(1)while(1) dis_buf0=1; dis_buf1=2;/dis_buf0=1; dis_buf1=2;/送显示数据送显示数据1212display();display(); /调显示函数调显示函数dl(500); dl(500); /延时延时500ms 500ms dis_buf0=16; dis_buf1=16;dis_b
14、uf0=16; dis_buf1=16; /显示显示-display();display(); dl(500);dl(500);dis_buf0=0 x0a; dis_buf1=0 x0b; /dis_buf0=0 x0a; dis_buf1=0 x0b; /显示显示ababdisplay();display(); dl(500);dl(500); 例例2 2:利用:利用8255PA8255PA、PBPB、PCPC口进行静态显口进行静态显示:轮流显示示:轮流显示“123”123”、“abc”abc”PA7PC7PC0PC1PC2PC3PC4PC5PC0PC6PC1PC7PC2PC3PC4PC5
15、PC6PA0PA5PA1PA6PA2PA7PA3PA4PA5PA6PA0PA1PA2PA3PA4XTAL218XTAL119ALE30EA31PSEN29RST9P0.0/AD039P0.1/AD138P0.2/AD237P0.3/AD336P0.4/AD435P0.5/AD534P0.6/AD633P0.7/AD732P1.0/T21P1.1/T2EX2P1.23P1.34P1.45P1.56P1.67P1.78P3.0/RXD10P3.1/TXD11P3.2/INT012P3.3/INT113P3.4/T014P3.7/RD17P3.6/WR16P3.5/T115P2.7/A1528P2.
16、0/A821P2.1/A922P2.2/A1023P2.3/A1124P2.4/A1225P2.5/A1326P2.6/A1427U1AT89C52PROGRAM=.例2程序例2.hexD034D133D232D331D430D529D628D727RD5WR36A09A18RESET35CS6PA04PA13PA22PA31PA440PA539PA638PA737PB018PB119PB220PB321PB422PB523PB624PB725PC014PC115PC216PC317PC413PC512PC611PC710U58255AA02B018A13B117A24B216A35B315A
17、46B414A57B513A68B612A79B711CE19AB/BA1U274LS245A02B018A13B117A24B216A35B315A46B414A57B513A68B612A79B711CE19AB/BA1U374LS245A02B018A13B117A24B216A35B315A46B414A57B513A68B612A79B711CE19AB/BA1U474LS245 #include #include #include #include #define COM8255 XBYTE0 xbfff#define COM8255 XBYTE0 xbfff #define PA
18、8255 XBYTE0 xbcff#define PA8255 XBYTE0 xbcff #define PB8255 XBYTE0 xbdff#define PB8255 XBYTE0 xbdff #define PC8255 XBYTE0 xbeff#define PC8255 XBYTE0 xbeff unsigned char dis_buf3;unsigned char dis_buf3; / /显示缓冲区显示缓冲区 unsigned char code table18=unsigned char code table18= 0 x3F,0 x06,0 x5B,0 x4F,0 x66
19、,0 x6D,0 x7D,0 x27,0 x7F,0 x6F,0 x0 x3F,0 x06,0 x5B,0 x4F,0 x66,0 x6D,0 x7D,0 x27,0 x7F,0 x6F,0 x77,0 x7C,0 x39,0 x5E,0 x79,0 x71,0 x40,0 x00;77,0 x7C,0 x39,0 x5E,0 x79,0 x71,0 x40,0 x00; void dl(unsigned int x)void dl(unsigned int x) / /延时延时xmsxms unsigned int t1,t2;unsigned int t1,t2;for (t1=0;t1x
20、;t1+)for (t1=0;t1x;t1+)for (t2=0;t2120;t2+) ;for (t2=0;t2120;t2+) ; void display(void)void display(void) PA8255=tabledis_buf0;PA8255=tabledis_buf0;PB8255=tabledis_buf1;PB8255=tabledis_buf1;PC8255=tabledis_buf2; PC8255=tabledis_buf2; void main(void)void main(void) COM8255=0 x80;COM8255=0 x80;/8255/82
21、55初始化初始化while(1)while(1) dis_buf0=1; dis_buf0=1; dis_buf1=2; dis_buf1=2; dis_buf2=3; / dis_buf2=3; /显示显示123123 display(); display(); /调显示函数调显示函数 dl(500); /dl(500); /延时延时500ms 500ms dis_buf0=0 x0a; dis_buf0=0 x0a; dis_buf1=0 x0b; dis_buf1=0 x0b; dis_buf2=0 x0c; dis_buf2=0 x0c; / /显示显示abc abc display(
22、); display(); dl(500); dl(500); (5 5)LEDLED动态显示动态显示 动态显示即一位一位轮流点亮各位显示器,动态显示即一位一位轮流点亮各位显示器,采用动画模式。采用动画模式。理解:段口和位口的含义理解:段口和位口的含义 unsigned char dis_buf8 ;unsigned char dis_buf8 ; / /显示缓冲区显示缓冲区 unsigned char code table16=unsigned char code table16=0 x3F,0 x06,0 x5B,0 x4F,0 x66,0 x6D,0 x7D,0 x27,0 x7F,0
23、x6F,0 x77,0 x3F,0 x06,0 x5B,0 x4F,0 x66,0 x6D,0 x7D,0 x27,0 x7F,0 x6F,0 x77,0 x7C,0 x39,0 x5E,0 x79,0 x71;0 x7C,0 x39,0 x5E,0 x79,0 x71; void void d dispisplaylay(void)(void) unsigned char unsigned char i i; ;unsigned char unsigned char bitcodebitcode=0 xfe;=0 xfe;/位码位码for(for(i i=0;=0;i i8;8;i i+)+
24、) DUANKOUDUANKOU= =tabletable dis_bufdis_buf i i; / /送段码送段码WEIKOUWEIKOU= =bitcodebitcode; ; /位码位码dldl_ _ms();ms(); /延时延时1ms1ms WEIKOU=0 xff; /WEIKOU=0 xff; /关闭显示关闭显示bitcodebitcode=_crol_(=_crol_(bitcodebitcode,1);/,1);/位码左循环移位位码左循环移位 例例3 3:利用:利用P0P0、P3P3口进行动态显示:显示口进行动态显示:显示“123456”123456”XTAL218XTAL
25、119ALE30EA31PSEN29RST9P0.0/AD039P0.1/AD138P0.2/AD237P0.3/AD336P0.4/AD435P0.5/AD534P0.6/AD633P0.7/AD732P1.0/T21P1.1/T2EX2P1.23P1.34P1.45P1.56P1.67P1.78P3.0/RXD10P3.1/TXD11P3.2/INT012P3.3/INT113P3.4/T014P3.7/RD17P3.6/WR16P3.5/T115P2.7/A1528P2.0/A821P2.1/A922P2.2/A1023P2.3/A1124P2.4/A1225P2.5/A1326P2.6
26、/A1427U1AT89C52A02B018A13B117A24B216A35B315A46B414A57B513A68B612A79B711CE19AB/BA1U274LS24512U1:A740734U1:B740756U1:C740798U1:D74071110U1:E74071312U1:F7407 #include #include #include #include unsigned char dis_buf6=0; /unsigned char dis_buf6=0; /显示缓冲区显示缓冲区 unsigned char code unsigned char code table1
27、6=0 x3F,0 x06,0 x5B,0 x4F,0 x66,0 x6D,0 x7table16=0 x3F,0 x06,0 x5B,0 x4F,0 x66,0 x6D,0 x7D,0 x27,0 x7F,0 x6F,0 x77,0 x7C,0 x39,0 x5E,0 x79,0 xD,0 x27,0 x7F,0 x6F,0 x77,0 x7C,0 x39,0 x5E,0 x79,0 x71;71; void dl_ms()void dl_ms() / /延时延时1ms1ms unsigned int j;unsigned int j;for (j=0;j150;j+) ;for (j=0;
28、j150;j+) ; void display(void)void display(void) unsigned char i;unsigned char i;unsigned char bitcode=0 xfe;unsigned char bitcode=0 xfe;/位码位码for(i=0;i6;i+)for(i=0;i6;i+) P0=tabledis_bufi; P0=tabledis_bufi; / /送段码送段码 P3=bitcode;P3=bitcode; / /位码位码 dl_ms();dl_ms(); / /延时延时1ms1ms P3=0 xff; P3=0 xff; /
29、/关闭显示关闭显示 bitcode=_crol_(bitcode,1); /bitcode=_crol_(bitcode,1); /位码左循环移位位码左循环移位 void main(void)void main(void) dis_buf0=1; dis_buf1=2;dis_buf0=1; dis_buf1=2;dis_buf2=3; dis_buf3=4;dis_buf2=3; dis_buf3=4; dis_buf4=5; dis_buf5=6; dis_buf4=5; dis_buf5=6; while(1)while(1) display();display(); A15 A14 A
30、13 A12 A11 A10 A9 A8 A7-A0A15 A14 A13 A12 A11 A10 A9 A8 A7-A0 1 1 0 0 1 1 1 1 1 1 1 1 0 00 0 1 - 1 1 - 1 0 10 1 1 01 0 1 11 1 82558255端口地址:端口地址:BCFFHBFFFHBCFFHBFFFH例例4 4:利用:利用8255A8255A控制动态显示控制动态显示PAPA口为段口,口为段口,PBPB口为位口口为位口74LS24574LS245、74077407均为同向驱动器。均为同向驱动器。例例4 4:利用:利用82558255进行动态显示:显示进行动态显示:显示“
31、12345678”12345678”XTAL218XTAL119ALE30EA31PSEN29RST9P0.0/AD039P0.1/AD138P0.2/AD237P0.3/AD336P0.4/AD435P0.5/AD534P0.6/AD633P0.7/AD732P1.0/T21P1.1/T2EX2P1.23P1.34P1.45P1.56P1.67P1.78P3.0/RXD10P3.1/TXD11P3.2/INT012P3.3/INT113P3.4/T014P3.7/RD17P3.6/WR16P3.5/T115P2.7/A1528P2.0/A821P2.1/A922P2.2/A1023P2.3/
32、A1124P2.4/A1225P2.5/A1326P2.6/A1427U0AT89C52D034D133D232D331D430D529D628D727RD5WR36A09A18RESET35CS6PA04PA13PA22PA31PA440PA539PA638PA737PB018PB119PB220PB321PB422PB523PB624PB725PC014PC115PC216PC317PC413PC512PC611PC710U38255AA02B018A13B117A24B216A35B315A46B414A57B513A68B612A79B711CE19AB/BA1U474LS24512U
33、1:A740734U1:B740756U1:C740798U1:D74071110U1:E74071312U1:F740712U2:A740734U2:B7407 #include #include #include #include #include #include #define COM8255 XBYTE0 xbfff#define COM8255 XBYTE0 xbfff #define PA8255 XBYTE0 xbcff#define PA8255 XBYTE0 xbcff #define PB8255 XBYTE0 xbdff#define PB8255 XBYTE0 xbd
34、ff #define PC8255 XBYTE0 xbeff#define PC8255 XBYTE0 xbeff unsigned char dis_buf8=1,2,3,4,5,6,7,8;unsigned char dis_buf8=1,2,3,4,5,6,7,8; / /显显示缓冲区示缓冲区 unsigned char code unsigned char code table16=0 x3F,0 x06,0 x5B,0 x4F,0 x66,0 x6D,0 x7D,0 x27,table16=0 x3F,0 x06,0 x5B,0 x4F,0 x66,0 x6D,0 x7D,0 x27
35、,0 x7F,0 x6F,0 x77,0 x7C,0 x39,0 x5E,0 x79,0 x71;0 x7F,0 x6F,0 x77,0 x7C,0 x39,0 x5E,0 x79,0 x71; void dl_ms()void dl_ms() / /延时延时1ms1ms unsigned int j;unsigned int j;for (j=0;j150;j+) ;for (j=0;j150;j+) ; void display(void)void display(void) unsigned char i;unsigned char i;unsigned char bitcode=0 x
36、fe;unsigned char bitcode=0 xfe;/位码位码for(i=0;i8;i+)for(i=0;i8;i+) PA8255=tabledis_bufi; PA8255=tabledis_bufi; /送段码送段码PC8255=bitcode;PC8255=bitcode;/位码位码dl_ms();dl_ms(); /延时延时1ms1ms PC8255=0 xff; PC8255=0 xff; /关闭显示关闭显示bitcode=_crol_(bitcode,1);/bitcode=_crol_(bitcode,1);/位码左循环移位位码左循环移位 void main()voi
37、d main() COM8255=0 x80;COM8255=0 x80;/8255/8255初始化初始化while(1)while(1) display();display(); 提高:显示程序的实际问题提高:显示程序的实际问题 前述显示程序是理想仿真下的情况。前述显示程序是理想仿真下的情况。 实际电路板中的显示程序如何呢?实际电路板中的显示程序如何呢? 与仿真程序相比较,有何区别?与仿真程序相比较,有何区别?PAPA口为段口,口为段口,PBPB口为位口口为位口74LS24574LS245、74077407均为同向驱动器。均为同向驱动器。82558255端口地址:端口地址:BCFFHBFFF
38、HBCFFHBFFFHD140073A53Y65A116Y12VCC144Y84A95Y106A13U474073A53Y65A116Y12VCC144Y84A95Y106A13U37407+5+5C6220UF/25VC5104C4104C3104C21041VS1VC+5C110UFR110K+5AN1AN0AN4AN8AN15AN11AN7AN3AN14AN10AN6AN2AN13AN9AN5AN121CS1A01A11WR1RDCOM3DP5B6A7C4D2E1COM8F9G10LED3COM3DP5B6A7C4D2E1COM8F9G10LED2COM3DP5B6A7C4D2E1COM
39、8F9G10LED1COM3DP5B6A7C4D2E1COM8F9G10LED4COM3DP5B6A7C4D2E1COM8F9G10LED8COM3DP5B6A7C4D2E1COM8F9G10LED5COM3DP5B6A7C4D2E1COM8F9G10LED6COM3DP5B6A7C4D2E1COM8F9G10LED7D034D133D232D331D430D529D628D727PA04PA13PA22PA31PA440PA539PA638PA737PB018PB119PB220PB321PB422PB523PB624PB725PC014PC115PC216PC317PC413PC512PC611PC710RD5WR36A09A18RESET35CS6GND7VCC26U18255+5A02A13A24A35A46A57A68A79B018B117B216B315B414B513B612B711E19DIR1VCC20U274LS24512345678PIN1+5R32KR42KR52KR62KR72KR82KR92KR102KR25.1KR115.1KR125.1KR135.1KR145.1KR155.1KR165.1KR175.1KR182KL1C101UC111U1234USBC2+4T1I11R
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
评论
0/150
提交评论