#include #include #include #include "lcd.h" // Delay.h is included inside lcd.c #define LCD_LENGTH 16 #define LCD_ROWS 2 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 left justified ADFM=0; //Fire up for A/D converter module ADON=1; } void rs232_init(void) { SPEN = 0; // Serial Port Enable Bit... 0 = disabled TRISC6 = 0; TRISC7 = 1; SYNC = 0; // SYNC switches between async(0) and sync(1) mode. SPBRG = 25; TXSTA = 0x24; RCSTA = 0x90; SPEN = 1; } void interrupt_init(void) { // Assumes that all interrupts default is 0 PEIE = 1; GIE = 1; RCIE = 1; } void pic18_io_init(void) { TRISA0 = 1; // analog input TRISB1 = 1; // TRISB1-4 Digital input TRISB2 = 1; TRISB3 = 1; TRISB4 = 1; } void interrupt_recieve_handler(void) { // Handle recieve inputs... } void interrupt interrupt_handler(void) { // Finds out what interrupt have been trigged, and starts the respective function. if(RCIF == 1) { interrupt_recieve_handler(); RCIF = 0; } } void update_lcd(void) { char toLCD0[LCD_LENGTH], toLCD1[LCD_LENGTH]; char B1[LCD_LENGTH]; char sprintF[LCD_LENGTH]; 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(sprintF,"%08d%08d", global_Pot_Hi, global_Pot_Lo); lcd_puts(sprintF); } void main() { ///////////////////////////////////////////// // Running Init's // Running init for various components. //AD_init(); ad_init(); rs232_init(); pic18_io_init(); 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 = 1; } update_lcd(); } }