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

rs232 help

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



Joined: 23 Feb 2014
Posts: 35

View user's profile Send private message

rs232 help
PostPosted: Mon Feb 24, 2014 2:40 pm     Reply with quote

Hello, as i wrote a code to just show the value of the adc of the y axis if an accelometer on screen, an error showed saying i need to use #use rs232.
I'd like to know why and when i need to use the rs232 as well as what do i do with the xmit and rvc pins?
This is the code:
Code:

#include <16f877a.h>
#fuses NOWDT, NOPROTECT, HS
#device ADC=10                                               
#use DELAY (crystal=20MHz)
#use rs232 (xmit=??, rcv=??, baud=38400)
                                                                           
void main(void)
{
   int16 res;                                                                           
   output_low(PIN_B2);
   setup_ADC_ports(AN0);
   set_adc_channel(0);
   setup_adc(ADC_CLOCK_DIV_32);
   
   while(TRUE)
   {     
   delay_us(10);                                   
   res=read_adc();
   printf("ADC result=%Lu\n\r", res);                         
   }                         
}
Ttelmah



Joined: 11 Mar 2010
Posts: 19510

View user's profile Send private message

PostPosted: Mon Feb 24, 2014 2:52 pm     Reply with quote

#USE RS232 sets up the async serial for you....

Now key is that in traditional 'C' you run inside an OS, and the serial transmit and receive connect to the hardware UART (on a PC), via the OS. So you can transmit, and the OS does the job of sending this to the UART. In the PIC you don't have this, and #USE RS232 allows you to setup this type of connection.

There are two choices:

#use rs232 (UART1, baud=38400, ERRORS)

This says 'use the hardware UART 1'. The pin numbers used, simply require you to look at the data sheet.

The alternative is to specify pin numbers. If you do, and these are not the hardware pins, then a software UART emulation is used. Advantage, you can use any pins. Disadvantages: Half duplex only. No buffering. You have to poll the receive line much faster than the bit time, or data will be lost. etc...

With the hardware UART, you _must_ have the ERRORS directive, or add code to clear UART errors yourself. Otherwise if a couple of receive characters are missed, the UART _will_ hang.

You talk about a screen?. How is this connected?. If this is an LCD, then you don't need #USE RS232. Instead load lcd.c, or the flex lcd driver. Set it up to match your hardware, and print to lcd_putc. A search in the code library flex lcd entry, will show how you print to this instead of to the serial.

Look at the CCS examples, and at the posts here to see how it all works.
ezflyr



Joined: 25 Oct 2010
Posts: 1019
Location: Tewksbury, MA

View user's profile Send private message

PostPosted: Mon Feb 24, 2014 2:53 pm     Reply with quote

Hi,

This topic has been covered a million times before! The answer is out there if you use a little bit of initiative to find it! So, search the compiler manual, the forum, and the CCS-supplied example files on your own. Trust me, you'll be much better off in the long run if you don't insist we hold your hand!

Good Luck!

John
moryoav



Joined: 23 Feb 2014
Posts: 35

View user's profile Send private message

PostPosted: Mon Feb 24, 2014 3:05 pm     Reply with quote

Ttelmah wrote:
#USE RS232 sets up the async serial for you....

Now key is that in traditional 'C' you run inside an OS, and the serial transmit and receive connect to the hardware UART (on a PC), via the OS. So you can transmit, and the OS does the job of sending this to the UART. In the PIC you don't have this, and #USE RS232 allows you to setup this type of connection.

There are two choices:

#use rs232 (UART1, baud=38400, ERRORS)

This says 'use the hardware UART 1'. The pin numbers used, simply require you to look at the data sheet.

The alternative is to specify pin numbers. If you do, and these are not the hardware pins, then a software UART emulation is used. Advantage, you can use any pins. Disadvantages: Half duplex only. No buffering. You have to poll the receive line much faster than the bit time, or data will be lost. etc...

With the hardware UART, you _must_ have the ERRORS directive, or add code to clear UART errors yourself. Otherwise if a couple of receive characters are missed, the UART _will_ hang.

You talk about a screen?. How is this connected?. If this is an LCD, then you don't need #USE RS232. Instead load lcd.c, or the flex lcd driver. Set it up to match your hardware, and print to lcd_putc. A search in the code library flex lcd entry, will show how you print to this instead of to the serial.

Look at the CCS examples, and at the posts here to see how it all works.

Thank you for the detailed answer. Of course i look around for more information but since I'm new to this i find it hard to understand other programs...
Anyway, my question is about this line
Quote:
#use rs232 (xmit=??, rcv=??, baud=38400)

I hope I'm correct by saying that rcv=PIN_B2 [according to my code], but i fail to understand where to connect it to, to be able to see a flow of adc values. I saw a lot of codes doing something like
Quote:
xmit=pin_c6 rcv=pin_c7

How connecting them that way help them see the results? and where[lcd/window like in visual c++'s printf/else]
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Feb 24, 2014 3:56 pm     Reply with quote

Use Google to find some RS-232 websites for newbies.

Use this search string:
Quote:
RS-232 with CCS compiler -ccsinfo.com


Here's one example:
http://www.picprojects.net/rs232_communication/
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