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

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

  ViewVC Help
Powered by ViewVC 1.1.20