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