--- trunk/Embedded/main.lst 2007/12/03 14:40:44 138 +++ trunk/Embedded/main.lst 2007/12/03 17:19:35 139 @@ -7,157 +7,183 @@ 7: 8: #define LCD_LENGTH 16 9: #define LCD_ROWS 2 - 10: + 10: #define SEND_BUFFER 128 11: - 12: unsigned char global_Pot_Hi, global_Pot_Lo; - 13: unsigned char global_LCD_Buffer[LCD_ROWS][LCD_LENGTH]; - 14: unsigned char global_serial_data; - 15: unsigned char global_serial_recieve_buffer[LCD_LENGTH]; - 16: bit global_recieve_done = 0; - 17: int global_serial_byte_counter = 0; - 18: - 19: void serial_recieved(void); - 20: - 21: // Nicked from H7 - 22: void ad_init(void) - 23: { - 24: // AD Conversion clock - 25: ADCS0 = 0; - 26: ADCS1 = 0; - 27: ADCS2 = 0; - 28: - 29: //Select AN0/RA0 for AD source - 30: // In this (000) setup, it's only RA0/AN0 that does ad convertion. - 31: CHS0=0; - 32: CHS1=0; - 33: CHS2=0; - 34: - 35: //Only AN0 is selected for AD and with Vdd/Vss as limits - 36: PCFG0=0; - 37: PCFG1=1; - 38: PCFG2=1; - 39: PCFG3=1; - 40: - 41: //Result is left justified - 42: ADFM=0; + 12: + 13: unsigned char global_Pot_Hi, global_Pot_Lo; + 14: unsigned char global_LCD_Buffer[LCD_ROWS][LCD_LENGTH]; + 15: unsigned char global_serial_send[SEND_BUFFER]; + 16: unsigned char global_serial_recieve_buffer[LCD_LENGTH]; + 17: bit global_recieve_done = 0; + 18: int global_serial_byte_counter = 0; + 19: + 20: void serial_recieved(void); + 21: void serial_send(void); + 22: void update_lcd(void); + 23: + 24: // Nicked from H7 + 25: void ad_init(void) + 26: { + 27: // AD Conversion clock + 28: ADCS0 = 0; + 29: ADCS1 = 0; + 30: ADCS2 = 0; + 31: + 32: //Select AN0/RA0 for AD source + 33: // In this (000) setup, it's only RA0/AN0 that does ad convertion. + 34: CHS0=0; + 35: CHS1=0; + 36: CHS2=0; + 37: + 38: //Only AN0 is selected for AD and with Vdd/Vss as limits + 39: PCFG0=0; + 40: PCFG1=1; + 41: PCFG2=1; + 42: PCFG3=1; 43: - 44: //Fire up for A/D converter module - 45: ADON=1; - 46: } - 47: - 48: void rs232_init(void) - 49: { - 50: SPEN = 0; // Serial Port Enable Bit... 0 = disabled - 51: TRISC6 = 0; - 52: TRISC7 = 1; - 53: - 54: SPBRG = 207; // 1200 baud rate... 25 = 9600 - 55: // x = (Fosc / (16*[baud rate]) )-1 - 56: TXSTA = 0x24; // Enables BRGH and TXEN inthe TXSTA register - 57: RCSTA = 0x90; // 0x90 enables SPEN and CREN in the RCSTA register - 58: } - 59: - 60: void interrupt_init(void) - 61: { - 62: // Assumes that all interrupts default is 0 - 63: PEIE = 1; - 64: GIE = 1; - 65: RCIE = 1; // Recieve interrupt enable. - 66: IPEN = 0; // Nfo interrupt priority - 67: TXIE = 0; // Serial interrupt enabled - 68: } - 69: - 70: void pic18_io_init(void) - 71: { - 72: TRISA0 = 1; // analog input - 73: TRISB1 = 1; // TRISB1-4 Digital input - 74: TRISB2 = 1; - 75: TRISB3 = 1; - 76: TRISB4 = 1; - 77: } - 78: - 79: - 80: - 81: void interrupt interrupt_handler(void) - 82: { - 83: // Finds out what interrupt have been trigged, and starts the respective function. - 84: if(RCIF == 1) // Serial recieve interrupt - 85: { - 86: serial_recieved(); - 87: RCIF = 0; - 88: } - 89: } - 90: - 91: - 92: - 93: void serial_send(void) - 94: { - 95: int i; - 96: char tosend[3]; - 97: char data; - 98: sprintf(tosend,"%s", "at\r"); - 99: for(i = 0; i < 3; i++) - 100: { - 101: data = tosend[i]; - 102: TXREG = data; - 103: while(TRMT==0) - 104: DelayMs(1000); - 105: } - 106: } - 107: - 108: void serial_recieved(void) - 109: { - 110: char data, saved_data[LCD_LENGTH]; - 111: - 112: data = RCREG; - 113: - 114: global_serial_recieve_buffer[global_serial_byte_counter] = data; - 115: if(data == '\r') - 116: { - 117: global_recieve_done = 1; - 118: global_serial_byte_counter = 0; - 119: } - 120: else - 121: { - 122: global_serial_byte_counter++; - 123: } - 124: - 125: } - 126: - 127: void main() - 128: { - 129: ///////////////////////////////////////////// - 130: // Running Init's + 44: //Result is left justified + 45: ADFM=0; + 46: + 47: //Fire up for A/D converter module + 48: ADON=1; + 49: } + 50: + 51: void rs232_init(void) + 52: { + 53: SPEN = 0; // Serial Port Enable Bit... 0 = disabled + 54: TRISC6 = 0; + 55: TRISC7 = 1; + 56: + 57: SPBRG = 207; // 1200 baud rate... 25 = 9600 + 58: // x = (Fosc / (16*[baud rate]) )-1 + 59: TXSTA = 0x24; // Enables BRGH and TXEN inthe TXSTA register + 60: RCSTA = 0x90; // 0x90 enables SPEN and CREN in the RCSTA register + 61: } + 62: + 63: void interrupt_init(void) + 64: { + 65: // Assumes that all interrupts default is 0 + 66: PEIE = 1; + 67: GIE = 1; + 68: RCIE = 1; // Recieve interrupt enable. + 69: IPEN = 0; // Nfo interrupt priority + 70: TXIE = 0; // Serial interrupt enabled + 71: } + 72: + 73: void pic18_io_init(void) + 74: { + 75: TRISA0 = 1; // analog input + 76: TRISB1 = 1; // TRISB1-4 Digital input + 77: TRISB2 = 1; + 78: TRISB3 = 1; + 79: TRISB4 = 1; + 80: } + 81: + 82: void sms_init(void) + 83: { + 84: int i = 1; + 85: sprintf(global_serial_send,"%s", "at+cpin=8043\r"); + 86: serial_send(); + 87: DelaySek(60); + 88: + 89: update_lcd(); + 90: DelaySek(5); + 91: + 92: sprintf(global_serial_send,"%s%s", "at+cmgs=","\"22337617\"\r"); + 93: serial_send(); + 94: DelayMs(5000); + 95: + 96: sprintf(global_serial_send,"%s%d%c","Dette er test nr: ", i, 0x1A); + 97: serial_send(); + 98: DelayMs(5000); + 99: i++; + 100: + 101: } + 102: + 103: void interrupt interrupt_handler(void) + 104: { + 105: // Finds out what interrupt have been trigged, and starts the respective function. + 106: if(RCIF == 1) // Serial recieve interrupt + 107: { + 108: serial_recieved(); + 109: RCIF = 0; + 110: } + 111: } + 112: + 113: + 114: + 115: void serial_send(void) + 116: { + 117: int i; + 118: // char tosend[3]; + 119: char data; + 120: // sprintf(tosend,"%s", "at\r"); + 121: for(i = 0; i < SEND_BUFFER; i++) + 122: { + 123: data = global_serial_send[i]; + 124: if( data == '\r') + 125: i = (SEND_BUFFER - 1); + 126: TXREG = data; + 127: while(TRMT==0) ; + 128: DelayMs(1000); + 129: } + 130: } 131: - 132: // Running init for various components. - 133: //AD_init(); - 134: ad_init(); - 135: rs232_init(); - 136: pic18_io_init(); - 137: lcd_init(0); - 138: interrupt_init(); - 139: - 140: ///////////////////////////////////////////// - 141: // Main loop - 142: - 143: while(1) - 144: { - 145: DelayMs(3000); - 146: serial_send(); - 147: // Checking if A/D convertion is done, and save the data in global_Pot_?? - 148: if(GODONE==0) - 149: { - 150: global_Pot_Hi = ADRESH; - 151: global_Pot_Lo = ADRESL; - 152: GODONE = 1; - 153: } - 154: - 155: if( global_recieve_done == 1 ) - 156: { - 157: lcd_clear(); - 158: lcd_goto(0x00); - 159: lcd_puts(global_serial_recieve_buffer); - 160: } - 161: //update_lcd(); - 162: } - 163: } + 132: void serial_recieved(void) + 133: { + 134: char data, saved_data[LCD_LENGTH]; + 135: + 136: data = RCREG; + 137: + 138: global_serial_recieve_buffer[global_serial_byte_counter] = data; + 139: if(data == '\r') + 140: { + 141: global_recieve_done = 1; + 142: global_serial_byte_counter = 0; + 143: } + 144: else + 145: { + 146: global_serial_byte_counter++; + 147: } + 148: + 149: } + 150: void update_lcd(void) + 151: { + 152: if( global_recieve_done == 1 ) + 153: { + 154: lcd_clear(); + 155: lcd_goto(0x00); + 156: lcd_puts(global_serial_recieve_buffer); + 157: global_recieve_done = 0; + 158: } + 159: } + 160: + 161: void main() + 162: { + 163: ///////////////////////////////////////////// + 164: // Running Init's + 165: + 166: // Running init for various components. + 167: //AD_init(); + 168: ad_init(); + 169: rs232_init(); + 170: pic18_io_init(); + 171: lcd_init(0); + 172: lcd_clear(); + 173: interrupt_init(); + 174: sms_init(); + 175: ///////////////////////////////////////////// + 176: // Main loop + 177: + 178: while(1) + 179: { + 180: // Checking if A/D convertion is done, and save the data in global_Pot_?? + 181: if(GODONE==0) + 182: { + 183: global_Pot_Hi = ADRESH; + 184: global_Pot_Lo = ADRESL; + 185: GODONE = 1; + 186: } + 187: update_lcd(); + 188: } + 189: }