/[H9]/trunk/Embedded/main.lst
ViewVC logotype

Diff of /trunk/Embedded/main.lst

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

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

Legend:
Removed from v.108  
changed lines
  Added in v.109

  ViewVC Help
Powered by ViewVC 1.1.20