View previous topic :: View next topic |
Author |
Message |
Abidi
Joined: 12 May 2014 Posts: 6
|
ADC Pic18f452 |
Posted: Mon May 12, 2014 3:04 am |
|
|
Hello everybody
I need a program (PIC C) to display on LCD a current value got from a card of measurement, using pic 18f452. |
|
|
ezflyr
Joined: 25 Oct 2010 Posts: 1019 Location: Tewksbury, MA
|
|
Posted: Mon May 12, 2014 6:44 am |
|
|
Hi,
Here is a program for a different PIC, but it will give you the idea. This program will print the A/D results to your PC.
Code: |
#include <16F877.H>
#device adc=10
#fuses XT, NOWDT, NOPROTECT, BROWNOUT, PUT, NOLVP
#use delay(clock=4000000)
//#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, ERRORS)
//============================
void main()
{
int16 adc_value;
float volts;
setup_adc_ports(AN0);
setup_adc(ADC_CLOCK_DIV_8);
set_adc_channel(0);
delay_us(20);
while(1)
{
adc_value = read_adc();
volts = (float)(adc_value * 5)/1023.0;
printf("%3.2f", volts);
delay_ms(500);
}
}
|
This should be good !
John |
|
|
Abidi
Joined: 12 May 2014 Posts: 6
|
|
Posted: Mon May 12, 2014 2:08 pm |
|
|
I want to display the value appeared at Voltmetre on LCD after every modification of resistance value. the probleme is that value displayed is incorrect.
Thank you for your help |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19587
|
|
Posted: Mon May 12, 2014 2:19 pm |
|
|
What sort of resistance?.
The PIC requires quite a low impedance drive. More than a very few KR, and you won't get reasonable voltages.
Remember also the accuracy of your readings is dependent on the accuracy of your reference (commonly the supply rail). Unless this is accurate and stable, the readings will be in error.
Are you remembering to use an int16?. |
|
|
Mike Walne
Joined: 19 Feb 2004 Posts: 1785 Location: Boston Spa UK
|
|
Posted: Mon May 12, 2014 2:22 pm |
|
|
Abidi wrote: | I want to display the value appeared at Voltmetre on LCD after every modification of resistance value. the probleme is that value displayed is incorrect.
Thank you for your help |
Please explain.
1) What you expect to see.
2) What you actually see.
Mike |
|
|
Abidi
Joined: 12 May 2014 Posts: 6
|
|
Posted: Mon May 12, 2014 3:04 pm |
|
|
I can not find how I can join code and isis to understand my problem |
|
|
Mike Walne
Joined: 19 Feb 2004 Posts: 1785 Location: Boston Spa UK
|
|
Posted: Mon May 12, 2014 3:07 pm |
|
|
Abidi wrote: | I can not find how I can join code and isis to understand my problem |
Throw ISIS/Proteus away.
When you have a real hardware question, ask again.
Mike |
|
|
ezflyr
Joined: 25 Oct 2010 Posts: 1019 Location: Tewksbury, MA
|
|
Posted: Mon May 12, 2014 3:30 pm |
|
|
Hi All,
Hehe, I told you all this was going to be good!
John |
|
|
|