1 |
1: #include <pic18.h>
|
2 |
2: #include <stdio.h>
|
3 |
3: #include <string.h>
|
4 |
4:
|
5 |
5: #include "lcd.h"
|
6 |
6:
|
7 |
7:
|
8 |
8: void rs232_init(void)
|
9 |
9: {
|
10 |
10: SPEN = 0; // Serial Port Enable Bit... 0 = disabled
|
11 |
11: TRISC6 = 0;
|
12 |
12: TRISC7 = 1;
|
13 |
13: SYNC = 0; // SYNC switches between async(0) and sync(1) mode.
|
14 |
14: SPBRG = 25;
|
15 |
15: TXSTA = 0x24;
|
16 |
16: RCSTA = 0x90;
|
17 |
17: SPEN = 1;
|
18 |
18: }
|
19 |
19:
|
20 |
20: void interrupt_init(void)
|
21 |
21: {
|
22 |
22: // Assumes that all interrupts default is 0
|
23 |
23: PEIE = 1;
|
24 |
24: GIE = 1;
|
25 |
25: RCIE = 1;
|
26 |
26: }
|
27 |
27:
|
28 |
28: void pic18_io_init(void)
|
29 |
29: {
|
30 |
30: TRISA0 = 1;
|
31 |
31: TRISB1 = 1;
|
32 |
32: TRISB2 = 1;
|
33 |
33: TRISB3 = 1;
|
34 |
34: TRISB4 = 1;
|
35 |
35: }
|
36 |
36:
|
37 |
37: void interrupt_recieve_handler(void)
|
38 |
38: {
|
39 |
39: // Handle recieve inputs...
|
40 |
40: }
|
41 |
41:
|
42 |
42: void interrupt interrupt_handler(void)
|
43 |
43: {
|
44 |
44: if(RCIF == 1)
|
45 |
45: {
|
46 |
46: interrupt_recieve_handler();
|
47 |
47: RCIF = 0;
|
48 |
48: }
|
49 |
49: }
|
50 |
50:
|
51 |
51:
|
52 |
52: void main()
|
53 |
53: {
|
54 |
54: rs232_init();
|
55 |
55: pic18_io_init();
|
56 |
56: }
|