Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
Try the attached project. If you weigh 42 Kgs and the scale gives out 4200000 continuously then it doesn't cause problem because until the weigh value is changed it displays the same data repeatedly. If value changes then it displays new data.
Code C - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 // LCD module connections sbit LCD_RS at RB1_bit; sbit LCD_EN at RB0_bit; sbit LCD_D4 at RB4_bit; sbit LCD_D5 at RB5_bit; sbit LCD_D6 at RB6_bit; sbit LCD_D7 at RB7_bit; sbit LCD_RS_Direction at TRISB1_bit; sbit LCD_EN_Direction at TRISB0_bit; sbit LCD_D4_Direction at TRISB4_bit; sbit LCD_D5_Direction at TRISB5_bit; sbit LCD_D6_Direction at TRISB6_bit; sbit LCD_D7_Direction at TRISB7_bit; // End LCD module connections char Read = 0, myFlags = 0; char uart_rd[20]; unsigned int index = 0, value = 0; sbit Display at myFlags.B0; void interrupt() { if(OERR_bit) { OERR_bit = 0; CREN_bit = 0; CREN_bit = 1; } if(RCIF_bit) { if((RCREG != '=')) { uart_rd[index++] = RCREG; uart_rd[index] = '\0'; } else if(RCREG == '=') { index = 0; } RCIF_bit = 0; } } void main() { CMCON = 0x07; ADCON1 = 0x87; TRISA = 0xC0; TRISB = 0x00; TRISC = 0x80; TRISD = 0x00; PORTA = 0x00; PORTB = 0x00; PORTC = 0x00; PORTD = 0x00; LCD_Init(); // Initialize LCD LCD_Cmd(_LCD_CURSOR_OFF); // Cursor off LCD_Cmd(_LCD_CLEAR); // Clear display LCD_Out(1,6,"Weight:"); // Write text in first row UART1_Init(9615); Delay_ms(200); RCIE_bit = 1; PEIE_bit = 1; GIE_bit = 1; RCIF_bit = 0; while(1) { if(Display) { LCD_Out(2,1," "); LCD_Out(2,1,uart_rd); Display = 0; } //value = atoi(uart_rd); } }
Try this code. I hope it will solve your problem.
Code C - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 // LCD module connections sbit LCD_RS at RB1_bit; sbit LCD_EN at RB0_bit; sbit LCD_D4 at RB4_bit; sbit LCD_D5 at RB5_bit; sbit LCD_D6 at RB6_bit; sbit LCD_D7 at RB7_bit; sbit LCD_RS_Direction at TRISB1_bit; sbit LCD_EN_Direction at TRISB0_bit; sbit LCD_D4_Direction at TRISB4_bit; sbit LCD_D5_Direction at TRISB5_bit; sbit LCD_D6_Direction at TRISB6_bit; sbit LCD_D7_Direction at TRISB7_bit; // End LCD module connections char Read = 0, myFlags = 0; char uart_rd[20]; unsigned int index = 0, value = 0; sbit Display at myFlags.B0; void interrupt() { if(OERR_bit) { OERR_bit = 0; CREN_bit = 0; CREN_bit = 1; } if(RCIF_bit) { if((RCREG != '=')) { uart_rd[index++] = RCREG; uart_rd[index] = '\0'; } else if(RCREG == '=') { index = 0; } RCIF_bit = 0; } } void main() { CMCON = 0x07; ADCON1 = 0x87; TRISA = 0xC0; TRISB = 0x00; TRISC = 0x80; TRISD = 0x00; PORTA = 0x00; PORTB = 0x00; PORTC = 0x00; PORTD = 0x00; LCD_Init(); // Initialize LCD LCD_Cmd(_LCD_CURSOR_OFF); // Cursor off LCD_Cmd(_LCD_CLEAR); // Clear display LCD_Out(1,6,"Weight:"); // Write text in first row UART1_Init(9615); Delay_ms(200); RCIE_bit = 1; PEIE_bit = 1; GIE_bit = 1; RCIF_bit = 0; while(1) { if(Display) { LCD_Out(2,1," "); LCD_Out(2,1,uart_rd); Display = 0; } //value = atoi(uart_rd); } }
Code C - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 // LCD module connections sbit LCD_RS at RB1_bit; sbit LCD_EN at RB0_bit; sbit LCD_D4 at RB4_bit; sbit LCD_D5 at RB5_bit; sbit LCD_D6 at RB6_bit; sbit LCD_D7 at RB7_bit; sbit LCD_RS_Direction at TRISB1_bit; sbit LCD_EN_Direction at TRISB0_bit; sbit LCD_D4_Direction at TRISB4_bit; sbit LCD_D5_Direction at TRISB5_bit; sbit LCD_D6_Direction at TRISB6_bit; sbit LCD_D7_Direction at TRISB7_bit; // End LCD module connections char Read = 0, myFlags = 0; char uart_rd[20]; unsigned int index = 0, value = 0; sbit Display at myFlags.B0; void interrupt() { if(OERR_bit) { OERR_bit = 0; CREN_bit = 0; CREN_bit = 1; } if(RCIF_bit) { if((RCREG != '=')) { uart_rd[index++] = RCREG; uart_rd[index] = '\0'; } else if(RCREG == '=') { if(index > 0)Display = 1; index = 0; } RCIF_bit = 0; } } void main() { CMCON = 0x07; ADCON1 = 0x87; TRISA = 0xC0; TRISB = 0x00; TRISC = 0x80; TRISD = 0x00; PORTA = 0x00; PORTB = 0x00; PORTC = 0x00; PORTD = 0x00; LCD_Init(); // Initialize LCD LCD_Cmd(_LCD_CURSOR_OFF); // Cursor off LCD_Cmd(_LCD_CLEAR); // Clear display LCD_Out(1,5,"Weight:"); // Write text in first row UART1_Init(9615); Delay_ms(200); RCIE_bit = 1; PEIE_bit = 1; GIE_bit = 1; RCIF_bit = 0; while(1) { if(Display) { LCD_Out(2,1," "); LCD_Out(2,1,uart_rd); Display = 0; } //value = atoi(uart_rd); } }
There was a mistake in the code. I have fixed it and tested in Proteus. Try this.
Code C - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 // LCD module connections sbit LCD_RS at RB1_bit; sbit LCD_EN at RB0_bit; sbit LCD_D4 at RB4_bit; sbit LCD_D5 at RB5_bit; sbit LCD_D6 at RB6_bit; sbit LCD_D7 at RB7_bit; sbit LCD_RS_Direction at TRISB1_bit; sbit LCD_EN_Direction at TRISB0_bit; sbit LCD_D4_Direction at TRISB4_bit; sbit LCD_D5_Direction at TRISB5_bit; sbit LCD_D6_Direction at TRISB6_bit; sbit LCD_D7_Direction at TRISB7_bit; // End LCD module connections char Read = 0, myFlags = 0; char uart_rd[20]; unsigned int index = 0, value = 0; sbit Display at myFlags.B0; void interrupt() { if(OERR_bit) { OERR_bit = 0; CREN_bit = 0; CREN_bit = 1; } if(RCIF_bit) { if((RCREG != '=')) { uart_rd[index++] = RCREG; uart_rd[index] = '\0'; } else if(RCREG == '=') { if(index > 0)Display = 1; index = 0; } RCIF_bit = 0; } } void main() { CMCON = 0x07; ADCON1 = 0x87; TRISA = 0xC0; TRISB = 0x00; TRISC = 0x80; TRISD = 0x00; PORTA = 0x00; PORTB = 0x00; PORTC = 0x00; PORTD = 0x00; LCD_Init(); // Initialize LCD LCD_Cmd(_LCD_CURSOR_OFF); // Cursor off LCD_Cmd(_LCD_CLEAR); // Clear display LCD_Out(1,5,"Weight:"); // Write text in first row UART1_Init(9615); Delay_ms(200); RCIE_bit = 1; PEIE_bit = 1; GIE_bit = 1; RCIF_bit = 0; while(1) { if(Display) { LCD_Out(2,1," "); LCD_Out(2,1,uart_rd); Display = 0; } //value = atoi(uart_rd); } }
You have entered 5487412 between two = and it has displayed it correctly. What else do you want ?
Code C - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 // LCD module connections sbit LCD_RS at RB1_bit; sbit LCD_EN at RB0_bit; sbit LCD_D4 at RB4_bit; sbit LCD_D5 at RB5_bit; sbit LCD_D6 at RB6_bit; sbit LCD_D7 at RB7_bit; sbit LCD_RS_Direction at TRISB1_bit; sbit LCD_EN_Direction at TRISB0_bit; sbit LCD_D4_Direction at TRISB4_bit; sbit LCD_D5_Direction at TRISB5_bit; sbit LCD_D6_Direction at TRISB6_bit; sbit LCD_D7_Direction at TRISB7_bit; // End LCD module connections char Read = 0, myFlags = 0; char uart_rd[20], str[20]; unsigned int index = 0, value = 0; signed int i = 0, j = 0; sbit Display at myFlags.B0; void interrupt() { if(OERR_bit) { OERR_bit = 0; CREN_bit = 0; CREN_bit = 1; } if(RCIF_bit) { if((RCREG != '=')) { uart_rd[index++] = RCREG; uart_rd[index] = '\0'; } else if(RCREG == '=') { if(index > 0)Display = 1; index = 0; } RCIF_bit = 0; } } void main() { CMCON = 0x07; ADCON1 = 0x87; TRISA = 0xC0; TRISB = 0x00; TRISC = 0x80; TRISD = 0x00; PORTA = 0x00; PORTB = 0x00; PORTC = 0x00; PORTD = 0x00; LCD_Init(); // Initialize LCD LCD_Cmd(_LCD_CURSOR_OFF); // Cursor off LCD_Cmd(_LCD_CLEAR); // Clear display LCD_Out(1,5,"Weight:"); // Write text in first row UART1_Init(9615); Delay_ms(200); RCIE_bit = 1; PEIE_bit = 1; GIE_bit = 1; RCIF_bit = 0; while(1) { if(Display) { i = strlen(uart_rd); str[i] = '\0'; i--; j = 0; while(i >= 0) { str[j++] = uart_rd[i]; i--; } LCD_Out(2,1," "); LCD_Out(2,1,str); Display = 0; } //value = atoi(uart_rd); } }
Try this code then.
Code C - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 // LCD module connections sbit LCD_RS at RB1_bit; sbit LCD_EN at RB0_bit; sbit LCD_D4 at RB4_bit; sbit LCD_D5 at RB5_bit; sbit LCD_D6 at RB6_bit; sbit LCD_D7 at RB7_bit; sbit LCD_RS_Direction at TRISB1_bit; sbit LCD_EN_Direction at TRISB0_bit; sbit LCD_D4_Direction at TRISB4_bit; sbit LCD_D5_Direction at TRISB5_bit; sbit LCD_D6_Direction at TRISB6_bit; sbit LCD_D7_Direction at TRISB7_bit; // End LCD module connections char Read = 0, myFlags = 0; char uart_rd[20], str[20]; unsigned int index = 0, value = 0; signed int i = 0, j = 0; sbit Display at myFlags.B0; void interrupt() { if(OERR_bit) { OERR_bit = 0; CREN_bit = 0; CREN_bit = 1; } if(RCIF_bit) { if((RCREG != '=')) { uart_rd[index++] = RCREG; uart_rd[index] = '\0'; } else if(RCREG == '=') { if(index > 0)Display = 1; index = 0; } RCIF_bit = 0; } } void main() { CMCON = 0x07; ADCON1 = 0x87; TRISA = 0xC0; TRISB = 0x00; TRISC = 0x80; TRISD = 0x00; PORTA = 0x00; PORTB = 0x00; PORTC = 0x00; PORTD = 0x00; LCD_Init(); // Initialize LCD LCD_Cmd(_LCD_CURSOR_OFF); // Cursor off LCD_Cmd(_LCD_CLEAR); // Clear display LCD_Out(1,5,"Weight:"); // Write text in first row UART1_Init(9615); Delay_ms(200); RCIE_bit = 1; PEIE_bit = 1; GIE_bit = 1; RCIF_bit = 0; while(1) { if(Display) { i = strlen(uart_rd); str[i] = '\0'; i--; j = 0; while(i >= 0) { str[j++] = uart_rd[i]; i--; } LCD_Out(2,1," "); LCD_Out(2,1,str); Display = 0; } //value = atoi(uart_rd); } }
So there is no way to place the code in a loop and trigger it by a switch, I tried it my self but it didn't work and I've come so close to finish this, don't have enough time at this point to adjust my project direction and read after the op amp circuit.My advice is replace the board in the weighing scale with a new board which gives both LCD output and UART output. Just read the load cell values (after op amp circuit) and write a new code.
Code C - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 // LCD module connections sbit LCD_RS at RB1_bit; sbit LCD_EN at RB0_bit; sbit LCD_D4 at RB4_bit; sbit LCD_D5 at RB5_bit; sbit LCD_D6 at RB6_bit; sbit LCD_D7 at RB7_bit; sbit LCD_RS_Direction at TRISB1_bit; sbit LCD_EN_Direction at TRISB0_bit; sbit LCD_D4_Direction at TRISB4_bit; sbit LCD_D5_Direction at TRISB5_bit; sbit LCD_D6_Direction at TRISB6_bit; sbit LCD_D7_Direction at TRISB7_bit; // End LCD module connections char myFlags = 0; char uart_rd[20], str[20]; long index = 0, value = 0; signed int i = 0, j = 0; sbit Display at myFlags.B0; void interrupt() { if(OERR_bit) { OERR_bit = 0; CREN_bit = 0; CREN_bit = 1; } if(RCIF_bit) { if((RCREG != '=')) { uart_rd[index++] = RCREG; uart_rd[index] = '\0'; } else if(RCREG == '=') { if(index > 0)Display = 1; index = 0; } RCIF_bit = 0; } } void main() { CMCON = 0x07; ADCON1 = 0x87; TRISA = 0xC0; TRISB = 0x00; TRISC = 0x80; TRISD = 0x00; PORTA = 0x00; PORTB = 0x00; PORTC = 0x00; PORTD = 0x00; LCD_Init(); // Initialize LCD LCD_Cmd(_LCD_CURSOR_OFF); // Cursor off LCD_Cmd(_LCD_CLEAR); // Clear display LCD_Out(1,5,"Weight:"); // Write text in first row UART1_Init(9615); Delay_ms(200); RCIE_bit = 1; PEIE_bit = 1; GIE_bit = 1; RCIF_bit = 0; while(1) { if(Display) { i = strlen(uart_rd); str[i] = '\0'; i--; j = 0; while(i >= 0) { str[j++] = uart_rd[i]; i--; } value = atoi(str); LongToStr(value, str); Ltrim(str); LCD_Out(2,1," "); LCD_Out(2,1,str); Display = 0; } } }
No the number received from serial has the value at one end and the ZEROS at the other end so it starts with zeros and end with the number =00000123=00000045 etc0025805000 has to be displayed as 5085200 ?
Then it is easy. I will write a code for you.
Confirm
=000012305= has to be displayed as 50321 ?
Code C - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 // LCD module connections sbit LCD_RS at RB1_bit; sbit LCD_EN at RB0_bit; sbit LCD_D4 at RB4_bit; sbit LCD_D5 at RB5_bit; sbit LCD_D6 at RB6_bit; sbit LCD_D7 at RB7_bit; sbit LCD_RS_Direction at TRISB1_bit; sbit LCD_EN_Direction at TRISB0_bit; sbit LCD_D4_Direction at TRISB4_bit; sbit LCD_D5_Direction at TRISB5_bit; sbit LCD_D6_Direction at TRISB6_bit; sbit LCD_D7_Direction at TRISB7_bit; // End LCD module connections char myFlags = 0; char uart_rd[20], str[20], Read1 = 0, Read2 = 0; long index = 0, value = 0; signed int i = 0, j = 0; unsigned int counter = 0; sbit Display at myFlags.B0; sbit Process at myFlags.B1; //Timer1 //Prescaler 1:8; TMR1 Preload = 3036; Actual Interrupt Time : 500 ms //Place/Copy this part in declaration section void InitTimer1() { T1CON = 0x31; TMR1IF_bit = 0; TMR1H = 0x0B; TMR1L = 0xDC; TMR1IE_bit = 1; } void interrupt() { if(OERR_bit) { OERR_bit = 0; CREN_bit = 0; CREN_bit = 1; } if(RCIF_bit) { if((RCREG != '=')) { if(Read1 == 2) { uart_rd[index++] = RCREG; uart_rd[index] = '\0'; } else if(Read1 == 1) { if(RCREG != '0') { uart_rd[index++] = RCREG; uart_rd[index] = '\0'; Read1 = 2; } } } else if(RCREG == '=') { if(index > 0)Process = 1; index = 0; Read1 = 1; } RCIF_bit = 0; } if(TMR1IF_bit){ TMR1IF_bit = 0; TMR1H = 0x0B; TMR1L = 0xDC; //Enter your code here if(++counter == 60) { Display = 0; counter = 0; TMR1ON_bit = 0; } } } void main() { CMCON = 0x07; ADCON1 = 0x87; TRISA = 0xC0; TRISB = 0x00; TRISC = 0x81; TRISD = 0x00; PORTA = 0x00; PORTB = 0x00; PORTC = 0x00; PORTD = 0x00; LCD_Init(); // Initialize LCD LCD_Cmd(_LCD_CURSOR_OFF); // Cursor off LCD_Cmd(_LCD_CLEAR); // Clear display LCD_Out(1,5,"Weight:"); // Write text in first row UART1_Init(9615); Delay_ms(200); RCIE_bit = 1; PEIE_bit = 1; GIE_bit = 1; RCIF_bit = 0; while(1) { if(RC0_bit) { Delay_ms(50); while(RC0_bit)asm clrwdt; Display = 1; InitTimer1(); } if(Process) { i = strlen(uart_rd); str[i] = '\0'; i--; j = 0; while(i >= 0) { str[j++] = uart_rd[i]; i--; } Process = 0; } if(Display) { LCD_Out(2,1," "); LCD_Out(2,1,str); Display = 0; } } }
Thanks a lot, I tested this code using Proteus and hardware, in Proteus everything works fine, but when I turn to hardware since I receive continuous non stop feed of this format =000240=000090=000088= ...etc
Try attached code. I will post another project after adding button.
- - - Updated - - -
Try this code with new circuit.
Code C - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 // LCD module connections sbit LCD_RS at RB1_bit; sbit LCD_EN at RB0_bit; sbit LCD_D4 at RB4_bit; sbit LCD_D5 at RB5_bit; sbit LCD_D6 at RB6_bit; sbit LCD_D7 at RB7_bit; sbit LCD_RS_Direction at TRISB1_bit; sbit LCD_EN_Direction at TRISB0_bit; sbit LCD_D4_Direction at TRISB4_bit; sbit LCD_D5_Direction at TRISB5_bit; sbit LCD_D6_Direction at TRISB6_bit; sbit LCD_D7_Direction at TRISB7_bit; // End LCD module connections char myFlags = 0; char uart_rd[20], str[20], Read1 = 0, Read2 = 0; long index = 0, value = 0; signed int i = 0, j = 0; unsigned int counter = 0; sbit Display at myFlags.B0; sbit Process at myFlags.B1; //Timer1 //Prescaler 1:8; TMR1 Preload = 3036; Actual Interrupt Time : 500 ms //Place/Copy this part in declaration section void InitTimer1() { T1CON = 0x31; TMR1IF_bit = 0; TMR1H = 0x0B; TMR1L = 0xDC; TMR1IE_bit = 1; } void interrupt() { if(OERR_bit) { OERR_bit = 0; CREN_bit = 0; CREN_bit = 1; } if(RCIF_bit) { if((RCREG != '=')) { if(Read1 == 2) { uart_rd[index++] = RCREG; uart_rd[index] = '\0'; } else if(Read1 == 1) { if(RCREG != '0') { uart_rd[index++] = RCREG; uart_rd[index] = '\0'; Read1 = 2; } } } else if(RCREG == '=') { if(index > 0)Process = 1; index = 0; Read1 = 1; } RCIF_bit = 0; } if(TMR1IF_bit){ TMR1IF_bit = 0; TMR1H = 0x0B; TMR1L = 0xDC; //Enter your code here if(++counter == 60) { Display = 0; counter = 0; TMR1ON_bit = 0; } } } void main() { CMCON = 0x07; ADCON1 = 0x87; TRISA = 0xC0; TRISB = 0x00; TRISC = 0x81; TRISD = 0x00; PORTA = 0x00; PORTB = 0x00; PORTC = 0x00; PORTD = 0x00; LCD_Init(); // Initialize LCD LCD_Cmd(_LCD_CURSOR_OFF); // Cursor off LCD_Cmd(_LCD_CLEAR); // Clear display LCD_Out(1,5,"Weight:"); // Write text in first row UART1_Init(9615); Delay_ms(200); RCIE_bit = 1; PEIE_bit = 1; GIE_bit = 1; RCIF_bit = 0; while(1) { if(RC0_bit) { Delay_ms(50); while(RC0_bit)asm clrwdt; Display = 1; InitTimer1(); } if(Process) { i = strlen(uart_rd); str[i] = '\0'; i--; j = 0; while(i >= 0) { str[j++] = uart_rd[i]; i--; } Process = 0; } if(Display) { LCD_Out(2,1," "); LCD_Out(2,1,str); Display = 0; } } }