51单片机直接驱动共阴极数码管
数码管种类:
数码管类型 | 上拉电阻 | 限流电阻 | 对单片机电流的影响 | 三极管驱动 | 工业IC |
共阳极 | 不需 | 200~470Ω (非排阻) | 位码高电平, 段码低电平时点亮 | PNP | |
共阴极 | 需要 (可排阻1KΩ) (因而浪费电 而且而且全部 熄灭时比全部 点亮时更费电) | 不需 | 位码低电平, 段码高电平时点亮 | NPN | 常用 |
现在手里只有共阴的数码管(LG5011AH),按照网上搜索到的下图实现:
实际用的单片机是AT89S51,参考上面的的图做了适当的修改,用P2控制段,P3控制位。
所有与单片机的连接均用排针。
LED驱动的段显控制:
首先确定显示的段,将段按顺序转换成二进制数字,进而转换成十进制数字。
假设P2.0~P2.6按顺序接到a-h段
单片机 | Pn.7 | Pn.6 | Pn.5 | Pn.4 | Pn.3 | Pn.2 | Pn.1 | Pn.0 |
数码管 | h | g | f | e | d | c | b | a |
如显示“H” | 0 | 1 | 1 | 1 | 0 | 1 | 1 | 0 |
B01110110= 0x76 | ||||||||
如显示“O” | 0 | 0 | 1 | 1 | 1 | 1 | 1 | 1 |
B00111111= 0x3f |
程序(C语言)
//这是采用查询方式的,比较占CUP资源,
# include
typedef unsigned char uchar;
//这里定义了所有二进制--十六进制转换
#define B00000000 0x0
#define B00000001 0x1
#define B00000010 0x2
#define B00000011 0x3
#define B00000100 0x4
#define B00000101 0x5
#define B00000110 0x6
#define B00000111 0x7
#define B00001000 0x8
#define B00001001 0x9
#define B00001010 0xa
#define B00001011 0xB
#define B00001100 0xc
#define B00001101 0xd
#define B00001110 0xe
#define B00001111 0xf
#define B00010000 0x10
#define B00010001 0x11
#define B00010010 0x12
#define B00010011 0x13
#define B00010100 0x14
#define B00010101 0x15
#define B00010110 0x16
#define B00010111 0x17
#define B00011000 0x18
#define B00011001 0x19
#define B00011010 0x1a
#define B00011011 0x1B
#define B00011100 0x1c
#define B00011101 0x1d
#define B00011110 0x1e
#define B00011111 0x1f
#define B00100000 0x20
#define B00100001 0x21
#define B00100010 0x22
#define B00100011 0x23
#define B00100100 0x24
#define B00100101 0x25
#define B00100110 0x26
#define B00100111 0x27
#define B00101000 0x28
#define B00101001 0x29
#define B00101010 0x2a
#define B00101011 0x2B
#define B00101100 0x2c
#define B00101101 0x2d
#define B00101110 0x2e
#define B00101111 0x2f
#define B00110000 0x30
#define B00110001 0x31
#define B00110010 0x32
#define B00110011 0x33
#define B00110100 0x34
#define B00110101 0x35
#define B00110110 0x36
#define B00110111 0x37
#define B00111000 0x38
#define B00111001 0x39
#define B00111010 0x3a
#define B00111011 0x3B
#define B00111100 0x3c
#define B00111101 0x3d
#define B00111110 0x3e
#define B00111111 0x3f
#define B01000000 0x40
#define B01000001 0x41
#define B01000010 0x42
#define B01000011 0x43
#define B01000100 0x44
#define B01000101 0x45
#define B01000110 0x46
#define B01000111 0x47
#define B01001000 0x48
#define B01001001 0x49
#define B01001010 0x4a
#define B01001011 0x4B
#define B01001100 0x4c
#define B01001101 0x4d
#define B01001110 0x4e
#define B01001111 0x4f
#define B01010000 0x50
#define B01010001 0x51
#define B01010010 0x52
#define B01010011 0x53
#define B01010100 0x54
#define B01010101 0x55
#define B01010110 0x56
#define B01010111 0x57
#define B01011000 0x58
#define B01011001 0x59
#define B01011010 0x5a
#define B01011011 0x5B
#define B01011100 0x5c
#define B01011101 0x5d
#define B01011110 0x5e
#define B01011111 0x5f
#define B01100000 0x60
#define B01100001 0x61
#define B01100010 0x62
#define B01100011 0x63
#define B01100100 0x64
#define B01100101 0x65
#define B01100110 0x66
#define B01100111 0x67
#define B01101000 0x68
#define B01101001 0x69
#define B01101010 0x6a
#define B01101011 0x6B
#define B01101100 0x6c
#define B01101101 0x6d
#define B01101110 0x6e
#define B01101111 0x6f
51单片机直接驱动共阴极数码 相关文章:
- Windows CE 进程、线程和内存管理(11-09)
- RedHatLinux新手入门教程(5)(11-12)
- uClinux介绍(11-09)
- openwebmailV1.60安装教学(11-12)
- Linux嵌入式系统开发平台选型探讨(11-09)
- Windows CE 进程、线程和内存管理(二)(11-09)