// Monitor.C // // This program reads the serial port at 9600 baus // and displays the data on the LCD display // Global Variables unsigned char MSG0[21] = "Network.C "; unsigned char MSG1[21] = "9600 Baud "; unsigned char M; // byte M of message unsigned char TEMP; // temp data from SCI port unsigned char i; unsigned char FLAG; // Subroutine Declarations #include // Subroutines #include "lcd_portd.c" // High-priority service void interrupt IntServe(void) { if (RCIF) { TEMP = RCREG; TXREG = TEMP; if (TEMP > 20) MSG0[M++] = TEMP; if (M > 21) M = 21; if (TEMP == 13){ FLAG = 1; for (i=M+1; i<21; i++) MSG1[i] = ' '; for (i=0; i<20; i++) { MSG1[i] = MSG0[i]; MSG0[i] = ' '; } M = 0; } RCIF = 0; } } unsigned int A2D_Read(unsigned char c) { unsigned int result; unsigned char i; c = c & 0x0F; ADCON0 = (c << 2) + 0x01; // set Channel Select for (i=0; i<20; i++); // wait 2.4us (approx) GODONE = 1; // start the A/D conversion while(GODONE); // wait until complete (approx 8us) return(ADRES); } // Main Routine void main(void) { unsigned int DATA; unsigned int i, j; unsigned int ID, T, N, VOLT; TRISA = 0; TRISB = 0; TRISC = 0; TRISD = 0; TRISE = 0; ADCON1 = 0x0F; LCD_Init(); // initialize the LCD LCD_Move(0,0); for (i=0; i<20; i++) LCD_Write(MSG0[i]); LCD_Move(1,0); for (i=0; i<20; i++) LCD_Write(MSG1[i]); LCD_Inst(0x01); // Initialize Serial Port to 9600 baud TRISC = TRISC | 0xC0; TXIE = 0; RCIE = 1; BRGH = 1; BRG16 = 1; SYNC = 0; SPBRG = 255; SPBRGH = 0; TXSTA = 0x22; RCSTA = 0x90; PEIE = 1; // Initialize the A/D port TRISA = 0xFF; TRISE = 0x0F; ADCON2 = 0x85; ADCON1 = 0x07; ADCON0 = 0x01; // Turn on all interrupts GIE = 1; //S01T100N050 // display 000 to 999 while(1) { LCD_Move(0,0); for(i=0; i<16; i++) LCD_Write(MSG0[i]); LCD_Move(1,0); LCD_Out(ID, 3, 0); LCD_Move(1,5); LCD_Out(T, 3, 0); LCD_Move(1,10); LCD_Out(N, 3, 0); if(FLAG) { if(MSG1[0] == 'T') { T = ( MSG1[1] - 48) * 100 + ( MSG1[2] - 48) * 10 + ( MSG1[3] - 48) * 1; } if(MSG1[0] == 'N') { N = ( MSG1[1] - 48) * 100 + ( MSG1[2] - 48) * 10 + ( MSG1[3] - 48) * 1; } if(MSG1[0] == 'S') { ID = ( MSG1[1] - 48) * 100 + ( MSG1[2] - 48) * 10 + ( MSG1[3] - 48) * 1; } if(MSG1[0] == 'G') { if(ID == 1) { for(i=0; i