4 |
#include "tick.h" |
#include "tick.h" |
5 |
#include "delay.h" |
#include "delay.h" |
6 |
#include "network.h" |
#include "network.h" |
7 |
|
#include "barcode.h" |
8 |
|
#include "keyboard.h" |
9 |
|
#include "MyI2C.h" |
10 |
|
#include "xlcd.h" |
11 |
#include <string.h> |
#include <string.h> |
12 |
|
|
|
|
|
13 |
/* |
/* |
14 |
* This is used by other stack elements. |
* This is used by other stack elements. |
15 |
* Main application must define this and initialize it with |
* Main application must define this and initialize it with |
47 |
static void InitializeBoard(void); |
static void InitializeBoard(void); |
48 |
static void SetConfig(void); |
static void SetConfig(void); |
49 |
|
|
50 |
|
// Skal fjernes |
51 |
|
#define LCD_IC 0x74 |
52 |
|
void mylcd_write_byte(unsigned char data) |
53 |
|
{ |
54 |
|
StartI2C(LCD_IC); |
55 |
|
WriteI2CByte( data ); |
56 |
|
StopI2C(); |
57 |
|
Delay10us(1); //I2C spec's siger min 4.7 uSec mellem stop og næste start |
58 |
|
} |
59 |
|
|
60 |
|
|
61 |
|
|
62 |
void main(void) |
void main(void) |
63 |
{ |
{ |
64 |
// Tick to blink SYSTEM led. |
// Tick to blink SYSTEM led. |
65 |
static TICK t = 0; |
static TICK t = 0; |
66 |
|
char i; |
67 |
|
unsigned char numbers[20]; |
68 |
|
unsigned long amount; |
69 |
|
unsigned char lcd_buffer[21]; |
70 |
|
short number_count = 0; |
71 |
|
short produkt_amount = 0; |
72 |
|
static bit hello = 0; |
73 |
|
short varetal = 1; |
74 |
|
|
75 |
TICK tick; |
TICK tick; |
76 |
TICK lastTick; |
TICK lastTick; |
96 |
StackInit(); |
StackInit(); |
97 |
|
|
98 |
network_init(); |
network_init(); |
99 |
|
barcode_init(); |
100 |
|
InitI2C(); |
101 |
|
XLCDInit(); |
102 |
|
|
103 |
|
|
104 |
|
|
105 |
/* |
/* |
124 |
|
|
125 |
while(1) |
while(1) |
126 |
{ |
{ |
127 |
|
char keyboard_entered; |
128 |
|
char network_error; |
129 |
|
|
130 |
|
|
131 |
/* |
/* |
132 |
* Blink SYSTEM LED every second. |
* Blink SYSTEM LED every second. |
133 |
*/ |
*/ |
148 |
* For DHCP information, display how many times we have renewed the IP |
* For DHCP information, display how many times we have renewed the IP |
149 |
* configuration since last reset. |
* configuration since last reset. |
150 |
*/ |
*/ |
151 |
|
|
152 |
|
//mylcd_write_byte(0b10100101); |
153 |
network_send_hello( 0x01 ); |
|
154 |
|
if( (barcode_is_ready() || keyboard_entered) && !hello){ |
155 |
strncpy(global_network_char, "12345678", 8); |
network_send_hello(0x01); |
156 |
|
hello = 1; |
157 |
|
} |
158 |
|
if (barcode_is_ready()) |
159 |
|
{ |
160 |
|
for (i=0;i< barcode_get_length(); i++) |
161 |
|
{ |
162 |
|
global_network_char[i] = global_barcode_buffer[i]; |
163 |
|
global_network_charlen = barcode_get_length(); |
164 |
|
} |
165 |
|
barcode_reset(); |
166 |
|
network_send_scan_frame( varetal, global_network_charlen ); |
167 |
|
varetal = 1; |
168 |
|
/* |
169 |
|
XLCDClear(); |
170 |
|
XLCDGoto(1,0); |
171 |
|
for (i=0;i< barcode_get_length(); i++) |
172 |
|
{ |
173 |
|
XLCDPut(global_barcode_buffer[i]); |
174 |
|
} |
175 |
|
*/ |
176 |
|
} |
177 |
|
|
178 |
|
keyboard_entered = keyboard_read_safe(); |
179 |
|
if( keyboard_entered ) |
180 |
|
{ |
181 |
|
switch( keyboard_entered ) |
182 |
|
{ |
183 |
|
case 'A': |
184 |
|
network_send_calc_total(); |
185 |
|
XLCDClear(); |
186 |
|
XLCDGoto(0,0); |
187 |
|
for( i=0; i<global_network_charlen; i++ ) |
188 |
|
{ |
189 |
|
XLCDPut(global_network_char[i]); |
190 |
|
} |
191 |
|
break; |
192 |
|
|
193 |
|
case 'B': |
194 |
|
numbers[number_count] = 0; //nulterminering inden brug af atol |
195 |
|
amount = atol(numbers); |
196 |
|
number_count = 0; |
197 |
|
|
198 |
|
network_send_cash_payed(amount); |
199 |
|
network_send_goodbye(); |
200 |
|
hello = 0; |
201 |
|
|
202 |
|
sprintf(lcd_buffer,"%5d", amount); |
203 |
|
XLCDGoto(0,0); |
204 |
|
XLCDPutString(lcd_buffer); |
205 |
|
break; |
206 |
|
|
207 |
|
case 'C': |
208 |
|
network_send_cancel_last(); |
209 |
|
break; |
210 |
|
|
211 |
|
case 'D': |
212 |
|
network_send_cancel_all(); |
213 |
|
network_send_goodbye(); |
214 |
|
hello = 0; |
215 |
|
break; |
216 |
|
|
217 |
|
case 'E': |
218 |
|
for( i=0; i<number_count;i++ ) |
219 |
|
{ |
220 |
|
global_network_char[i] = numbers[i]; |
221 |
|
} |
222 |
|
network_send_scan_frame( varetal, number_count ); |
223 |
|
varetal = 1; |
224 |
|
number_count = 0; |
225 |
|
break; |
226 |
|
|
227 |
|
case 'F': |
228 |
|
numbers[number_count] = 0; //nulterminering inden brug af atol |
229 |
|
varetal = atol(numbers); |
230 |
|
number_count = 0; |
231 |
|
break; |
232 |
|
|
233 |
|
default: |
234 |
|
numbers[number_count] = keyboard_entered; |
235 |
|
|
236 |
|
//numbers; // got to catch 0-9; 20 byte array. |
237 |
|
number_count++; // amount of used bytes in numbers. |
238 |
|
} |
239 |
|
|
240 |
|
} |
241 |
|
/* |
242 |
|
network_send_hello( 0x01 ); |
243 |
|
|
244 |
|
strncpy(global_network_char, "12345678", 8); |
245 |
network_send_scan_frame( 1, 8 ); //1x vare, stregkodelængde=8 |
network_send_scan_frame( 1, 8 ); //1x vare, stregkodelængde=8 |
246 |
|
|
247 |
strncpy(global_network_char, "87654444", 8); |
strncpy(global_network_char, "87654444", 8); |
248 |
network_send_scan_frame( 1, 8 ); //1x vare, stregkodelængde=8 |
network_send_scan_frame( 1, 8 ); //1x vare, stregkodelængde=8 |
249 |
|
|
250 |
network_send_calc_total(); |
network_send_calc_total(); |
251 |
|
|
252 |
network_send_cash_payed(50000); |
network_send_cash_payed(50000); |
256 |
network_send_cancel_all(); |
network_send_cancel_all(); |
257 |
|
|
258 |
network_send_goodbye(); |
network_send_goodbye(); |
259 |
|
*/ |
260 |
} |
} |
261 |
} |
} |
262 |
|
|
263 |
void interrupt HighISR(void) |
void interrupt HighISR(void) |
264 |
{ |
{ |
265 |
TickUpdate(); |
if (RCIF == 1) |
266 |
|
barcode_interrupt(); |
267 |
|
else |
268 |
|
TickUpdate(); |
269 |
} |
} |
270 |
|
|
271 |
|
|
394 |
return (byteIndex == 3); |
return (byteIndex == 3); |
395 |
} |
} |
396 |
|
|
397 |
|
void XLCDDelay15ms(void) |
398 |
|
{ |
399 |
|
DelayMs(15); |
400 |
|
} |
401 |
|
void XLCDDelay4ms(void) |
402 |
|
{ |
403 |
|
DelayMs(4); |
404 |
|
} |
405 |
|
|
406 |
|
void XLCDDelay100us(void) |
407 |
|
{ |
408 |
|
INTCON_GIEH = 0; |
409 |
|
Delay10us(1); |
410 |
|
INTCON_GIEH = 1; |
411 |
|
} |