This repository has been archived by the owner on Apr 29, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathScratch.c
executable file
·208 lines (197 loc) · 5.18 KB
/
Scratch.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
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
#define tris_ICSPDAT TRISAbits.TRISA2 // AN2 Input/Output
#define ICSPDAT_in PORTAbits.RA2
#define ICSPDAT_out LATAbits.LATA2
#define tris_ICSPCLK TRISAbits.TRISA3 // AN3 Input/Output
#define ICSPCLK_in PORTAbits.RA3
#define ICSPCLK_out LATAbits.LATA3
#define tris_AUX TRISAbits.TRISA4 // AN4 Input/Output
#define AUX_in PORTAbits.RA4
#define AUX LATAbits.LATA4
#define tris_MCLR_TGT TRISAbits.TRISA5 // AN5 Output
#define MCLR_TGT LATAbits.LATA5
#define MCLR_TGT_pin PORTAbits.RA5 // WEK
#define tris_BUSY_LED TRISCbits.TRISC0 // RC0 Output
#define BUSY_LED LATCbits.LATC0
extern volatile near unsigned char PIE1;
extern volatile near struct {
unsigned TMR1IE:1;
unsigned TMR2IE:1;
unsigned CCP1IE:1;
unsigned SSPIE:1;
unsigned TXIE:1;
unsigned RCIE:1;
unsigned ADIE:1;
} PIE1bits;
extern volatile near unsigned char PIR1;
extern volatile near struct {
unsigned TMR1IF:1;
unsigned TMR2IF:1;
unsigned CCP1IF:1;
unsigned SSPIF:1;
unsigned TXIF:1;
unsigned RCIF:1;
unsigned ADIF:1;
} PIR1bits;
extern volatile near unsigned char PIE2;
extern volatile near union {
struct {
unsigned CCP2IE:1;
unsigned TMR3IE:1;
unsigned LVDIE:1;
unsigned BCLIE:1;
unsigned EEIE:1;
unsigned USBIE:1;
unsigned CMIE:1;
unsigned OSCFIE:1;
};
struct {
unsigned :2;
unsigned HLVDIE:1;
};
} PIE2bits;
extern volatile near unsigned char PIR2;
extern volatile near union {
struct {
unsigned CCP2IF:1;
unsigned TMR3IF:1;
unsigned LVDIF:1;
unsigned BCLIF:1;
unsigned EEIF:1;
unsigned USBIF:1;
unsigned CMIF:1;
unsigned OSCFIF:1;
};
struct {
unsigned :2;
unsigned HLVDIF:1;
};
} PIR2bits;
extern volatile near unsigned char IPR2;
extern volatile near union {
struct {
unsigned CCP2IP:1;
unsigned TMR3IP:1;
unsigned LVDIP:1;
unsigned BCLIP:1;
unsigned EEIP:1;
unsigned USBIP:1;
unsigned CMIP:1;
unsigned OSCFIP:1;
};
struct {
unsigned :2;
unsigned HLVDIP:1;
};
} IPR2bits;
extern volatile near unsigned char T1CON;
extern volatile near union {
struct {
unsigned TMR1ON:1;
unsigned TMR1CS:1;
unsigned T1SYNC:1;
unsigned T1OSCEN:1;
unsigned T1CKPS0:1;
unsigned T1CKPS1:1;
unsigned T1RUN:1;
unsigned RD16:1;
};
struct {
unsigned :2;
unsigned NOT_T1SYNC:1;
};
} T1CONbits;
extern volatile near unsigned char TMR1L;
extern volatile near unsigned char TMR1H;
extern volatile near unsigned char T3CON;
extern volatile near union {
struct {
unsigned TMR3ON:1;
unsigned TMR3CS:1;
unsigned T3SYNC:1;
unsigned T3CCP1:1;
unsigned T3CKPS0:1;
unsigned T3CKPS1:1;
unsigned T3CCP2:1;
unsigned RD16:1;
};
struct {
unsigned :2;
unsigned T3NSYNC:1;
};
struct {
unsigned :2;
unsigned NOT_T3SYNC:1;
};
} T3CONbits;
extern volatile near unsigned char TMR3L;
extern volatile near unsigned char TMR3H;
extern volatile near unsigned char CMCON;
extern volatile near struct {
unsigned CM0:1;
unsigned CM1:1;
unsigned CM2:1;
unsigned CIS:1;
unsigned C1INV:1;
unsigned C2INV:1;
unsigned C1OUT:1;
unsigned C2OUT:1;
} CMCONbits;
extern volatile near unsigned char CVRCON;
extern volatile near union {
struct {
unsigned CVR0:1;
unsigned CVR1:1;
unsigned CVR2:1;
unsigned CVR3:1;
unsigned CVREF:1;
unsigned CVRR:1;
unsigned CVROE:1;
unsigned CVREN:1;
};
struct {
unsigned :4;
unsigned CVRSS:1;
};
} CVRCONbits;
union { // Status bits
struct {
unsigned char StatusLow;
unsigned char StatusHigh;
};
struct{
// StatusLow
unsigned VddGNDOn:1; // bit 0
unsigned VddOn:1;
unsigned VppGNDOn:1;
unsigned VppOn:1;
unsigned VddError:1;
unsigned VppError:1;
unsigned ButtonPressed:1;
unsigned :1;
//StatusHigh
unsigned Reset:1; // bit 0
unsigned UARTMode:1;
unsigned ICDTimeOut:1;
unsigned UpLoadFull:1;
unsigned DownloadEmpty:1;
unsigned EmptyScript:1;
unsigned ScriptBufOvrFlow:1;
unsigned DownloadOvrFlow:1;
};
} Pk2Status;
struct {
unsigned char TimerBaudLoadL; // timer value to load for particular baud rate
unsigned char TimerBaudLoadH;
unsigned char RXbits; // # bits received during byte reception
unsigned char RXbyte; // Byte value being received
unsigned char TXbits; // # bits send during byte transmission
unsigned char TXByte; // Byte value being sent
unsigned char LastRXByte; // Received byte to be saved
unsigned char NewRX; // flag for new data in LastRXByte
} UARTStatus;
void ExitUARTMode(void)
void ICDSlaveBL_transmit (unsigned char TransmitByte)
unsigned char ICDSlaveBL_Receive (void)
#define ICDSLAVE_RX_BL 0xC2
#define ICDSLAVE_TX_LIT_BL 0xC1
#define ICDSLAVE_TX_BUF_BL 0xC0