25 |
25: ADCS2 = 0; |
25: ADCS2 = 0; |
26 |
26: |
26: |
27 |
27: //Select AN0/RA0 for AD source |
27: //Select AN0/RA0 for AD source |
28 |
28: CHS0=0; |
28: // In this (000) setup, it's only RA0/AN0 that does ad convertion. |
29 |
29: CHS1=0; |
29: CHS0=0; |
30 |
30: CHS2=0; |
30: CHS1=0; |
31 |
31: |
31: CHS2=0; |
32 |
32: //Only AN0 is selected for AD and with Vdd/Vss as limits |
32: |
33 |
33: PCFG0=0; |
33: //Only AN0 is selected for AD and with Vdd/Vss as limits |
34 |
34: PCFG1=1; |
34: PCFG0=0; |
35 |
35: PCFG2=1; |
35: PCFG1=1; |
36 |
36: PCFG3=1; |
36: PCFG2=1; |
37 |
37: |
37: PCFG3=1; |
38 |
38: //Result is right justified |
38: |
39 |
39: ADFM=1; |
39: //Result is left justified |
40 |
40: |
40: ADFM=0; |
41 |
41: //Fire up for A/D converter module |
41: |
42 |
42: ADON=1; |
42: //Fire up for A/D converter module |
43 |
43: } |
43: ADON=1; |
44 |
44: |
44: } |
45 |
45: void rs232_init(void) |
45: |
46 |
46: { |
46: void rs232_init(void) |
47 |
47: SPEN = 0; // Serial Port Enable Bit... 0 = disabled |
47: { |
48 |
48: TRISC6 = 0; |
48: SPEN = 0; // Serial Port Enable Bit... 0 = disabled |
49 |
49: TRISC7 = 1; |
49: TRISC6 = 0; |
50 |
50: SYNC = 0; // SYNC switches between async(0) and sync(1) mode. |
50: TRISC7 = 1; |
51 |
51: SPBRG = 25; |
51: SYNC = 0; // SYNC switches between async(0) and sync(1) mode. |
52 |
52: TXSTA = 0x24; |
52: SPBRG = 25; |
53 |
53: RCSTA = 0x90; |
53: TXSTA = 0x24; |
54 |
54: SPEN = 1; |
54: RCSTA = 0x90; |
55 |
55: } |
55: SPEN = 1; |
56 |
56: |
56: } |
57 |
57: void interrupt_init(void) |
57: |
58 |
58: { |
58: void interrupt_init(void) |
59 |
59: // Assumes that all interrupts default is 0 |
59: { |
60 |
60: PEIE = 1; |
60: // Assumes that all interrupts default is 0 |
61 |
61: GIE = 1; |
61: PEIE = 1; |
62 |
62: RCIE = 1; |
62: GIE = 1; |
63 |
63: } |
63: RCIE = 1; |
64 |
64: |
64: } |
65 |
65: void pic18_io_init(void) |
65: |
66 |
66: { |
66: void pic18_io_init(void) |
67 |
67: TRISA0 = 1; // analog input |
67: { |
68 |
68: TRISB1 = 1; // TRISB1-4 Digital input |
68: TRISA0 = 1; // analog input |
69 |
69: TRISB2 = 1; |
69: TRISB1 = 1; // TRISB1-4 Digital input |
70 |
70: TRISB3 = 1; |
70: TRISB2 = 1; |
71 |
71: TRISB4 = 1; |
71: TRISB3 = 1; |
72 |
72: } |
72: TRISB4 = 1; |
73 |
73: |
73: } |
74 |
74: void interrupt_recieve_handler(void) |
74: |
75 |
75: { |
75: void interrupt_recieve_handler(void) |
76 |
76: // Handle recieve inputs... |
76: { |
77 |
77: } |
77: // Handle recieve inputs... |
78 |
78: |
78: } |
79 |
79: void interrupt interrupt_handler(void) |
79: |
80 |
80: { |
80: void interrupt interrupt_handler(void) |
81 |
81: // Finds out what interrupt have been trigged, and starts the respective function. |
81: { |
82 |
82: if(RCIF == 1) |
82: // Finds out what interrupt have been trigged, and starts the respective function. |
83 |
83: { |
83: if(RCIF == 1) |
84 |
84: interrupt_recieve_handler(); |
84: { |
85 |
85: RCIF = 0; |
85: interrupt_recieve_handler(); |
86 |
86: } |
86: RCIF = 0; |
87 |
87: } |
87: } |
88 |
88: |
88: } |
89 |
89: void update_lcd(void) |
89: |
90 |
90: { |
90: void update_lcd(void) |
91 |
91: int i = 0, horizontal = 0, vertical = 0; |
91: { |
92 |
92: char alfa[2][LCD_LENGTH]; |
92: char toLCD0[LCD_LENGTH], toLCD1[LCD_LENGTH]; |
93 |
93: |
93: char B1[LCD_LENGTH]; |
94 |
94: |
94: char sprintF[LCD_LENGTH]; |
95 |
95: static char current_row = 0; |
95: lcd_goto(0x00); |
96 |
96: static char current_char = 0; |
96: sprintf(toLCD0, "%s", "Ejdesgaard"); |
97 |
97: char toLCD0[LCD_LENGTH], toLCD1[LCD_LENGTH]; |
97: if(RB1) |
98 |
98: char B1[16]; |
98: { |
99 |
99: lcd_goto(0x00); |
99: sprintf(B1, "Pwr%s", "True"); |
100 |
100: sprintf(toLCD0, "%s", "Ejdesgaard"); |
100: } |
101 |
101: if(RB1) |
101: else |
102 |
102: { |
102: { |
103 |
103: sprintf(B1, "%s", "True"); |
103: sprintf(B1, "%s", "False"); |
104 |
104: } |
104: } |
105 |
105: else |
105: lcd_puts(B1); |
106 |
106: { |
106: |
107 |
107: sprintf(B1, "%s", "False"); |
107: lcd_goto(0x40); |
108 |
108: } |
108: sprintf(sprintF,"%08d%08d", global_Pot_Hi, global_Pot_Lo); |
109 |
109: lcd_puts(B1); |
109: lcd_puts(sprintF); |
110 |
110: |
110: |
111 |
111: lcd_goto(0x40); |
111: } |
112 |
112: // sprintf(toLCD1, "%s", "Test"); |
112: |
113 |
113: lcd_puts("Test1"); |
113: void main() |
114 |
114: |
114: { |
115 |
115: } |
115: ///////////////////////////////////////////// |
116 |
116: |
116: // Running Init's |
117 |
117: void main() |
117: |
118 |
118: { |
118: // Running init for various components. |
119 |
119: ///////////////////////////////////////////// |
119: //AD_init(); |
120 |
120: // Running Init's |
120: ad_init(); |
121 |
121: |
121: rs232_init(); |
122 |
122: // Running init for various components. |
122: pic18_io_init(); |
123 |
123: //AD_init(); |
123: lcd_init(0); |
124 |
124: ad_init(); |
124: |
125 |
125: rs232_init(); |
125: ///////////////////////////////////////////// |
126 |
126: pic18_io_init(); |
126: // Main loop |
127 |
127: lcd_init(0); |
127: |
128 |
128: |
128: while(1) |
129 |
129: ///////////////////////////////////////////// |
129: { |
130 |
130: // Main loop |
130: // Checking if A/D convertion is done, and save the data in global_Pot_?? |
131 |
131: |
131: if(GODONE==0) |
132 |
132: while(1) |
132: { |
133 |
133: { |
133: global_Pot_Hi = ADRESH; |
134 |
134: // Checking if A/D convertion is done, and save the data in global_Pot_?? |
134: global_Pot_Lo = ADRESL; |
135 |
135: if(GODONE==0) |
135: GODONE = 1; |
136 |
136: { |
136: } |
137 |
137: global_Pot_Hi = ADRESH; |
137: |
138 |
138: global_Pot_Lo = ADRESL; |
138: update_lcd(); |
139 |
139: GODONE = 0; |
139: } |
140 |
140: } |
140: } |
|
141: |
|
|
142: update_lcd(); |
|
|
143: } |
|
|
144: } |
|