-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.c
277 lines (185 loc) · 6.95 KB
/
main.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
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
/*******************************************************************************
Copyright 2016 Microchip Technology Inc. (www.microchip.com)
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
To request to license the code under the MLA license (www.microchip.com/mla_license),
please contact [email protected]
*******************************************************************************/
#define CCS_ST7735 LATBbits.LATB2
#define DCs LATBbits.LATB3
#define RES LATBbits.LATB4
/** INCLUDES *******************************************************/
#include "system.h"
#include <stdio.h>
#include "app_device_cdc_basic.h"
#include "app_led_usb_status.h"
#include "usb.h"
#include "usb_device.h"
#include "usb_device_cdc.h"
#include "Fonts.h"
#include "Pic18f4550_spi.h"
#include "ST7735.h"
static unsigned char readBuffer[CDC_DATA_OUT_EP_SIZE];
static uint8_t writeBuffer[CDC_DATA_IN_EP_SIZE];
uint8_t i;
uint8_t numBytesRead;
void Processing_Data(uint8_t Data[])
{
//Clear Display Command, String = clc
if(Data[0]==99 && Data[1]==108 && Data[2]==99)
{
ST7735S_Fill_display(Black_Color);
//putUSBUSART(writeBuffer,3);
// CDCTxService();
}
if(Data[0]==112 && Data[1]==105 && Data[2]==103)
{
//ST7735S_Fill_display(White_Color);
putUSBUSART(writeBuffer,3);
Set_Display_Cursor(0, 0, 63, 91);
CDCTxService();
while(readBuffer[0]!=99 || readBuffer[1]!=114)
{
/* If the USB device isn't configured yet, we can't really do anything
* else since we don't have a host to talk to. So jump back to the
* top of the while loop. */
if( USBGetDeviceState() < CONFIGURED_STATE )
{
return;
}
/* If we are currently suspended, then we need to see if we need to
* issue a remote wakeup. In either case, we shouldn't process any
* keyboard commands since we aren't currently communicating to the host
* thus just continue back to the start of the while loop. */
if( USBIsDeviceSuspended()== true )
{
return;
}
if( USBUSARTIsTxTrfReady() == true)
{
int byte_control;
char value;
byte_control = getsUSBUSART(readBuffer, sizeof(readBuffer));
if(Data[0]==115 && Data[1]==101 && Data[2]==116)
{
Set_Display_Cursor(0, 0, 63, 91);
//CDCTxService();
}
if(byte_control > 0)
{
sprintf(value, "%d", readBuffer[0]);
for(i=0; i<byte_control; i++)
{
write_color(readBuffer[i]);
}
}
}
CDCTxService();
}
}
}
void Get_USB_Data()
{
/* If the USB device isn't configured yet, we can't really do anything
* else since we don't have a host to talk to. So jump back to the
* top of the while loop. */
if( USBGetDeviceState() < CONFIGURED_STATE )
{
return;
}
/* If we are currently suspended, then we need to see if we need to
* issue a remote wakeup. In either case, we shouldn't process any
* keyboard commands since we aren't currently communicating to the host
* thus just continue back to the start of the while loop. */
if( USBIsDeviceSuspended()== true )
{
return;
}
if( USBUSARTIsTxTrfReady() == true)
{
numBytesRead = getsUSBUSART(readBuffer, sizeof(readBuffer));
if(numBytesRead > 0)
{
/* For every byte that was read... */
// for(i=0; i<numBytesRead; i++)
// {
// switch(readBuffer[i])
// {
// /* If we receive new line or line feed commands, just echo
// * them direct.
// */
// case 0x0A:
// case 0x0D:
//
//
//
//
//
//
//
// break;
//
// /* If we receive something else, then echo it plus one
// * so that if we receive 'a', we echo 'b' so that the
// * user knows that it isn't the echo enabled on their
// * terminal program.
// */
// default:
// //writeBuffer[i] = readBuffer[i];
// break;
// }
// }
Processing_Data(readBuffer);
}
// if(numBytesRead > 0)
// {
// /* After processing all of the received data, we need to send out
// * the "echo" data now.
// */
// ;;
// // putUSBUSART(writeBuffer,numBytesRead);
// }
}
CDCTxService();
}
MAIN_RETURN main(void)
{
SYSTEM_Initialize(SYSTEM_STATE_USB_START);
USBDeviceInit();
USBDeviceAttach();
writeBuffer[0] = 79;
writeBuffer[1] = 107;
writeBuffer[2] = 10;
writeBuffer[3] = 13;
//SPI
Spi_init();//start spi interface
Spi_mode(CPOL_1_CPHA_0);//SPI mode 0 0
Spi_clock_mode(SPI_MASTER_CLOCK_DIV_4);//SPI clock = FOSC/4
TRISBbits.RB2 = 0;//SLAVE control PIN
TRISBbits.RB3 = 0;//output DC comman/data ST7735 control
TRISBbits.RB4 = 0;//output DC comman/data ST7735 control
__delay_ms(10);
RES = 1;
CCS_ST7735 = 1;
DCs = 0;
ST7735S_Init(ST7735_128_x_160);
ST7735S_Fill_display(Black_Color);
while(1)
{
SYSTEM_Tasks();
#if defined(USB_POLLING)
#endif
//Application specific tasks
Get_USB_Data();
}//end while
}//end main
/*******************************************************************************
End of File
*/