Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

RS232 search received text

Status
Not open for further replies.
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.
 

Attachments

  • eda rev1.rar
    77.3 KB · Views: 50

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.

This code work great
It only have one last problem
my weight is 82 kilogram but it display it 28 kilo gram on the LCD
it display all the numbers reversed
45 shows 54
23 shows 32
etc
how can I reverse display the value
 

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);
     }
}

 

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);
     }
}


When I try it in simulation it display nothing ! just "weight" word in the first line
 

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);
     }
}

 

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);
     }
}


Still display it in the same order
2.JPG
 

You have entered 5487412 between two = and it has displayed it correctly. What else do you want ?
 

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);
     }
}

 

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);
     }
}


It works, but now it shows the zeros that the first code wasn't showing
meaning =000250
previous shows 052
new shows 000250
how can I remove the zeros?

Also I'm trying to put the whole code in an if statment and a for loop so that when some one enter a coin or press abutton lcd shows 20 to 40 reading of the weight then display the latest reading and stop and the program doesn't work unless someone put anothet coin
 

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.

Tell how the below data has to be displayed.

00025805000
 
Last edited:

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.
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.

I'm ok with zeros appear at the beginning, but really need a way to trigger the measurement action
 

0025805000 has to be displayed as 5085200 ?

You can use this code but it is not working as expected. atoi() is not returning the correct value. If atoi() works then your problem is solved.

If you just give me two voltages appearing at the ADC input for 0 Kgs and 5 Kgs then I will be able to write a code for you. All you have to do is copy the same op amp interfacing circuit and interface with your PIC16F877A.


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;
            }            
     }
}

 
Last edited:
Then it is easy. I will write a code for you.

Confirm

=000012305= has to be displayed as 50321 ?
 
Then it is easy. I will write a code for you.

Confirm

=000012305= has to be displayed as 50321 ?

Yes it must display like that and the whole process must be triggered by switch for 30 second then display the last reading the wait for anothet click on the switch to start display again for 30 second
 

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;            
            }            
     }
}

 

Attachments

  • eda rev2.rar
    82.1 KB · Views: 39
  • weighing.png
    weighing.png
    47.5 KB · Views: 51
  • weighing2.png
    weighing2.png
    36.6 KB · Views: 49
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

After all the experience can you say that simulators can be a waste of time?
If the answer is yes then you have learnt important lesson.
 

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;            
            }            
     }
}


After testing the code it works fine in simulation but when I try to burn the code to PIC using my programmer it shows an error message

attached

3.JPG
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top