|
|
View previous topic :: View next topic |
Author |
Message |
Student Guest
|
Setting up ADC |
Posted: Thu Feb 22, 2007 7:16 am |
|
|
Hi,
i'm trying to write a program to run setup my adc and i'm getting problems and i do not know the reason why. Anyone can help me? Thanks!
Code: | #include <16F877.h>
#device adc=10
#fuses HS,NOWDT,NOPROTECT,NOLVP
#use delay(clock=2000000)
#use rs232(baud=9600, xmit = PIN_C6, rcv = PIN_C7)
int16 value;
void main() {
setup_adc_ports(RA0_ANALOG);
setup_adc(ADC_CLOCK_INTERNAL);
delay_ms(2000);
set_adc_channel(0);
while(1)
{
value=read_adc(); //read the ADC
printf("%LX \n\r", value);
delay_ms(1000);
}
}
|
Output from hyperterminal:
rrrrr>>>>><<<<>>>>[/code] |
|
|
Ttelmah Guest
|
|
Posted: Thu Feb 22, 2007 9:39 am |
|
|
How is the serial connected to the PC?. What happens if you do a 'test' print like:
printf("Test message\n\r");
There is nothing obviously wrong with the code, so I'd suspect a hardware problem with the serial connection.
Best Wishes |
|
|
buiz
Joined: 21 Feb 2007 Posts: 4
|
|
Posted: Thu Feb 22, 2007 9:48 am |
|
|
Hello!
#include <16F877.h>
#device adc=10
#fuses HS,NOWDT,NOPROTECT,NOLVP
#use delay(clock=2000000) // crystal 2000000? or 20000000? look at this detail!!!
#use rs232(baud=9600, xmit = PIN_C6, rcv = PIN_C7)
int16 value;
void main() {
setup_ADC_ports (an0); // (an0) it configures door an0
setup_adc(ADC_CLOCK_INTERNAL);
delay_ms(2000);
set_adc_channel(0);
while(1)
{
value=read_adc(); //read the ADC
printf("%LX \n\r", value);
delay_ms(1000);
}
}
Ok!
Last edited by buiz on Thu Feb 22, 2007 11:36 am; edited 2 times in total |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Thu Feb 22, 2007 11:20 am |
|
|
Quote: |
Output from hyperterminal:
rrrrr>>>>><<<<>>>>
#include <16F877.h>
#device adc=10
#fuses HS,NOWDT,NOPROTECT,NOLVP
#use delay(clock=2000000)
#use rs232(baud=9600, xmit = PIN_C6, rcv = PIN_C7)
|
Look closely at the line in bold. Then look at the numbers on your
crystal. |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|