LED P5全彩 3264 数码管字 By STC12C5A60S2单片机
边缘更饱满的数码管字体
效果图:
C51 代码1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201//STC12C5A60S2 @12M晶振
#include <STC12C5A60S2.H>
#include <intrins.h>
sbit R1 = P0 ^ 0;
sbit G1 = P0 ^ 1;
sbit B1 = P0 ^ 2;
sbit R2 = P0 ^ 3;
sbit G2 = P0 ^ 4;
sbit B2 = P0 ^ 5;
sbit IA = P2 ^ 7; //行控制线A
sbit IB = P2 ^ 6; //行控制线B
sbit IC = P2 ^ 5; //行控制线C
sbit ID = P2 ^ 4; //行控制线D
sbit CK = P2 ^ 2; //时钟
sbit LS = P2 ^ 1; //锁存
sbit OE = P2 ^ 0; //输出,低电平有效
#define SCAN(X) IA=(X)&1; IB=(X)&2; IC=(X)&4; ID=(X)&8;
unsigned short ms = 0;
unsigned short sec = 0;
unsigned char code Num16x32[][64]= //16x32点阵数字字符
{
//8字数码管字体
0x7F,0xF0,0xBF,0xE8,0xDF,0xD8,0xE0,0x38,0xE0,0x38,0xE0,0x38,0xE0,0x38,0xE0,0x38,
0xE0,0x38,0xE0,0x38,0xE0,0x38,0xE0,0x38,0xE0,0x38,0xE0,0x38,0xE0,0x38,0xC0,0x18,
0x80,0x08,0xC0,0x18,0xE0,0x38,0xE0,0x38,0xE0,0x38,0xE0,0x38,0xE0,0x38,0xE0,0x38,
0xE0,0x38,0xE0,0x38,0xE0,0x38,0xE0,0x38,0xE0,0x38,0xDF,0xD8,0xBF,0xE8,0x7F,0xF0, /*"E:\0.bmp",0*/
/* (16 X 32 )*/
0x00,0x00,0x00,0x08,0x00,0x18,0x00,0x38,0x00,0x38,0x00,0x38,0x00,0x38,0x00,0x38,
0x00,0x38,0x00,0x38,0x00,0x38,0x00,0x38,0x00,0x38,0x00,0x38,0x00,0x38,0x00,0x18,
0x00,0x08,0x00,0x18,0x00,0x38,0x00,0x38,0x00,0x38,0x00,0x38,0x00,0x38,0x00,0x38,
0x00,0x38,0x00,0x38,0x00,0x38,0x00,0x38,0x00,0x18,0x00,0x18,0x00,0x08,0x00,0x00, /*"E:\1.bmp",1*/
/* (16 X 32 )*/
0x7F,0xF0,0x3F,0xE8,0x1F,0xD8,0x00,0x38,0x00,0x38,0x00,0x38,0x00,0x38,0x00,0x38,
0x00,0x38,0x00,0x38,0x00,0x38,0x00,0x38,0x00,0x38,0x00,0x38,0x00,0x38,0x1F,0xD8,
0xBF,0xE8,0xDF,0xC0,0xE0,0x00,0xE0,0x00,0xE0,0x00,0xE0,0x00,0xE0,0x00,0xE0,0x00,
0xE0,0x00,0xE0,0x00,0xE0,0x00,0xE0,0x00,0xE0,0x00,0xDF,0xC0,0xBF,0xE0,0x7F,0xF0, /*"E:\2.bmp",2*/
/* (16 X 32 )*/
0x7F,0xF0,0x3F,0xE8,0x1F,0xD8,0x00,0x38,0x00,0x38,0x00,0x38,0x00,0x38,0x00,0x38,
0x00,0x38,0x00,0x38,0x00,0x38,0x00,0x38,0x00,0x38,0x00,0x38,0x00,0x38,0x1F,0xD8,
0x3F,0xE8,0x1F,0xD8,0x00,0x38,0x00,0x38,0x00,0x38,0x00,0x38,0x00,0x38,0x00,0x38,
0x00,0x38,0x00,0x38,0x00,0x38,0x00,0x38,0x00,0x38,0x1F,0xD8,0x3F,0xE8,0x7F,0xF0, /*"E:\3.bmp",3*/
/* (16 X 32 )*/
0x00,0x00,0x80,0x08,0xC0,0x18,0xE0,0x38,0xE0,0x38,0xE0,0x38,0xE0,0x38,0xE0,0x38,
0xE0,0x38,0xE0,0x38,0xE0,0x38,0xE0,0x38,0xE0,0x38,0xE0,0x38,0xE0,0x38,0xDF,0xD8,
0xBF,0xE8,0x1F,0xD8,0x00,0x38,0x00,0x38,0x00,0x38,0x00,0x38,0x00,0x38,0x00,0x38,
0x00,0x38,0x00,0x38,0x00,0x38,0x00,0x38,0x00,0x38,0x00,0x18,0x00,0x08,0x00,0x00, /*"E:\4.bmp",4*/
/* (16 X 32 )*/
0x7F,0xF0,0xBF,0xE0,0xDF,0xC0,0xE0,0x00,0xE0,0x00,0xE0,0x00,0xE0,0x00,0xE0,0x00,
0xE0,0x00,0xE0,0x00,0xE0,0x00,0xE0,0x00,0xE0,0x00,0xE0,0x00,0xE0,0x00,0xDF,0xC0,
0xBF,0xE8,0x1F,0xD8,0x00,0x38,0x00,0x38,0x00,0x38,0x00,0x38,0x00,0x38,0x00,0x38,
0x00,0x38,0x00,0x38,0x00,0x38,0x00,0x38,0x00,0x38,0x1F,0xD8,0x3F,0xE8,0x7F,0xF0, /*"E:\5.bmp",5*/
/* (16 X 32 )*/
0x7F,0xF0,0xBF,0xE0,0xDF,0xC0,0xE0,0x00,0xE0,0x00,0xE0,0x00,0xE0,0x00,0xE0,0x00,
0xE0,0x00,0xE0,0x00,0xE0,0x00,0xE0,0x00,0xE0,0x00,0xE0,0x00,0xE0,0x00,0xDF,0xC0,
0xBF,0xE8,0xDF,0xD8,0xE0,0x38,0xE0,0x38,0xE0,0x38,0xE0,0x38,0xE0,0x38,0xE0,0x38,
0xE0,0x38,0xE0,0x38,0xE0,0x38,0xE0,0x38,0xE0,0x38,0xDF,0xD8,0xBF,0xE8,0x7F,0xF0, /*"E:\6.bmp",6*/
/* (16 X 32 )*/
0x7F,0xF0,0x3F,0xE8,0x1F,0xD8,0x00,0x38,0x00,0x38,0x00,0x38,0x00,0x38,0x00,0x38,
0x00,0x38,0x00,0x38,0x00,0x38,0x00,0x38,0x00,0x38,0x00,0x38,0x00,0x38,0x00,0x18,
0x00,0x08,0x00,0x18,0x00,0x38,0x00,0x38,0x00,0x38,0x00,0x38,0x00,0x38,0x00,0x38,
0x00,0x38,0x00,0x38,0x00,0x38,0x00,0x38,0x00,0x38,0x00,0x18,0x00,0x08,0x00,0x00, /*"E:\7.bmp",7*/
/* (16 X 32 )*/
0x7F,0xF0,0xBF,0xE8,0xDF,0xD8,0xE0,0x38,0xE0,0x38,0xE0,0x38,0xE0,0x38,0xE0,0x38,
0xE0,0x38,0xE0,0x38,0xE0,0x38,0xE0,0x38,0xE0,0x38,0xE0,0x38,0xE0,0x38,0xDF,0xD8,
0xBF,0xE8,0xDF,0xD8,0xE0,0x38,0xE0,0x38,0xE0,0x38,0xE0,0x38,0xE0,0x38,0xE0,0x38,
0xE0,0x38,0xE0,0x38,0xE0,0x38,0xE0,0x38,0xE0,0x38,0xDF,0xD8,0xBF,0xE8,0x7F,0xF0, /*"E:\8.bmp",8*/
/* (16 X 32 )*/
0x7F,0xF0,0xBF,0xE8,0xDF,0xD8,0xE0,0x38,0xE0,0x38,0xE0,0x38,0xE0,0x38,0xE0,0x38,
0xE0,0x38,0xE0,0x38,0xE0,0x38,0xE0,0x38,0xE0,0x38,0xE0,0x38,0xE0,0x38,0xDF,0xD8,
0xBF,0xE8,0x1F,0xD8,0x00,0x38,0x00,0x38,0x00,0x38,0x00,0x38,0x00,0x38,0x00,0x38,
0x00,0x38,0x00,0x38,0x00,0x38,0x00,0x38,0x00,0x38,0x1F,0xD8,0x3F,0xE8,0x7F,0xF0, /*"E:\9.bmp",9*/
/* (16 X 32 )*/
};
void Delay10us() //@12.000MHz
{
unsigned char i;
i = 27;
while (--i);
}
void SendRGB(int s)
{
unsigned int i;
unsigned int j;
unsigned int k;
unsigned int num1 = (s / 1000) % 10;
unsigned int num2 = (s / 100) % 10;
unsigned int num3 = (s / 10) % 10;
unsigned int num4 = s % 10;
unsigned char *bitmap = Num16x32;
unsigned short buff_up[4];
unsigned short buff_down[4];
for(i = 0; i < 16; i++) //扫描行数
{
SCAN(i); //选择扫描行
//载入此行的 上半屏数据 8*8=64bit
buff_up[0] = *(unsigned short*)(bitmap + 64 * num1 + i * 2);
buff_up[1] = *(unsigned short*)(bitmap + 64 * num2 + i * 2);
buff_up[2] = *(unsigned short*)(bitmap + 64 * num3 + i * 2);
buff_up[3] = *(unsigned short*)(bitmap + 64 * num4 + i * 2);
//载入此行的 下半屏数据 8*8=64bit
buff_down[0] = *(unsigned short*)(bitmap + 64 * num1 + i * 2 + 32);
buff_down[1] = *(unsigned short*)(bitmap + 64 * num2 + i * 2 + 32);
buff_down[2] = *(unsigned short*)(bitmap + 64 * num3 + i * 2 + 32);
buff_down[3] = *(unsigned short*)(bitmap + 64 * num4 + i * 2 + 32);
for(j = 0; j < 4; j++)
{
for(k = 0; k < 16; k++)
{
buff_up[j] <<= 1;
R1 = CY;
G1 = CY;
B1 = CY;
buff_down[j] <<= 1;
R2 = CY;
G2 = CY;
B2 = CY;
//时钟
CK=1;
CK=0;
}
}
//锁存
LS=1;
LS=0;
//显示开
OE=0;
Delay10us();
Delay10us();
Delay10us();
OE=1;
}
}
void Timer0Init(void) //1毫秒@12.000MHz
{
AUXR |= 0x80; //定时器时钟1T模式
TMOD &= 0xF0; //设置定时器模式
TL0 = 0x20; //设置定时初始值
TH0 = 0xD1; //设置定时初始值
TF0 = 0; //清除TF0标志
TR0 = 1; //定时器0开始计时
ET0 = 1; //定时器0中断允许
}
void EnableEA()
{
EA = 1; //开启全局中断
}
int main()
{
P0M1 = 0x00;
P0M0 = 0xff;
P2M1 = 0x00;
P2M0 = 0xf0;
Timer0Init();
EnableEA();
while(1)
{
SendRGB(sec);
}
}
void timer0 (void) interrupt 1
{
ms++;
if(ms >=1000)
{
sec++;
ms = 0;
}
}