This repository has been archived by the owner on Jun 6, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfritzing_test.c
169 lines (150 loc) · 3.4 KB
/
fritzing_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
/*
* WORD CLOCK - fritzing_test.c
* ----------------------------
* Program for testing the functionality of the
* processor. To be distributed with Fritzing
* schematics and PCB layout of the electronic
* circuit. The program lights up the words
* TWELVE OCLOCK and the green test LED in an
* alternating pattern.
*
* To be used in Fritzing, the code file must be
* saved with .ino extension and in a suitable folder.
*
* by:
* - Simone Stefani, @SimoneStefani
* - Marcel Eschmann, @eschmar
*
* Compiler:
* B Knudsen Cc5x C-compiler - not ANSI-C
*/
#include "16F690.h"
#include "int16Cxx.h"
#pragma config |= 0x00D4
#define MTEN VSR0.0 = 1
#define HALF VSR0.1 = 1
#define QUARTER VSR0.2 = 1
#define TWENTY VSR0.3 = 1
#define MFIVE VSR0.4 = 1
#define MINUTES VSR0.5 = 1
#define PAST VSR0.6 = 1
#define PEW0 VSR0.7 = 1
#define TO VSR1.0 = 1
#define ONE VSR1.1 = 1
#define TWO VSR1.2 = 1
#define THREE VSR1.3 = 1
#define FOUR VSR1.4 = 1
#define HFIVE VSR1.5 = 1
#define SIX VSR1.6 = 1
#define PEW1 VSR1.7 = 1
#define SEVEN VSR2.0 = 1
#define EIGHT VSR2.1 = 1
#define NINE VSR2.2 = 1
#define HTEN VSR2.3 = 1
#define ELEVEN VSR2.4 = 1
#define TWELVE VSR2.5 = 1
#define OCLOCK VSR2.6 = 1
#define PEW2 VSR2.7 = 1
/**
* Shift Register Pins
*/
#define DATA_PORT PORTC.0
#define CLOCK_PORT PORTC.1
#define STROBE_PORT PORTC.2
/**
* Functions
*/
void shiftOut(char val);
void shiftOutSingle(int b);
void initPorts(void);
void updateShiftRegisters(void);
void updateView(void);
void turnOffLeds(void);
void delay10(char n);
int VSR0, VSR1, VSR2; // shift register X
/**
* Main routine
* Test program to check processor functionality:
* lights up the words TWELVE OCLOCK and the test
* LED in an alternating pattern with 1 sec dealy.
*/
void main(void) {
initPorts();
while(1) {
TWELVE;
OCLOCK;
updateView();
PORTB.5 = 0;
delay10(100);
turnOffLeds();
PORTB.5 = 1;
delay10(100);
}
}
/**
* Initialise PIC16F690 general purpose I/O ports.
*/
void initPorts(void) {
TRISC.0 = 0; // DATA
TRISC.1 = 0; // CLOCK
TRISC.2 = 0; // STROBE
TRISB.5 = 0; // TEST LED
}
/**
* Helper function for shiftOut.
*/
void shiftOutSingle(int b) {
DATA_PORT = b;
CLOCK_PORT = 1;
nop();
CLOCK_PORT = 0;
}
/**
* Shifts out a byte of data one bit at a time. Starts from the most significant bit.
* Each bit is written in turn to a DATA_PORT, after which a CLOCK_PORT is pulsed
* to indicate that the bit is available.
*/
void shiftOut(char val) {
shiftOutSingle(val.7);
shiftOutSingle(val.6);
shiftOutSingle(val.5);
shiftOutSingle(val.4);
shiftOutSingle(val.3);
shiftOutSingle(val.2);
shiftOutSingle(val.1);
shiftOutSingle(val.0);
}
/**
* Update clock face to show new time.
*/
void updateView(void) {
shiftOut((char) VSR2);
shiftOut((char) VSR1);
shiftOut((char) VSR0);
STROBE_PORT = 1;
nop2();
STROBE_PORT = 0;
}
/**
* Power off all LEDs.
*/
void turnOffLeds(void) {
VSR0 = 0;
VSR1 = 0;
VSR2 = 0;
updateView();
}
/**
* Delay function
* Delays a multiple of 10 milliseconds using the TMR0 timer
* error: 0.16 percent. B Knudsen.
*/
void delay10(char n) {
char i;
OPTION = 7;
do {
i = TMR0 + 39;
while (i != TMR0)
;
} while ( --n > 0);
}