/[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 108 by hedin, Thu Nov 29 13:23:57 2007 UTC revision 109 by hedin, Fri Nov 30 13:47:05 2007 UTC
# Line 1  Line 1 
1  #include <pic18.h>  #include <pic18.h>
2  #include <stdio.h>  #include <stdio.h>
3  #include <string.h>  #include <string.h>
   
4  #include "lcd.h"  #include "lcd.h"
5    // Delay.h is included inside lcd.c
6    
7    #define LCD_LENGTH 16
8    #define LCD_ROWS 2
9    
10    
11  void AD_init(void)  unsigned char global_Pot_Hi;
12    unsigned char global_Pot_Lo;
13    unsigned char global_LCD_Buffer[LCD_ROWS][LCD_LENGTH];
14    /*void AD_init(void)
15  {  {
16          ADON    = 1;          ADON    = 1;
17  }  }
18    */
19    // Nicked from H7
20    void ad_init(void)
21    {
22            // AD Conversion clock
23            ADCS0 = 0;
24            ADCS1 = 0;
25            ADCS2 = 0;
26    
27            //Select AN0/RA0 for AD source
28                    // In this (000) setup, it's only RA0/AN0 that does ad convertion.
29            CHS0=0;
30            CHS1=0;
31            CHS2=0;
32            
33            //Only AN0 is selected for AD and with Vdd/Vss as limits
34            PCFG0=0;
35            PCFG1=1;
36            PCFG2=1;
37            PCFG3=1;
38            
39            //Result is right justified
40            ADFM=1;
41            
42            //Fire up for A/D converter module
43            ADON=1;
44    }
45    
46  void rs232_init(void)  void rs232_init(void)
47  {  {
# Line 31  void interrupt_init(void) Line 65  void interrupt_init(void)
65    
66  void pic18_io_init(void)  void pic18_io_init(void)
67  {  {
68          TRISA0  = 1;          TRISA0  = 1;    // analog input
69          TRISB1  = 1;          TRISB1  = 1;    // TRISB1-4 Digital input
70          TRISB2  = 1;          TRISB2  = 1;
71          TRISB3  = 1;          TRISB3  = 1;
72          TRISB4  = 1;          TRISB4  = 1;
# Line 44  void interrupt_recieve_handler(void) Line 78  void interrupt_recieve_handler(void)
78  }  }
79    
80  void interrupt interrupt_handler(void)  void interrupt interrupt_handler(void)
 // Finds out what interrupt have been trigged, and starts the respective function.  
81  {  {
82            // Finds out what interrupt have been trigged, and starts the respective function.
83          if(RCIF == 1)          if(RCIF == 1)
84          {          {
85                  interrupt_recieve_handler();                  interrupt_recieve_handler();
86                  RCIF = 0;                  RCIF = 0;
87          }          }
88  }                }              
89    
90    void update_lcd(void)
91    {
92            int i = 0, horizontal = 0, vertical = 0;
93            char alfa[2][LCD_LENGTH];
94                    
95            
96            static char current_row = 0;
97            static char current_char = 0;
98            char toLCD0[LCD_LENGTH], toLCD1[LCD_LENGTH];
99            char B1[16];
100            lcd_goto(0x00);
101            sprintf(toLCD0, "%s", "Ejdesgaard");
102            if(RB1)
103            {
104                    sprintf(B1, "Pwr%s", "True");
105            }
106            else
107            {
108                    sprintf(B1, "%s", "False");
109            }
110            lcd_puts(B1);
111            
112            lcd_goto(0x40);
113    //      sprintf(toLCD1, "%s", "Test");
114            lcd_puts("Test1");
115            
116    }
117    
118  void main()  void main()
119  {  {
120          AD_init();  /////////////////////////////////////////////
121    // Running Init's
122    
123            // Running init for various components.
124            //AD_init();
125            ad_init();
126          rs232_init();          rs232_init();
127          pic18_io_init();          pic18_io_init();
128                    lcd_init(0);
129          if(GODONE==0)  
130    /////////////////////////////////////////////
131    // Main loop
132    
133            while(1)
134          {          {
135            // Checking if A/D convertion is done, and save the data in global_Pot_??
136                    if(GODONE==0)
137                    {
138                            global_Pot_Hi = ADRESH;
139                            global_Pot_Lo = ADRESL;
140                            GODONE = 0;
141                    }
142                                    
143            update_lcd();
144          }          }
145  }  }

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

  ViewVC Help
Powered by ViewVC 1.1.20