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

CCS USART SETUP --> 16F877A

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



Joined: 17 Nov 2010
Posts: 38
Location: 121

View user's profile Send private message

CCS USART SETUP --> 16F877A
PostPosted: Tue Mar 08, 2011 1:46 pm     Reply with quote

Hi,

I'm planning to make a communication between 2 microcontroller with using RF transmitter and receiver (315Mhz).

So with USART, the data just will be put in the tx MCU1 and through the RF transmitter and in another side rx in MCU2 will receive the data.

There is a problem raise in my mind,
Do need method still need a rs232? I feel that it is don't need, but I just wonder when talk about USART, everybody talk about RS232. I'm really confusing with this?

Besides, any hint with writting the USART using CCS? Any built-in function. Else, how to set the USART register? I would happy if anyone willing to provide me some sample code.

Thanks alot.

Regards,
sysysy


Last edited by sysysy on Wed Mar 09, 2011 8:51 pm; edited 4 times in total
temtronic



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

View user's profile Send private message

PostPosted: Tue Mar 08, 2011 3:07 pm     Reply with quote

Whether you need RS232 interface chips(ie: MAX232) depends upon the RF transmitter / receiver modules you're using. Same are 'TTL' compatible, others need RS232 chips.
Be very careful with VOLTAGE supplies though, be sure both PIC and your xmt/rcv modules are compatible(both 5 v or both 3.3 volt)

CCS has several builtin functions for 'RS232' communications AKA serial interfaces, consult the help files as well as examples folders for info.

I suggest you get your program working without RF modules first, then add the modules later....
sysysy



Joined: 17 Nov 2010
Posts: 38
Location: 121

View user's profile Send private message

PostPosted: Tue Mar 08, 2011 7:30 pm     Reply with quote

Quote:
I suggest you get your program working without RF modules first, then add the modules later....


what are you meaning here just direct use the wire to communicate between 2 MCU before proceed to RF module?

Quote:
CCS has several builtin functions for 'RS232' communications AKA serial interfaces, consult the help files as well as examples folders for info.


Since you say it might don't need with use for a RS232, so other than rs232 built-in function, other direct method?
sysysy



Joined: 17 Nov 2010
Posts: 38
Location: 121

View user's profile Send private message

PostPosted: Wed Mar 09, 2011 3:16 am     Reply with quote

Hi,

I need a help from you guys.
Anyone know how to write the setup code for USART without RS232?

I found that all the ccs built-in also involving #use232(...). I don't know how to apply this in my case since I am not using rs232.

In my hardware, I never use rs232 or max 232, the communication just between 2 MCU through RF module. But before proceed to further RF communication, I want to try just using the jumper to connect Tx and Rx to test first.

But now I am stucking in writing the setup code. Hopefully anyone can provide me a sample setup code. Thanks.
Ttelmah



Joined: 11 Mar 2010
Posts: 19497

View user's profile Send private message

PostPosted: Wed Mar 09, 2011 3:21 am     Reply with quote

Funnily enough 'well done', in being confused..... Smile

CCS, uses the nomenclature 'RS232' (which a PIC cannot generate without external buffer hardware), to refer to the async TTL serial which the chip generates. That the chip _doesn't_ actually generate 'RS232' communications leads sometimes to a lot of bother...
So the line #USE RS232, is used to setup the async hardware or software serial communication, even when 'RS232' is not involved. If (for example), you look in the RS485 examples (which obviously use 485, rather than 232 connections), they still use #USE RS232.
So in your case, you want this async serial connection, so use the #USE RS232 setup, and use the TTL serial to talk to your radio modules.

Best Wishes
sysysy



Joined: 17 Nov 2010
Posts: 38
Location: 121

View user's profile Send private message

PostPosted: Wed Mar 09, 2011 3:40 am     Reply with quote

Thanks for the fast reply.

Hmmm, so in the #use232(...)

example
Code:
#use rs232(baud=9600, xmit=PIN_B2, rcv=PIN_B1, stream=PC)


i see there is a lot of parameter, but the common use always is this 4.
and the last one, stream is use for rs232 port, that mean i dun use it, so in my case just simply 3 parameter?

am i right?
Ttelmah



Joined: 11 Mar 2010
Posts: 19497

View user's profile Send private message

PostPosted: Wed Mar 09, 2011 3:55 am     Reply with quote

Distinguish two configurations:
1) Setting up the hardware USART.
2) Generating a software UART emulation.

For '1', you 'need' the baud rate, the chip defaults to 8bits no parity (and the compiler does the same), so use:

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

You don't need to specify the TX, and RX pins, since you are using the hardware UART (UART1 says this), but _do_ have the ERRORS statement (this adds code to handle UART overrun, and framing errors, and _must_ be used with the hardware, unless you do this yourself).

Stream is only necessary if you are setting up multiple connections.

For '2', you need to define the pins.

Best Wishes
sysysy



Joined: 17 Nov 2010
Posts: 38
Location: 121

View user's profile Send private message

PostPosted: Wed Mar 09, 2011 4:59 am     Reply with quote

Hello,
i know i am weak in programming, this is just a only code that i can come out with. i don't know how to transmit and receive part.

I just want to simply send a signal from MCU1 to MCU2 while push the turn
on and off button. Then in other side, the LED will turn on when receive the signal.

I hope someone can help me complete my code. I know it is easy, but i don't know write the code to transmit out the data and receive data.

Transmitter Part

Code:
#include <16F877A.h>
#fuses HS,NOWDT,NOPROTECT,NOLVP
#use delay(clock=20000000)
#use rs232(baud=9600, UART1, ERRORS) //Setup, using UART hardware, error management

define BUTTON_ON PIN_D0
define BUTTON_OFF PIN_D1

void main()
{
   char On=0xAA, OFF=0xBB;

   while(1)
   {
   if(input(BUTTON_ON)==0)
   Tx = ON;
   
   else if(input(BUTTON_OFF)==0)
   Tx = OFF;
   }
}

.
.
.
.
.



Receiver Part

Code:

#include <16F877A.h>
#fuses HS,NOWDT,NOPROTECT,NOLVP
#use delay(clock=20000000)
#use rs232(baud=9600, UART1, ERRORS)

#define LED_1 PIN_B0

void main()
{

   while(1)
   {   

   if(receive=0xAA)
   output_high(LED_1);

   else if (receive=0xBB)
   output_low(LED_1);
   }
.
.
.
.
.


Really appreciate for the help Embarassed Embarassed Embarassed [/quote]
ezflyr



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

View user's profile Send private message

PostPosted: Wed Mar 09, 2011 1:24 pm     Reply with quote

Hi sysysy,

You really need to spend a bit of time reading the forum, and studying the example programs. I'm a self-taught "C" programmer, and I did that by taking on some small projects that interested me, looking at the work of others, and experimenting. It's not terribly difficult, and can actually be a lot of fun to "learn by doing"!! If your programming "strategy" is to throw yourself at the mercy of the forum, I think you are going to be awfully disappointed with the results in the long run....!

Your code has a lot of problems. First, in the transmitter code, you are not debouncing your pushbuttons, and this will surely lead to problems. Look at the 'button' routine that has been posted here previously to do this. Next, your serial transmit syntax, Tx = On;, is meaningless. Take a look at the 'PUTC' function for sending individual bytes of data (ie. PUTC(0xAA);).

In the receiver code, look at the 'GETC' function. This function will allow you to receive a single character from the defined serial port.

Good Luck,

John
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