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

Serial monitor for pic

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



Joined: 06 Sep 2017
Posts: 82

View user's profile Send private message

Serial monitor for pic
PostPosted: Tue Nov 14, 2017 3:27 am     Reply with quote

I wanted to analyze the data taken by analog sensor. But i don't want to use lcd display due to limited number of pins of pic So is there any other method to see the adc result?? Like arduino serial monitor??
Ttelmah



Joined: 11 Mar 2010
Posts: 19518

View user's profile Send private message

PostPosted: Tue Nov 14, 2017 4:03 am     Reply with quote

The simplest way to monitor what a PIC is doing is just an RS232 connection.

#USE RS232, and either a level translator to real RS232, or a USB TTL connection to your PC. This is by far the most basic and common way of interfacing to the chip. 95% of the CCS examples are using this not an LCD.

If you are debugging using an IDE, you may well be able to not even use a physical port at all, but a virtual 'debug' window. This is what the Arduino serial monitor is providing. The CCS IDE offers this through #use rs232(ICD), and also a 'snapshot' ability to record values at particular points in the code. Remember though to be debugging you will lose the debugging pins on the chip (and B3 if using the debug monitor), and need to be connected to the PC.
This launches the standard SIO terminal program and actually displays what you print in this.

To avoid the pin loss, and to allow working without a PC there are serial LCD displays that only need one pin!...
Something like this:
<https://www.sparkfun.com/products/9395>
Only requires GND, power, and a single pin from the PIC.

There are literally hundreds of ways of outputting data. It all depends on what you are doing, and where you need to see this.
temtronic



Joined: 01 Jul 2010
Posts: 9229
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Tue Nov 14, 2017 6:05 am     Reply with quote

Since you asked about display options...

You could connect 8 or 10 LEDs (and current limiting resistors) to the PIC.
If the ADC is set for 8 bit mode, it's easy. Just connect 8 LED (+Rs) to one port of the PIC.

Something like this
Code:

