LED P5全彩 3264 模块测试 By STC12C5A60S2单片机
7种颜色, 满屏循环显示
效果图:
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//STC12C5A60S2 @12M晶振
#include <STC12C5A60S2.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;
void Delay10us() //@12.000MHz
{
unsigned char i;
i = 27;
while (--i);
}
void SendRGB()
{
unsigned int i, j;
for(i = 0; i < 16; i++) //扫描行
{
SCAN(i);
for(j = 0; j < 64; j++) //发送点的数据
{
if(sec%8)
{
R2 = R1 = sec&1;
G2 = G1 = sec&2;
B2 = B1 = sec&4;
CK = 1;
CK = 0;
}
}
LS = 1;
LS = 0;
OE = 0; //显示开
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中断允许
EA = 1; //开启全局中断
}
int main()
{
Timer0Init();
while(1)
{
SendRGB();
}
}
void timer0 (void) interrupt 1
{
ms++;
if(ms >=1000)
{
sec++;
ms = 0;
}
}