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

Diff of /trunk/Embedded/main.c

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

revision 112 by hedin, Fri Nov 30 16:07:03 2007 UTC revision 139 by hedin, Mon Dec 3 17:19:35 2007 UTC
# Line 2  Line 2 
2  #include <stdio.h>  #include <stdio.h>
3  #include <string.h>  #include <string.h>
4  #include "lcd.h"  #include "lcd.h"
5    #include "Delay.h"
6  // Delay.h is included inside lcd.c  // Delay.h is included inside lcd.c
7    
8  #define LCD_LENGTH 16  #define LCD_LENGTH 16
9  #define LCD_ROWS 2  #define LCD_ROWS 2
10    #define SEND_BUFFER 128
11    
12    
13  unsigned char global_Pot_Hi;  unsigned char global_Pot_Hi, global_Pot_Lo;
 unsigned char global_Pot_Lo;  
14  unsigned char global_LCD_Buffer[LCD_ROWS][LCD_LENGTH];  unsigned char global_LCD_Buffer[LCD_ROWS][LCD_LENGTH];
15  /*void AD_init(void)  unsigned char global_serial_send[SEND_BUFFER];
16  {  unsigned char global_serial_recieve_buffer[LCD_LENGTH];
17          ADON    = 1;  bit global_recieve_done = 0;
18  }  int global_serial_byte_counter = 0;
19  */  
20    void serial_recieved(void);
21    void serial_send(void);
22    void update_lcd(void);
23    
24  // Nicked from H7  // Nicked from H7
25  void ad_init(void)  void ad_init(void)
26  {  {
# Line 46  void ad_init(void) Line 51  void ad_init(void)
51  void rs232_init(void)  void rs232_init(void)
52  {  {
53          SPEN    = 0;    // Serial Port Enable Bit... 0 = disabled          SPEN    = 0;    // Serial Port Enable Bit... 0 = disabled
54          TRISC6  = 0;          TRISC6  = 0;    
55          TRISC7  = 1;          TRISC7  = 1;
56          SYNC    = 0;    // SYNC switches between async(0) and sync(1) mode.  
57          SPBRG   = 25;          SPBRG   = 207;  // 1200 baud rate... 25 = 9600
58          TXSTA   = 0x24;                                          // x = (Fosc / (16*[baud rate]) )-1
59          RCSTA   = 0x90;          TXSTA   = 0x24; // Enables BRGH and TXEN inthe TXSTA register
60          SPEN    = 1;          RCSTA   = 0x90; // 0x90 enables SPEN and CREN in the RCSTA register
61  }  }
62    
63  void interrupt_init(void)  void interrupt_init(void)
# Line 60  void interrupt_init(void) Line 65  void interrupt_init(void)
65          // Assumes that all interrupts default is 0          // Assumes that all interrupts default is 0
66          PEIE    = 1;          PEIE    = 1;
67          GIE             = 1;          GIE             = 1;
68          RCIE    = 1;          RCIE    = 1;    // Recieve interrupt enable.
69            IPEN    = 0;    // Nfo interrupt priority
70            TXIE    = 0;    // Serial interrupt enabled
71  }        }      
72    
73  void pic18_io_init(void)  void pic18_io_init(void)
# Line 72  void pic18_io_init(void) Line 79  void pic18_io_init(void)
79          TRISB4  = 1;          TRISB4  = 1;
80  }        }      
81    
82  void interrupt_recieve_handler(void)  void sms_init(void)
83  {  {
84          // Handle recieve inputs...          int i = 1;
85            sprintf(global_serial_send,"%s", "at+cpin=8043\r");
86            serial_send();
87            DelaySek(60);
88            
89            update_lcd();
90            DelaySek(5);
91            
92            sprintf(global_serial_send,"%s%s", "at+cmgs=","\"22337617\"\r");
93            serial_send();
94            DelayMs(5000);
95            
96            sprintf(global_serial_send,"%s%d%c","Dette er test nr: ", i, 0x1A);
97            serial_send();
98            DelayMs(5000);
99            i++;
100            
101  }  }
102    
103  void interrupt interrupt_handler(void)  void interrupt interrupt_handler(void)
104  {  {
105          // Finds out what interrupt have been trigged, and starts the respective function.          // Finds out what interrupt have been trigged, and starts the respective function.
106          if(RCIF == 1)          if(RCIF == 1)                   // Serial recieve interrupt
107          {          {
108                  interrupt_recieve_handler();                  serial_recieved();
109                  RCIF = 0;                  RCIF = 0;
110          }          }
111  }                }              
112    
113  void update_lcd(void)  
114  {        
115          char toLCD0[LCD_LENGTH], toLCD1[LCD_LENGTH];  void serial_send(void)
116          char B1[LCD_LENGTH];  {
117          char sprintF[LCD_LENGTH];          int i;
118          lcd_goto(0x00);  //      char tosend[3];
119          sprintf(toLCD0, "%s", "Ejdesgaard");          char data;
120          if(RB1)  //      sprintf(tosend,"%s", "at\r");
121            for(i = 0; i < SEND_BUFFER; i++)
122          {          {
123                  sprintf(B1, "Pwr%s", "True");                  data = global_serial_send[i];
124                    if( data == '\r')
125                            i = (SEND_BUFFER - 1);
126                    TXREG = data;
127                    while(TRMT==0) ;
128                    DelayMs(1000);
129          }          }
130    }      
131    
132    void serial_recieved(void)
133    {
134            char data, saved_data[LCD_LENGTH];
135            
136            data = RCREG;
137            
138            global_serial_recieve_buffer[global_serial_byte_counter] = data;
139            if(data == '\r')
140            {
141                    global_recieve_done = 1;
142                    global_serial_byte_counter = 0;
143            }      
144          else          else
145          {          {
146                  sprintf(B1, "%s", "False");                  global_serial_byte_counter++;
147          }          }
         lcd_puts(B1);  
           
         lcd_goto(0x40);  
         sprintf(sprintF,"%08d%08d", global_Pot_Hi, global_Pot_Lo);  
         lcd_puts(sprintF);  
148                    
149  }  }
150    void update_lcd(void)
151    {
152            if( global_recieve_done == 1 )
153            {
154                    lcd_clear();
155                    lcd_goto(0x00);
156                    lcd_puts(global_serial_recieve_buffer);
157                    global_recieve_done = 0;
158            }
159    }
160            
161  void main()  void main()
162  {  {
163  /////////////////////////////////////////////  /////////////////////////////////////////////
# Line 121  void main() Line 169  void main()
169          rs232_init();          rs232_init();
170          pic18_io_init();          pic18_io_init();
171          lcd_init(0);          lcd_init(0);
172            lcd_clear();
173            interrupt_init();
174            sms_init();
175  /////////////////////////////////////////////  /////////////////////////////////////////////
176  // Main loop  // Main loop
177    
# Line 134  void main() Line 184  void main()
184                          global_Pot_Lo = ADRESL;                          global_Pot_Lo = ADRESL;
185                          GODONE = 1;                          GODONE = 1;
186                  }                  }
187                                    update_lcd();
         update_lcd();  
188          }          }
189  }  }

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

  ViewVC Help
Powered by ViewVC 1.1.20