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
202
203
204
205
206
207
208
209//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 RD1[8]; //数据缓存
unsigned char GD1[8];
unsigned char BD1[8];
unsigned char RD2[8];
unsigned char GD2[8];
unsigned char BD2[8];
unsigned char code Num16x32[][64]= //16x32点阵数字字符
{
//8字数码管字体
0x00,0x00,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,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,0xDF,0xD8,0xBF,0xE8,0x7F,0xF0,0x00,0x00,/*"E:\0.bmp",0*/
/* (16 X 32 )*/
0x00,0x00,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,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,0x08,0x00,0x00,0x00,0x00,/*"E:\1.bmp",1*/
/* (16 X 32 )*/
0x00,0x00,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,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,0xDF,0xC0,0xBF,0xE0,0x7F,0xF0,0x00,0x00,/*"E:\2.bmp",2*/
/* (16 X 32 )*/
0x00,0x00,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,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,0x1F,0xD8,0x3F,0xE8,0x7F,0xF0,0x00,0x00,/*"E:\3.bmp",3*/
/* (16 X 32 )*/
0x00,0x00,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,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,0x18,0x00,0x08,0x00,0x00,0x00,0x00,/*"E:\4.bmp",4*/
/* (16 X 32 )*/
0x00,0x00,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,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,0x1F,0xD8,0x3F,0xE8,0x7F,0xF0,0x00,0x00,/*"E:\5.bmp",5*/
/* (16 X 32 )*/
0x00,0x00,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,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,0xDF,0xD8,0xBF,0xE8,0x7F,0xF0,0x00,0x00,/*"E:\6.bmp",6*/
/* (16 X 32 )*/
0x00,0x00,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,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,0x08,0x00,0x00,0x00,0x00,/*"E:\7.bmp",7*/
/* (16 X 32 )*/
0x00,0x00,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,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,0xDF,0xD8,0xBF,0xE8,0x7F,0xF0,0x00,0x00,/*"E:\8.bmp",8*/
/* (16 X 32 )*/
0x00,0x00,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,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,0x1F,0xD8,0x3F,0xE8,0x7F,0xF0,0x00,0x00,/*"E:\9.bmp",9*/
/* (16 X 32 )*/
};
void Delay100us() //@12.000MHz
{
unsigned char i, j;
_nop_();
_nop_();
i = 2;
j = 38;
do
{
while (--j);
} 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;
for(i = 0; i < 16; i++) //扫描行数
{
SCAN(i); //选择扫描行
//载入此行的 上半屏数据 8*8=64bit
RD1[0] = Num16x32[num1][i * 2];
RD1[1] = Num16x32[num1][i * 2 + 1];
RD1[2] = Num16x32[num2][i * 2];
RD1[3] = Num16x32[num2][i * 2 + 1];
RD1[4] = Num16x32[num3][i * 2];
RD1[5] = Num16x32[num3][i * 2 + 1];
RD1[6] = Num16x32[num4][i * 2];
RD1[7] = Num16x32[num4][i * 2 + 1];
//RD1[7] = Num16x32[num4][i * 2 + 1] >> 3 | (RD1[6] &7)<<5; RD1[6]>>=3; //为了右边缘对齐
//载入此行的 下半屏数据 8*8=64bit
RD2[0] = Num16x32[num1][32 + i * 2];
RD2[1] = Num16x32[num1][32 + i * 2 + 1];
RD2[2] = Num16x32[num2][32 + i * 2];
RD2[3] = Num16x32[num2][32 + i * 2 + 1];
RD2[4] = Num16x32[num3][32 + i * 2];
RD2[5] = Num16x32[num3][32 + i * 2 + 1];
RD2[6] = Num16x32[num4][32 + i * 2];
RD2[7] = Num16x32[num4][32 + i * 2 + 1];
//RD2[7] = Num16x32[num4][32 + i * 2 + 1] >>3 | (RD2[6] &7)<<5;RD2[6]>>=3;//为了右边缘对齐
for(j = 0; j < 8; j++)
{
for(k = 0; k < 8; k++)
{
RD1[j] <<= 1;
R1 = CY;
G1 = CY;
B1 = CY;
RD2[j] <<= 1;
R2 = CY;
G2 = CY;
B2 = CY;
//时钟
CK=1;
CK=0;
}
}
//锁存
LS=1;
LS=0;
//显示开
OE=0;
Delay100us();
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中断允许
EA = 1; //开启全局中断
}
int main()
{
Timer0Init();
while(1)
{
SendRGB(sec);
}
}
void timer0 (void) interrupt 1
{
ms++;
if(ms >=1000)
{
sec++;
ms = 0;
}
}