/[H7]/trunk/PIC/main.c
ViewVC logotype

Diff of /trunk/PIC/main.c

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

revision 25 by torben, Tue Jan 30 22:49:03 2007 UTC revision 26 by torben, Wed Jan 31 10:45:20 2007 UTC
# Line 67  bit global_comm_ready; Line 67  bit global_comm_ready;
67  bit global_comm_error;  bit global_comm_error;
68    
69  unsigned char global_comm_slipstate;  unsigned char global_comm_slipstate;
70  unsigned char global_comm_currentrate;  unsigned char global_comm_baudrate;
71    
72  unsigned char global_lcd_buffer[20];  unsigned char global_lcd_buffer[2][20];
 unsigned char global_lcd_index;  
73    
74    
75  bit global_led_0;  bit global_led_0;
# Line 90  void recieve_interrupt(void) Line 89  void recieve_interrupt(void)
89  {  {
90          unsigned char data = RCREG;              unsigned char data = RCREG;    
91                    
92            if (global_comm_length == BUFFERLEN) //avoid buffer overrun
93                    global_comm_slipstate == SlipError;
94            
95          switch (global_comm_slipstate)          switch (global_comm_slipstate)
96          {                        {              
97                  case SlipNormal:                  case SlipNormal:
# Line 145  void transmit_interrupt(void) Line 147  void transmit_interrupt(void)
147  //timer overflow ca hvert sekund  //timer overflow ca hvert sekund
148  void timer1_interrupt(void)  void timer1_interrupt(void)
149  {  {
         RB2 = !RB2;  
150          TMR1H = 0xEF;          TMR1H = 0xEF;
151          TMR1L = 0xFF;          TMR1L = 0xFF;
152  }  }
# Line 173  void interrupt interrupt_handler(void) Line 174  void interrupt interrupt_handler(void)
174  ///////////////////////////////////////////////////////////////////  ///////////////////////////////////////////////////////////////////
175  // Slip funktioner  // Slip funktioner
176    
177    
178  void slip_reset(void)  void slip_reset(void)
179  {  {
180          global_comm_error = 0;          global_comm_error = 0;
# Line 253  void slip_highlevel_protocol(void) Line 255  void slip_highlevel_protocol(void)
255                                  {                                  {
256                                          //we can only handle 1200,2400,9600,19200                                          //we can only handle 1200,2400,9600,19200
257                                          if (data == 0 || data == 1 || data == 3 || data == 4)                                          if (data == 0 || data == 1 || data == 3 || data == 4)
258                                            {
259                                                  global_reset_baudrate = 1;                                                  global_reset_baudrate = 1;
260                                                    global_comm_baudrate = data;
261                                            }
262                                          else                                          else
263                                                  global_comm_error = 1;                                                  global_comm_error = 1;
264                                  }                                  }
# Line 312  void slip_send_response(void) Line 317  void slip_send_response(void)
317  }  }
318    
319  ///////////////////////////////////////////////////////////////////  ///////////////////////////////////////////////////////////////////
320  // Gennerelle funktioner  // init funktioner
321    
322  void interrupt_init(void)  void interrupt_init(void)
323  {  {
# Line 433  void timer_init(void) Line 438  void timer_init(void)
438          TMR1ON = 1;          TMR1ON = 1;
439  }  }
440    
441    ///////////////////////////////////////////////////////////////////
442    // Gennerelle funktioner
443    
444    
445  char ReadTemp(void)  char ReadTemp(void)
446  {  {
447          char temp;          char temp;
# Line 444  char ReadTemp(void) Line 453  char ReadTemp(void)
453          return temp;          return temp;
454  }  }
455    
456    void update_lcd(void)
457    {
458    }
459    
460    void reset_baudrate(void)
461    {
462            SPEN = 0; //disable serial port
463            
464            //set baudrate generator, i henhold til side 171 af PIC18F452 dokumentationen
465            switch (global_comm_baudrate)
466            {
467                    case Baud1200:
468                            SPBRG = 207;
469                            break;
470                    case Baud2400:
471                            SPBRG = 103;
472                            break;
473                    case Baud9600:
474                            SPBRG = 25;
475                            break;
476                    case Baud19200:
477                            SPBRG = 12;
478                            break;
479                    default:
480                            SPBRG = 25; // this should not be possible, but default to 9600 anyway
481            }
482            SPEN = 1; // enable the serial port again
483    }
484    
485  ///////////////////////////////////////////////////////////////////  ///////////////////////////////////////////////////////////////////
486  //Main  //Main
# Line 461  void main(void) Line 498  void main(void)
498                    
499    
500          slip_reset(); //take SLIP FSM into normal state          slip_reset(); //take SLIP FSM into normal state
501          global_comm_currentrate = Baud9600; //default baudrate = 9600          global_comm_baudrate = Baud9600; //default baudrate = 9600 (allready set in serial_init)
502          global_reset_baudrate = 0;          global_reset_baudrate = 0;
503                    
504  //      initialisation completed and we are ready to recieve commands - enable serial reception  //      initialisation completed and we are ready to recieve commands - enable serial reception
# Line 478  void main(void) Line 515  void main(void)
515                                    
516                  if ( global_reset_baudrate == 1)                  if ( global_reset_baudrate == 1)
517                  {                  {
518                            reset_baudrate();
519                  }                  }
520                                    
521                  RB1 = global_led_0;                  RB1 = global_led_0;
522          //      RB2 = global_led_1;                  RB2 = global_led_1;
523                  RB3 = global_led_2;                  RB3 = global_led_2;
524                                    
525                  global_temp = ReadTemp();                  global_temp = ReadTemp();

Legend:
Removed from v.25  
changed lines
  Added in v.26

  ViewVC Help
Powered by ViewVC 1.1.20