一、说明
大部分发光二极管工作电流15mA之间,其内阻为20100Ω。电流越大,亮度也越高。
单片机并行端口P1~P3驱动发光二极管,可以采用图6-1电路。其中,(a)图为输出高电平驱动,(b)图为输出低电平驱动。
当P0口引脚高电平时可提供约400µA的拉电流,为低电平时可提供约3.2mA的灌电流,P0口每位可驱动8个LSTTL输入,而P1~P3口每一位驱动能力,只有P0口一半。P1~P3口内有30kΩ左右上拉电阻。 由于P1、P2和P3口直接输出高电平的拉电流Id仅几百µA,驱动能力较弱,如果直接连接LED,致使LED亮度较差。
如一定要高电平驱动,可在单片机与发光二极管间加驱动电路,如74LS04、74LS373、74LS244等。见图(a)。引脚为低电平,具有较大的驱动能力,能使灌电流Id从单片机外部流入内部,则将大大增加流过LED的电流值,见图(b)。
LED数码管实际上就是8个按一定形状制作的LED,排列成 “8”字型和一个小数点,如图(a)。数码管按其公共端连接的方式分为共阳极和共阴极两种,共阴极数码管阴极连在一起接地,如图(b);共阳极数码管的阳极连接在一起,接+5V,如图(c)。
对于共阴极数码管,当某发光二极管阳极为高电平时,LED点亮,相应段被显示。同样,共阳极数码管,当某个LED阴极接低电平时,该LED被点亮,相应段被显示。
为使LED数码管显示不同字符,要把某些段点亮,就要为数码管各段提供一字节的二进制码,即字型码(也称段码)。以“a”段对应字型码字节的最低位。各字符段码见表。
要控制数码管显示不同的字符,只要把对应字符的字形编码送到数码管的段输入端。
利用Proteus仿真功能,编程实现以下功能:
- 点阵汉字显示电路图的设计及动态显示“产教融合创新创业” 控制程序的设计
- 掌握16×16点阵的汉字点阵设计方法,能进行仿真运行
二、重点
- 单片机各种开发工具的使用
- 单片机人机交互的常用方法及相关电路控制技术
三、实现
#include<reg51.h> #define uchar unsigned char #define uint unsigned int void delay(uint j) //延时函数 { uchar i=250; for(;j>0;j--) { while(--i); i=100; } } //16×16汉字点阵码 uchar code string[]= { 0x02,0x00,0x01,0x00,0x01,0x08,0x7F,0xFC, 0x08,0x10,0x04,0x20,0x04,0x48,0x1F,0xFC, 0x10,0x00,0x10,0x00,0x10,0x00,0x10,0x00, 0x20,0x00,0x20,0x00,0x40,0x00,0x80,0x00, 0x08,0x40,0x08,0x40,0x7F,0x40,0x09,0x44, 0x0A,0x7E,0xFF,0x88,0x08,0x08,0x1F,0x48, 0x22,0x50,0xCC,0x50,0x08,0x20,0x0E,0x50, 0x78,0x50,0x08,0x88,0x29,0x0E,0x12,0x04, 0x02,0x10,0x7F,0x10,0x00,0x10,0x3E,0x14, 0x22,0x7E,0x22,0x54,0x3E,0x54,0x00,0x54, 0x7F,0x54,0x63,0x7C,0x55,0x54,0x7F,0x10, 0x49,0x10,0x49,0x14,0x49,0xFE,0x43,0x02, 0x01,0x00,0x01,0x00,0x02,0x80,0x04,0x40, 0x08,0x20,0x10,0x10,0x2F,0xEE,0xC0,0x04, 0x00,0x10,0x1F,0xF8,0x10,0x10,0x10,0x10, 0x10,0x10,0x10,0x10,0x1F,0xF0,0x10,0x10, 0x08,0x04,0x08,0x04,0x14,0x04,0x12,0x24, 0x21,0xA4,0x20,0xA4,0x7E,0x24,0xA2,0x24, 0x22,0x24,0x2A,0x24,0x24,0x24,0x20,0x04, 0x21,0x04,0x21,0x04,0x1F,0x14,0x00,0x08, 0x10,0x08,0x0A,0x1C,0x7F,0x60,0x00,0x40, 0x22,0x40,0x14,0x44,0xFF,0xFE,0x0A,0x48, 0x7F,0x48,0x08,0x48,0x0A,0x48,0x29,0x88, 0x48,0x88,0x89,0x08,0x28,0x08,0x10,0x08, 0x08,0x04,0x08,0x04,0x14,0x04,0x12,0x24, 0x21,0xA4,0x20,0xA4,0x7E,0x24,0xA2,0x24, 0x22,0x24,0x2A,0x24,0x24,0x24,0x20,0x04, 0x21,0x04,0x21,0x04,0x1F,0x14,0x00,0x08, 0x04,0x40,0x04,0x40,0x04,0x40,0x04,0x40, 0x44,0x44,0x24,0x44,0x24,0x48,0x14,0x48, 0x14,0x50,0x14,0x50,0x14,0x60,0x04,0x40, 0x04,0x40,0x04,0x44,0xFF,0xFE,0x00,0x00 }; void main() { uchar i,j,n; while(1) { for(j=0;j<8;j++) //共显示5个汉字 { for(n=0;n<40;n++) //每个汉字整屏扫描40次 { for(i=0;i<16;i++) //逐行扫描16行 { P1=i%16; //输出行码, P0=string[i*2+j*32]; //输出列码到C0~C7 P2=string[i*2+1+j*32]; //输出列码到C8~C15 delay(4); P0=0xff; //列线C ~C7为高电平,熄灭LED P2=0xff; //列线C8~C15为高电平,熄灭LED } } } } }
四、下载