main()
do {
ADC_result=read_adc();
Output_B(ADC_result);
delay_ms(500);
{
while(true);

main() reads the ADC, displays the data in binary, pauses for 1/2 second, then repeats this forever.

An 'upgrade' to this, is to use 7-segment displays that accept HEX data. HP made them a long, long time ago, each nibble of port B connects to a display. Still used on PC POST cards.

Jay
jeremiah



Joined: 20 Jul 2010
Posts: 1349

View user's profile Send private message

PostPosted: Tue Nov 14, 2017 8:25 am     Reply with quote

Ttelmah wrote:

If you are debugging using an IDE, you may well be able to not even use a physical port at all, but a virtual 'debug' window. This is what the Arduino serial monitor is providing. The CCS IDE offers this through #use rs232(ICD), and alse a 'snapshot' ability to record values at particular points in the code.


We use this a lot. I wanted to add some experience comments for the OP's benefit:

This is a "software" serial port rather than a hardware serial port. This is obvious to us old timers, but for newcomers, it may not be the first thing they think of. This comes with a couple of things to keep in mind:

1. Receiving on a software serial port is tricky and error prone. I know the OP was asking about display, but I have seen many engineers take the next step after getting comfortable and try to use it for input (simple character commands). I would definitely recommend against using it for input except in very controlled situations. Only use these for output as the default operation. If you do, your main code has to pretty much do nothing else but watch the serial port when not processing commands as any other code can cause the serial receive to get garbage stuff.

2. If you have interrupts, you should also specify to disable interrupts in the #use rs232() call. Even if it works out of the box on day 1, somewhere down the line...day 33 for example...you will start getting random code results and won't immediately know why. The side effect of disabling interrupts is that it can impact your normal operation, but that is something you need to consider. I've had this problem come up from several different coworkers. They call me in because their code stopped working and all they did was add _____. A couple of them forgot and had it happen again. Disabling interrupts for the software serial port fixed the issue.
srikrishna



Joined: 06 Sep 2017
Posts: 82

View user's profile Send private message

PostPosted: Wed Nov 15, 2017 1:44 am     Reply with quote

Ttelmah wrote:
The simplest way to monitor what a PIC is doing is just an RS232 connection.

#USE RS232, and either a level translator to real RS232, or a USB TTL connection to your PC.


Did you mean USB TTL Serial Cables??


like this model??
Ttelmah



Joined: 11 Mar 2010
Posts: 19518

View user's profile Send private message

PostPosted: Wed Nov 15, 2017 1:57 am     Reply with quote

Yes.
Assuming this is a 5v model, and the PIC is a 5v device (otherwise you need 3.3v types).

Connect it's GND to the PIC GND
Connect it's RX to any unused pin on the PIC (well 99% of unused pins there are a very few that can't do normal I/O - depends on your PIC).

Setup a software RS232 connection to this pin:
Code:

#USE RS232(XMIT=PIN, BAUD=57600, DISABLE_INTS, STREAM=DEBUG)
//Where 'PIN' is the pin you have connected


Then run a terminal program on the PC (CCS's serial monitor, or any of the normal terminal programs - Teraterm etc.). Set this up to listen to the serial port, and to the same baud rate.

Where you want to send data just fprintf to it:

fprintf(DEBUG,"This is a message\n\r");
srikrishna



Joined: 06 Sep 2017
Posts: 82

View user's profile Send private message

PostPosted: Wed Nov 15, 2017 7:32 am     Reply with quote

Ttelmah wrote:
Yes.
Assuming this is a 5v model, and the PIC is a 5v device (otherwise you need 3.3v types).

Connect it's GND to the PIC GND
Connect it's RX to any unused pin on the PIC (well 99% of unused pins there are a very few that can't do normal I/O - depends on your PIC).


Here is the list of products from ebay. Can you tell me which one should i buy?
    https://www.ebay.in/sch/i.html?_from=R40&_trksid=p2050601.m570.l1313.TR0.TRC0.H0.Xusb+to+ttl.TRS0&_nkw=usb+to+ttl&_sacat=0

It must be helpful because i just started to learn PIC. And i have no experience before.

Please tell me which one should i use? Rolling Eyes Rolling Eyes
srikrishna



Joined: 06 Sep 2017
Posts: 82

View user's profile Send private message

PostPosted: Wed Nov 15, 2017 10:11 am     Reply with quote

https://www.ebay.in/sch/i.html?_from=R40&_trksid=p2050601.m570.l1313.TR0.TRC0.H0.Xusb+to+ttl.TRS0&_nkw=usb+to+ttl&_sacat=0

Please give me advice which one should i buy ???
temtronic



Joined: 01 Jul 2010
Posts: 9229
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Wed Nov 15, 2017 10:29 am     Reply with quote

I did a quick check
https://www.ebay.in/itm/USB-To-RS232-PL2303-TTL-Converter-Adapter-For-Aurdino-Nano-Raspberry-Pi/122766169500?hash=item1c956f159c:g:BVsAAOSwa3BZ64ax

It seems OK for use. Under $2 CDN (Rs 80). You need to look at shipping costs. You can get free shipping from China (www.banggood.com). I've ordered a LOT of 'PIC' modules from them...keypads, RTC, cables, etc. all have been 100% working, take 2-3 weeks to get though.

Jay
Ttelmah



Joined: 11 Mar 2010
Posts: 19518

View user's profile Send private message

PostPosted: Thu Nov 16, 2017 4:47 am     Reply with quote

Let me just make a faint caveat.

This module is ideal for what is being discussed here. Monitor output from the PIC to PC. Should work fine, and is cheap.

However the 'caveat'.
If you want to make a RS232 connection to the PIC, using the hardware serial connections, this will not work (for a 5v PIC).
The PIC serial input has a Schmidt input. This requires the incoming signal to go up to 4v before it will be seen as 'high'.

So while the module is fine for the application here, don't buy this expecting to use it to send and receive on the hardware UART of a 5v PIC.

The one I have found that works are the modules based on the CH340G chip. This is the chip actually used in the Arduino, and the chip itself supports operation at 3v or 5v. Many of the modules using this have a jumper allowing you to run the chip at either voltage, making it great for interfacing with both 3.3v and 5v PIC's. The drivers on this chip were awful a while ago, but the drivers in W10 for the last year or so have been OK.
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