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.

Reading 4 - 20 mA on LCD using PIC16F876A

Status
Not open for further replies.
I now remember why i quit using mikroc. The newer 8.6 pro is great but the older was like a C of it's own
 
Hi Eric,
If you remember:
You could remove the bottom end +1V offset in the program, give you a Span of 4V.
I would do it in software, its cheaper and 4V is good enough.:)

I spare your suggestion until I got the circuit working, now I would like to know how to do it.

Thank you
 
Last edited:
This should work for you
Code:
 char message1[] = "ADC Value= ";
 
 char *value = "0000";
 
 unsigned int ADC_Value;
 
void main() {
  ADCON0 = 0b11000000;
  ADCON1 = 0b10001111;
  TRISA  = 0xFF;              // PORTA is input
  TRISB  = 0;                 // PORTB is output
  Lcd_Init(&PORTB);                 // Initialize LCD
 
 
  do {
       adc_value = ADC_Read(0);
 
   value[0] = adc_value/1000 + 48; // Add 48 to get character value
 
   value[1] = (adc_value/100)%10 + 48;
 
   value[2] = (adc_value/10)%10 + 48;
 
   value[3] = adc_value%10 + 48;
 
   Lcd_Out(1,11,value);
 
   Delay_ms(2000);
  } while(1);
}


Hi be80be,

I let myself to play with your code as per your recommendations :).

I tried to change the range 0 to 5 volts indication into 0 to 100 %, I did part of that by adding '.' and % sign but failed to change the range.

Here is Your/my code:

Code:
 char *value = "0000";
 unsigned int ADC_Value;
void main() {
  ADCON0 = 0b11000000;
  ADCON1 = 0b10001111;
  TRISA  = 0xFF;              // PORTA is input
  TRISB  = 0;                 // PORTB is output
  Lcd_Init(&PORTB);           // Initialize LCD
  do {
       adc_value = ADC_Read(0);
   value[0] = adc_value/1000 + 48; // Add 48 to get character value
   value[1] = (adc_value/100)%10 + 48;
   
   value[2] = '.';
   value[3] = (adc_value/10)%10 + 48;
   value[4] = adc_value%10 + 48;
   LCD_RETURN_HOME;
   
   Lcd_Cmd(Lcd_CLEAR);       // Clear display
   Lcd_Out_Cp(" VALVE POSITION ");
   Lcd_Out(2,5,value);
   
   Lcd_Out_Cp("%");
   
   Lcd_Cmd(Lcd_CURSOR_OFF);  // Turn cursor off
   Delay_ms(2000);
  } while(1);
}
 
The code gives a value of 0 to 1023 you have to change it to read volts
 
Thank you be80be, I've managed to change the reading into 0-100 % range.
I'll use this as Motoroized Valve Opening Indicator. Now I'll try to raise the zero reference from 0v into 1v. Eric told me once it can be done in the software, or shall I make the hardwaew Ref- = 1v instead of 0v ? which will give me range of 1 to 5volts.

my latest resutl is attached
 

Attachments

  • OS6.JPG
    OS6.JPG
    173.2 KB · Views: 287
Change the part

Code:
adc_value = ADC_Read(0);

To
Code:
adc_value = ((ADC.Read(0) + 1) * 500 / 1024);
 
It works fine using OS simulator ( see attachment in post #25 ) but in real circuit, it shows just black blocks filling the first raw of the LCD. Tried to play with the delay but not succeded. BTW, all the fuses desabled excpt for WRT which set to WRT_HALF and the oscillator set to HS.

and here is the final code:

Code:
char *value = "0000";
 unsigned int ADC_Value;
void main() {
  ADCON0 = 0b11000000;
  ADCON1 = 0b10001111;
  TRISA  = 0xFF;              // PORTA is input
  TRISB  = 0;                 // PORTB is output
  Lcd_Init(&PORTB);           // Initialize LCD
  Lcd_Cmd(Lcd_CLEAR);         // Clear display
  Lcd_Cmd(Lcd_CURSOR_OFF);    // Turn cursor off
  do {
       adc_value = ADC_Read(0);
   value[0] = adc_value/100 + 48; // Add 48 to get character value
   value[1] = (adc_value/10)%10 + 48;
   value[2] = '.';
   value[3] = (adc_value/1)%10 + 48;
   value[4] = adc_value%10 + 48;
   Lcd_Out_Cp(" VALVE POSITION ");
   Lcd_Out(2,5,value);
   Lcd_Out_Cp("%");
   Delay_ms(2000);
  } while(1);
    }
 
The problem was a Hardware issue. The R/W has to be connected to ground, the -Vref (pin#4) has to be connected to the voltage bottom Ref ( in my case Gnd ) and +VRef ( pin# 5) has to be connected to Voltage High Ref. ( In my case 5V ), everything went fine.

I'll post some pictures as soon as I BlueTooth them from my mobile into PC.

Thank you be80be, Eric for your patient and help.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top