Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

can anyone good on mikroc can help me?

Status
Not open for further replies.

ala khemiri

New Member
have a a Project that measures the voltage from a 3-phase lines and Display it on LCD using PIC16F877A.

I wrote the code in the mikroc language; the problem is that the LCD shows a lot of wrong characters.

this are the Project code `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;

void main() { int i,v10,v20,v30; float v11,v21,v31,max1,max2,max3 ; float v1[15],v2[15],v3[15]; char T1[3],T2[3],T3[3];

PORTA = 0xff;

LCD_Init (); // Initialize LCD ADC_Init (); LCD_Cmd(_LCD_CURSOR_OFF);// Clear display LCD_Cmd (_LCD_CLEAR) ; // Cursor off LCD_Out (1, 3, "voltmetre"); delay_ms (500); for(;;) {

for (i=0 ; i<15 ; i++) { v10= ADC_Read (0); delay_us(500); v11=0.0048*v10; v11=75*v11 ; v1=v11;

} max1=v1[0]; for (i=0;i<15;i++) {if (max1

// 2eme phase

for (i=0 ; i<15 ; i++) { v20= ADC_Read (1); delay_us(500); v21=0.0048*v20; v21=75*v21 ; v2=v21;

} max2=v2[0]; for (i=0;i<15;i++) {if (max2

//3eme phase

for (i=0 ; i<15 ; i++) { v30= ADC_Read (2); delay_us(10); v31=0.0048*v30; v31=75*v31 ; v3=v31;

} max3=v3[0]; for (i=0;i<15;i++) {if (max3

LCD_out(2,1,"v1="); LCD_out_cp(T1); LCD_chr_cp('v'); delay_ms(1000);

LCD_out(3,1,"v2="); LCD_out_cp(T2); LCD_chr_cp('v'); delay_ms(1000);

LCD_out(4,1,"v3="); LCD_out_cp(T3); LCD_chr_cp('v'); delay_ms(1000);

LCD_Cmd(_LCD_CURSOR_OFF); LCD_Cmd (_LCD_CLEAR) ; } }`

this is the LCD problem
bskoyK5
https://imgur.com/bskoyK5
 
I tried to follow it .. got as far as the attached ...

S
 

Attachments

  • new 1.c
    1.5 KB · Views: 335
C:
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;

void main()
 {
 
 int i,v10,v20,v30; float v11,v21,v31,max1,max2,max3 ;
 float v1[15],v2[15],v3[15];
 char T1[3],T2[3],T3[3];
PORTA = 0xff;
LCD_Init (); // Initialize LCD ADC_Init ();
LCD_Cmd(_LCD_CURSOR_OFF);//
Clear display LCD_Cmd (_LCD_CLEAR) ; //
Cursor off LCD_Out (1, 3, "voltmetre");
delay_ms (500);
for(; {
for (i=0 ; i<15 ; i++) { v10= ADC_Read (0);
delay_us(500);
v11=0.0048*v10;
v11=75*v11 ;
v1=v11;
}
max1=v1[0]; for (i=0;i<15;i++) {if (max1
// 2eme phase
for (i=0 ; i<15 ;
i++) { v20= ADC_Read (1);
delay_us(500);
v21=0.0048*v20;
v21=75*v21 ;
v2=v21;
}
max2=v2[0];
for (i=0;i<15;i++) {if (max2
//3eme phase
for (i=0 ; i<15 ;
i++) { v30= ADC_Read (2);
delay_us(10);
v31=0.0048*v30;
v31=75*v31 ;
v3=v31;
}
max3=v3[0];
for (i=0;i<15;i++) {if (max3
LCD_out(2,1,"v1=");
LCD_out_cp(T1);
LCD_chr_cp('v');
 delay_ms(1000);
LCD_out(3,1,"v2=");
LCD_out_cp(T2);
LCD_chr_cp('v');
delay_ms(1000);
LCD_out(4,1,"v3=");
LCD_out_cp(T3);
LCD_chr_cp('v');
delay_ms(1000);
LCD_Cmd(_LCD_CURSOR_OFF);
LCD_Cmd (_LCD_CLEAR) ;
 }
 }
 
After a bit of deciphering I found that..

Code:
for (i = 0; i < 15; i++)
   {
     if (max3)
     {
       LCD_out(2, 1, "v1=");
       LCD_out_cp(T1);
       LCD_chr_cp('v');
       delay_ms(1000);

       LCD_out(3, 1, "v2=");
       LCD_out_cp(T2);
       LCD_chr_cp('v');
       delay_ms(1000);

       LCD_out(4, 1, "v3=");
       LCD_out_cp(T3);
       LCD_chr_cp('v');
       delay_ms(1000);

       LCD_Cmd(_LCD_CURSOR_OFF);
       LCD_Cmd (_LCD_CLEAR);
     }
   }

..the char arrays T1, T2 and T3 are initialised, but they are never written to!
If you want to print the maximum value to the screen, you need to edit some previous code...
Code:
    for (i = 0 ; i < 15 ; i++)
    {
      v10 = ADC_Read(0);
      delay_us(500);
      v11 = 0.0048 * v10;
      v11 = 75 * v11 ;
      v1 = v11;
    }

    max1=v1[0];
    // Insert something like this below
    sprintf(T1, "%.1f", max1); //Float to char array

It also looks like your max voltage routines could be wrong too.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top