milan.rajik
Banned
This is untested code using Serial Interrupt for receiving 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 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 // LCD module connections sbit LCD_RS at RB4_bit; sbit LCD_EN at RB5_bit; sbit LCD_D4 at RB0_bit; sbit LCD_D5 at RB1_bit; sbit LCD_D6 at RB2_bit; sbit LCD_D7 at RB3_bit; sbit LCD_RS_Direction at TRISB4_bit; sbit LCD_EN_Direction at TRISB5_bit; sbit LCD_D4_Direction at TRISB0_bit; sbit LCD_D5_Direction at TRISB1_bit; sbit LCD_D6_Direction at TRISB2_bit; sbit LCD_D7_Direction at TRISB3_bit; // End LCD module connections char myFlags = 0; char uart_rd[50], buffer[20], str[17]; unsigned int index = 0, i = 0, j = 0, value = 0; sbit Read at myFlags.B0; sbit Convert at myFlags.B1; void interrupt() { if(OERR1_bit) { OERR1_bit = 0; CREN1_bit = 0; CREN1_bit = 1; } if(RC1IF_bit) { if(RC1REG == '=') { Read = 1; index = 0; } if(RC1REG == '0') { Read = 0; COnvert = 1; } if(Read) { uart_rd[index++] = RC1REG; } RC1IF_bit = 0; } } void main() { CM1CON0 = 0x00; CM2CON0 = 0x00; SLRCON = 0x00; ANSELA = 0x00; ANSELB = 0x00; ANSELC = 0x00; TRISA = 0xC0; TRISB = 0x00; TRISC = 0xC0; PORTA = 0x00; PORTB = 0x00; PORTC = 0x00; LATA = 0x00; LATB = 0x00; LATC = 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(100); RC1IE_bit = 1; PEIE_bit = 1; GIE_bit = 1; RC1IF_bit = 0; while(1) { if(Convert) { i = 0; j = 0; while(uart_rd[i] != '0') { buffer[j++] = uart_rd[i++]; } value = 0; for(i = 0; i < j; i++, j--) { value += (buffer[i] - 48) * 10^(j - 1); } IntToStr(value, str); Ltrim(str); strcat(str, " Kgs"); Lcd_Out(2,6,str); Convert = 0; } } }