--- trunk/Embedded/main.lst 2007/11/28 17:00:45 82 +++ trunk/Embedded/main.lst 2007/11/30 13:47:05 109 @@ -1,56 +1,144 @@ 1: #include 2: #include 3: #include - 4: - 5: #include "lcd.h" + 4: #include "lcd.h" + 5: // Delay.h is included inside lcd.c 6: - 7: - 8: void rs232_init(void) - 9: { - 10: SPEN = 0; // Serial Port Enable Bit... 0 = disabled - 11: TRISC6 = 0; - 12: TRISC7 = 1; - 13: SYNC = 0; // SYNC switches between async(0) and sync(1) mode. - 14: SPBRG = 25; - 15: TXSTA = 0x24; - 16: RCSTA = 0x90; - 17: SPEN = 1; - 18: } - 19: - 20: void interrupt_init(void) + 7: #define LCD_LENGTH 16 + 8: #define LCD_ROWS 2 + 9: + 10: + 11: 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; + 17: } + 18: */ + 19: // Nicked from H7 + 20: void ad_init(void) 21: { - 22: // Assumes that all interrupts default is 0 - 23: PEIE = 1; - 24: GIE = 1; - 25: RCIE = 1; - 26: } - 27: - 28: void pic18_io_init(void) - 29: { - 30: TRISA0 = 1; - 31: TRISB1 = 1; - 32: TRISB2 = 1; - 33: TRISB3 = 1; - 34: TRISB4 = 1; - 35: } - 36: - 37: void interrupt_recieve_handler(void) - 38: { - 39: // Handle recieve inputs... - 40: } - 41: - 42: void interrupt interrupt_handler(void) - 43: { - 44: if(RCIF == 1) - 45: { - 46: interrupt_recieve_handler(); - 47: RCIF = 0; - 48: } - 49: } - 50: - 51: - 52: void main() - 53: { - 54: rs232_init(); - 55: pic18_io_init(); - 56: } + 22: // AD Conversion clock + 23: ADCS0 = 0; + 24: ADCS1 = 0; + 25: ADCS2 = 0; + 26: + 27: //Select AN0/RA0 for AD source + 28: CHS0=0; + 29: CHS1=0; + 30: CHS2=0; + 31: + 32: //Only AN0 is selected for AD and with Vdd/Vss as limits + 33: PCFG0=0; + 34: PCFG1=1; + 35: PCFG2=1; + 36: PCFG3=1; + 37: + 38: //Result is right justified + 39: ADFM=1; + 40: + 41: //Fire up for A/D converter module + 42: ADON=1; + 43: } + 44: + 45: void rs232_init(void) + 46: { + 47: SPEN = 0; // Serial Port Enable Bit... 0 = disabled + 48: TRISC6 = 0; + 49: TRISC7 = 1; + 50: SYNC = 0; // SYNC switches between async(0) and sync(1) mode. + 51: SPBRG = 25; + 52: TXSTA = 0x24; + 53: RCSTA = 0x90; + 54: SPEN = 1; + 55: } + 56: + 57: void interrupt_init(void) + 58: { + 59: // Assumes that all interrupts default is 0 + 60: PEIE = 1; + 61: GIE = 1; + 62: RCIE = 1; + 63: } + 64: + 65: void pic18_io_init(void) + 66: { + 67: TRISA0 = 1; // analog input + 68: TRISB1 = 1; // TRISB1-4 Digital input + 69: TRISB2 = 1; + 70: TRISB3 = 1; + 71: TRISB4 = 1; + 72: } + 73: + 74: void interrupt_recieve_handler(void) + 75: { + 76: // Handle recieve inputs... + 77: } + 78: + 79: void interrupt interrupt_handler(void) + 80: { + 81: // Finds out what interrupt have been trigged, and starts the respective function. + 82: if(RCIF == 1) + 83: { + 84: interrupt_recieve_handler(); + 85: RCIF = 0; + 86: } + 87: } + 88: + 89: void update_lcd(void) + 90: { + 91: int i = 0, horizontal = 0, vertical = 0; + 92: char alfa[2][LCD_LENGTH]; + 93: + 94: + 95: static char current_row = 0; + 96: static char current_char = 0; + 97: char toLCD0[LCD_LENGTH], toLCD1[LCD_LENGTH]; + 98: char B1[16]; + 99: lcd_goto(0x00); + 100: sprintf(toLCD0, "%s", "Ejdesgaard"); + 101: if(RB1) + 102: { + 103: sprintf(B1, "%s", "True"); + 104: } + 105: else + 106: { + 107: sprintf(B1, "%s", "False"); + 108: } + 109: lcd_puts(B1); + 110: + 111: lcd_goto(0x40); + 112: // sprintf(toLCD1, "%s", "Test"); + 113: lcd_puts("Test1"); + 114: + 115: } + 116: + 117: void main() + 118: { + 119: ///////////////////////////////////////////// + 120: // Running Init's + 121: + 122: // Running init for various components. + 123: //AD_init(); + 124: ad_init(); + 125: rs232_init(); + 126: pic18_io_init(); + 127: lcd_init(0); + 128: + 129: ///////////////////////////////////////////// + 130: // Main loop + 131: + 132: while(1) + 133: { + 134: // Checking if A/D convertion is done, and save the data in global_Pot_?? + 135: if(GODONE==0) + 136: { + 137: global_Pot_Hi = ADRESH; + 138: global_Pot_Lo = ADRESL; + 139: GODONE = 0; + 140: } + 141: + 142: update_lcd(); + 143: } + 144: }