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

Legend:
Removed from v.138  
changed lines
  Added in v.139

  ViewVC Help
Powered by ViewVC 1.1.20