CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

Pickit 2 UART & ASCII Issue

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
kenjo



Joined: 16 Apr 2014
Posts: 2

View user's profile Send private message

Pickit 2 UART & ASCII Issue
PostPosted: Wed Apr 16, 2014 7:42 pm     Reply with quote

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

View user's profile Send private message Visit poster's website

PostPosted: Wed Apr 16, 2014 8:36 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Thu Apr 17, 2014 4:54 am     Reply with quote

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

View user's profile Send private message

PostPosted: Thu Apr 17, 2014 6:21 am     Reply with quote

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

View user's profile Send private message

PostPosted: Fri Apr 18, 2014 5:51 am     Reply with quote

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.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
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