/[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 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  #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    
11    
12  unsigned char global_Pot_Hi;  unsigned char global_Pot_Hi, global_Pot_Lo;
 unsigned char global_Pot_Lo;  
13  unsigned char global_LCD_Buffer[LCD_ROWS][LCD_LENGTH];  unsigned char global_LCD_Buffer[LCD_ROWS][LCD_LENGTH];
14  /*void AD_init(void)  unsigned char global_serial_data;
15  {  unsigned char global_serial_recieve_buffer[LCD_LENGTH];
16          ADON    = 1;  bit global_recieve_done = 0;
17  }  int global_serial_byte_counter = 0;
18  */  
19    void serial_recieved(void);
20    
21  // Nicked from H7  // Nicked from H7
22  void ad_init(void)  void ad_init(void)
23  {  {
# Line 36  void ad_init(void) Line 38  void ad_init(void)
38          PCFG2=1;          PCFG2=1;
39          PCFG3=1;          PCFG3=1;
40                    
41          //Result is right justified          //Result is left justified
42          ADFM=1;          ADFM=0;
43                    
44          //Fire up for A/D converter module          //Fire up for A/D converter module
45          ADON=1;          ADON=1;
# Line 46  void ad_init(void) Line 48  void ad_init(void)
48  void rs232_init(void)  void rs232_init(void)
49  {  {
50          SPEN    = 0;    // Serial Port Enable Bit... 0 = disabled          SPEN    = 0;    // Serial Port Enable Bit... 0 = disabled
51          TRISC6  = 0;          TRISC6  = 0;    
52          TRISC7  = 1;          TRISC7  = 1;
53          SYNC    = 0;    // SYNC switches between async(0) and sync(1) mode.  
54          SPBRG   = 25;          SPBRG   = 207;  // 1200 baud rate... 25 = 9600
55          TXSTA   = 0x24;                                          // x = (Fosc / (16*[baud rate]) )-1
56          RCSTA   = 0x90;          TXSTA   = 0x24; // Enables BRGH and TXEN inthe TXSTA register
57          SPEN    = 1;          RCSTA   = 0x90; // 0x90 enables SPEN and CREN in the RCSTA register
58  }  }
59    
60  void interrupt_init(void)  void interrupt_init(void)
# Line 60  void interrupt_init(void) Line 62  void interrupt_init(void)
62          // Assumes that all interrupts default is 0          // Assumes that all interrupts default is 0
63          PEIE    = 1;          PEIE    = 1;
64          GIE             = 1;          GIE             = 1;
65          RCIE    = 1;          RCIE    = 1;    // Recieve interrupt enable.
66            IPEN    = 0;    // Nfo interrupt priority
67            TXIE    = 0;    // Serial interrupt enabled
68  }        }      
69    
70  void pic18_io_init(void)  void pic18_io_init(void)
# Line 72  void pic18_io_init(void) Line 76  void pic18_io_init(void)
76          TRISB4  = 1;          TRISB4  = 1;
77  }        }      
78    
79  void interrupt_recieve_handler(void)  void sms_init(void)
80  {  {
         // Handle recieve inputs...  
81  }  }
82    
83  void interrupt interrupt_handler(void)  void interrupt interrupt_handler(void)
84  {  {
85          // Finds out what interrupt have been trigged, and starts the respective function.          // Finds out what interrupt have been trigged, and starts the respective function.
86          if(RCIF == 1)          if(RCIF == 1)                   // Serial recieve interrupt
87          {          {
88                  interrupt_recieve_handler();                  serial_recieved();
89                  RCIF = 0;                  RCIF = 0;
90          }          }
91  }                }              
92    
93  void update_lcd(void)  
94    
95    void serial_send(void)
96    {
97            int i;
98            char tosend[3];
99            char data;
100            sprintf(tosend,"%s", "at\r");
101            for(i = 0; i < 3; i++)
102            {
103                    data = tosend[i];
104                    TXREG = data;
105                    while(TRMT==0)
106                    DelayMs(1000);
107            }
108    }      
109    
110    void serial_recieved(void)
111  {  {
112          int i = 0, horizontal = 0, vertical = 0;          char data, saved_data[LCD_LENGTH];
         char alfa[2][LCD_LENGTH];  
113                    
114            data = RCREG;
115                    
116          static char current_row = 0;          global_serial_recieve_buffer[global_serial_byte_counter] = data;
117          static char current_char = 0;          if(data == '\r')
         char toLCD0[LCD_LENGTH], toLCD1[LCD_LENGTH];  
         char B1[16];  
         lcd_goto(0x00);  
         sprintf(toLCD0, "%s", "Ejdesgaard");  
         if(RB1)  
118          {          {
119                  sprintf(B1, "Pwr%s", "True");                  global_recieve_done = 1;
120          }                  global_serial_byte_counter = 0;
121            }      
122          else          else
123          {          {
124                  sprintf(B1, "%s", "False");                  global_serial_byte_counter++;
125          }          }
         lcd_puts(B1);  
           
         lcd_goto(0x40);  
 //      sprintf(toLCD1, "%s", "Test");  
         lcd_puts("Test1");  
126                    
127  }  }
128            
129  void main()  void main()
130  {  {
131  /////////////////////////////////////////////  /////////////////////////////////////////////
# Line 126  void main() Line 137  void main()
137          rs232_init();          rs232_init();
138          pic18_io_init();          pic18_io_init();
139          lcd_init(0);          lcd_init(0);
140            interrupt_init();
141            
142  /////////////////////////////////////////////  /////////////////////////////////////////////
143  // Main loop  // Main loop
144    
# Line 137  void main() Line 149  void main()
149                  {                  {
150                          global_Pot_Hi = ADRESH;                          global_Pot_Hi = ADRESH;
151                          global_Pot_Lo = ADRESL;                          global_Pot_Lo = ADRESL;
152                          GODONE = 0;                          GODONE = 1;
153                  }                  }
154                                    
155          update_lcd();                  if( global_recieve_done == 1 )
156                    {
157                            lcd_clear();
158                            lcd_goto(0x00);
159                            lcd_puts(global_serial_recieve_buffer);
160                            global_recieve_done = 0;
161                    }
162          }          }
163  }  }

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

  ViewVC Help
Powered by ViewVC 1.1.20