-
Notifications
You must be signed in to change notification settings - Fork 2
/
POV_Test.c
178 lines (143 loc) · 3.58 KB
/
POV_Test.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
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
////////////////////////////////////////////////////////////////////////////////////////
// The 303 Defcon Badge Project for 2012
//
// This is a hardware and software platform that can be used to make a cool badge
// It includes lightshow, sound DAC, and chiptunes subsystem
// Alcohol sensor, and an RF communciation system.
// The software includes the ability to access functions locally, and remotely given
// sufficient badge privilege, it also has an STD simulator that probabalistically
// causes badges to infect other badges through the beacon subsystem.
////////////////////////////////////////////////////////////////////////////////////////
//
// Please see general credits and information in the main.c file
//
// (c) 2012, Don Kark (Th3D0n)
//
////////////////////////////////////////////////////////////////////////////////////////
#include <system.h>
#include "Badge.h"
#include "CharData/Char5x7Data.h"
#define NUMROW 7
#define NUMCOL 5
rom char *povstring = "Thank You DT and Kryus !!! 303 & DENHAC ";
#define NUMCHARS 43
unsigned char readcharmap(unsigned char chr, unsigned char column)
{
unsigned long caddress;
unsigned short offset;
unsigned char cresult;
offset = (unsigned short) chr * NUMCOL;
offset += column;
caddress = CHARDATA + offset;
asm
{
MOVF _caddress + 2, W
MOVWF _tblptru
MOVF _caddress + 1, W
MOVWF _tblptrh
MOVF _caddress, W
MOVWF _tblptrl
TBLRD*
MOVF _tablat, W
MOVWF _cresult
// RETURN
}
return(cresult);
}
//#define LED_SHOW_NONE 0
//#define LED_SHOW_RED 1
//#define LED_SHOW_GRN 2
//#define LED_SHOW_BLU 3
//#define LED_SHOW_AUTO 4
void led_showbin(unsigned char color, unsigned char bitdata)
{
portc.SIG_RC_DISP_RED_O = 1;
portc.SIG_RC_DISP_BLU_O = 1;
portc.SIG_RC_DISP_GRN_O = 1; // TURN OFF COLORS
if(bitdata & 01000000b) {
portb.SIG_RB_DISPLED1_O = 1;
}
else {
portb.SIG_RB_DISPLED1_O = 0;
}
if(bitdata & 00100000b) {
portb.SIG_RB_DISPLED2_O = 1;
}
else {
portb.SIG_RB_DISPLED2_O = 0;
}
if(bitdata & 00010000b) {
portb.SIG_RB_DISPLED3_O = 1;
}
else {
portb.SIG_RB_DISPLED3_O = 0;
}
if(bitdata & 00001000b) {
portb.SIG_RB_DISPLED4_O = 1;
}
else {
portb.SIG_RB_DISPLED4_O = 0;
}
if(bitdata & 00000100b) {
portb.SIG_RB_DISPLED5_O = 1;
}
else {
portb.SIG_RB_DISPLED5_O = 0;
}
if(bitdata & 00000010b) {
portc.SIG_RC_DISPLED6_O = 1;
}
else {
portc.SIG_RC_DISPLED6_O = 0;
}
if(bitdata & 00000001b) {
portc.SIG_RC_DISPLED7_O = 1;
}
else {
portc.SIG_RC_DISPLED7_O = 0;
}
switch(color) { // TURN ON
case LED_SHOW_NONE:
break;
case LED_SHOW_RED:
portc.SIG_RC_DISP_RED_O = 0;
break;
case LED_SHOW_GRN:
portc.SIG_RC_DISP_GRN_O = 0;
break;
case LED_SHOW_BLU:
portc.SIG_RC_DISP_BLU_O = 0;
break;
}
}
volatile unsigned short povcycles = 0;
void led_pov_next(unsigned char color)
{
static unsigned char autocolor;
static unsigned char charcnt; // Character in the string
static unsigned char colcnt; // Column in the character
if(charcnt >= NUMCHARS) {
charcnt = 0;
povcycles++;
autocolor++;
if (autocolor > LED_SHOW_BLU) {
autocolor = LED_SHOW_RED;
}
}
led_showbin(color == LED_SHOW_AUTO ? autocolor : color, readcharmap(povstring[charcnt], colcnt));
delay_10us(40);
led_showbin(color == LED_SHOW_AUTO ? autocolor : color, 0);
colcnt++;
if(colcnt >= NUMCOL) {
colcnt = 0;
charcnt++;
delay_10us(80);
}
}
void led_pov(unsigned char color, unsigned short cycles)
{
povcycles = 0;
while (povcycles < cycles) {
led_pov_next(color);
}
}