|
|
View previous topic :: View next topic |
Author |
Message |
kenjo
Joined: 16 Apr 2014 Posts: 2
|
Pickit 2 UART & ASCII Issue |
Posted: Wed Apr 16, 2014 7:42 pm |
|
|
Hi there guys.
I've looked around the forum and have looked at the solutions for other similar problems, but I cant seem to solve this.
I'm trying to get the analog value into a string so it can be read on the ASCII of the Pickit 2 UART. But so far all I get is a bunch of ??????.
I'm currently using a PIC 16F819, MPLAB IDE v8.92 for coding and programming via Pickit 2 programmer v2.60.
My current code:
Code: |
#include <16f819.h>
#fuses INTRC_IO,NOWDT,NOPROTECT,MCLR,NOBROWNOUT
#DEVICE ADC=10
#use DELAY (clock=4000000)
#use rs232(baud=9600, xmit=PIN_B7, rcv=PIN_B6, STREAM=PC)
int16 Y;
void main(void)
{
delay_ms(500);
setup_ADC_ports(AN0);
setup_adc(ADC_CLOCK_DIV_8);
while(1)
{
char str[10];
set_adc_channel(0);
delay_us(38);
Y=read_adc();
sprintf(str, "%lu", Y);
fprintf(PC,"ADC Y=%lu\r\n", str);
}
}
|
To be honest I'm currently unable to get any sort of string value to appear, its always a bunch of ???????. I do get values for hex but they are in 8 bit, and so aren't really ideal when I set adc=10.
I appreciate all the help. |
|
|
johanpret
Joined: 23 Oct 2006 Posts: 33 Location: South Africa
|
|
Posted: Wed Apr 16, 2014 8:36 pm |
|
|
Cant use it like that.
Use:
fprintf(PC,"ADC Y=%lu\r\n", Y);
or
sprintf(str, "%lu", Y);
fprintf(PC,"ADC Y=%s\r\n", str); _________________ Johan Pretorius |
|
|
kenjo
Joined: 16 Apr 2014 Posts: 2
|
|
Posted: Thu Apr 17, 2014 4:54 am |
|
|
Thanks for the help, I've tried to replace the code with both the solutions but still get the same problem. Is there something wrong with my current #fuses or clock setups?
Edit: I also realised that I do not actually need the rcv, so I removed that from the code to avoid any complications within the pic |
|
|
ezflyr
Joined: 25 Oct 2010 Posts: 1019 Location: Tewksbury, MA
|
|
Posted: Thu Apr 17, 2014 6:21 am |
|
|
Hi,
This is really silly! Do you even know *for sure* that your PIC to PC communications are working correctly? Add this line just before the While(1) loop, and don't do ANYTHING else until you can make this work!!
Code: |
fprintf(PC, "Hello World!\r\n");
|
If this does not work, post your schematic!
Good Luck!
John |
|
|
RoGuE_StreaK
Joined: 02 Feb 2010 Posts: 73
|
|
Posted: Fri Apr 18, 2014 5:51 am |
|
|
As above, check that it's working fullstop before doing anything more complicated. I had the same thing a while back (the "?????"), and after much frustration I reverted to a standard "blink" program, only to find the LED was blinking about 1/4 of the speed it was supposed to; if your physical timing's out, then no way will comms work. |
|
|
|
|
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
|