-
Notifications
You must be signed in to change notification settings - Fork 0
/
nixie_tube.c
54 lines (46 loc) · 1.26 KB
/
nixie_tube.c
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
#include "nixie_tube.h"
#include "delay.h"
#include <math.h>
#include <REGX51.H>
unsigned int codes[10] = {~0xC0, ~0xF9, ~0xA4, ~0xB0, ~0x99, ~0x92, ~0x82, ~0xF8, ~0x80, ~0x90};
void NixieOn(unsigned char index, unsigned char n)
{
switch (index)
{
case 0: P2_4 = 0, P2_3 = 0, P2_2 = 0; break;
case 1: P2_4 = 0, P2_3 = 0, P2_2 = 1; break;
case 2: P2_4 = 0, P2_3 = 1, P2_2 = 0; break;
case 3: P2_4 = 0, P2_3 = 1, P2_2 = 1; break;
case 4: P2_4 = 1, P2_3 = 0, P2_2 = 0; break;
case 5: P2_4 = 1, P2_3 = 0, P2_2 = 1; break;
case 6: P2_4 = 1, P2_3 = 1, P2_2 = 0; break;
case 7: P2_4 = 1, P2_3 = 1, P2_2 = 1; break;
default: return;
}
P0 = codes[n]; // 位选
Delay(1); // 持续显示
P0 = 0x00; // 位选清空
}
void NixieOnNumber(unsigned int n)
{
unsigned char counts = ceil(log10(n));
unsigned char i = 0;
for (i = 0; i < counts; ++i)
{
NixieOn(i, n % 10);
n /= 10;
}
}
void NixieOnDemo2()
{
int i = 0;
for (i = 0; i < 1e8; ++i)
{
NixieOnNumber(i);
Delay(1);
}
}
void NixieOnDemo1()
{
NixieOn(4, 8);
}