--- trunk/Embedded/main.c 2007/11/30 13:12:44 108 +++ trunk/Embedded/main.c 2007/11/30 13:47:05 109 @@ -1,13 +1,47 @@ #include #include #include - #include "lcd.h" +// Delay.h is included inside lcd.c + +#define LCD_LENGTH 16 +#define LCD_ROWS 2 + -void AD_init(void) +unsigned char global_Pot_Hi; +unsigned char global_Pot_Lo; +unsigned char global_LCD_Buffer[LCD_ROWS][LCD_LENGTH]; +/*void AD_init(void) { ADON = 1; } +*/ +// Nicked from H7 +void ad_init(void) +{ + // AD Conversion clock + ADCS0 = 0; + ADCS1 = 0; + ADCS2 = 0; + + //Select AN0/RA0 for AD source + // In this (000) setup, it's only RA0/AN0 that does ad convertion. + CHS0=0; + CHS1=0; + CHS2=0; + + //Only AN0 is selected for AD and with Vdd/Vss as limits + PCFG0=0; + PCFG1=1; + PCFG2=1; + PCFG3=1; + + //Result is right justified + ADFM=1; + + //Fire up for A/D converter module + ADON=1; +} void rs232_init(void) { @@ -31,8 +65,8 @@ void pic18_io_init(void) { - TRISA0 = 1; - TRISB1 = 1; + TRISA0 = 1; // analog input + TRISB1 = 1; // TRISB1-4 Digital input TRISB2 = 1; TRISB3 = 1; TRISB4 = 1; @@ -44,24 +78,68 @@ } void interrupt interrupt_handler(void) -// Finds out what interrupt have been trigged, and starts the respective function. { + // Finds out what interrupt have been trigged, and starts the respective function. if(RCIF == 1) { interrupt_recieve_handler(); RCIF = 0; } } + +void update_lcd(void) +{ + int i = 0, horizontal = 0, vertical = 0; + char alfa[2][LCD_LENGTH]; + + static char current_row = 0; + static char current_char = 0; + char toLCD0[LCD_LENGTH], toLCD1[LCD_LENGTH]; + char B1[16]; + lcd_goto(0x00); + sprintf(toLCD0, "%s", "Ejdesgaard"); + if(RB1) + { + sprintf(B1, "Pwr%s", "True"); + } + else + { + sprintf(B1, "%s", "False"); + } + lcd_puts(B1); + + lcd_goto(0x40); +// sprintf(toLCD1, "%s", "Test"); + lcd_puts("Test1"); + +} void main() { - AD_init(); +///////////////////////////////////////////// +// Running Init's + + // Running init for various components. + //AD_init(); + ad_init(); rs232_init(); pic18_io_init(); - - if(GODONE==0) + lcd_init(0); + +///////////////////////////////////////////// +// Main loop + + while(1) { + // Checking if A/D convertion is done, and save the data in global_Pot_?? + if(GODONE==0) + { + global_Pot_Hi = ADRESH; + global_Pot_Lo = ADRESL; + GODONE = 0; + } + update_lcd(); } }