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

setup_uart(); not working

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



Joined: 11 Feb 2005
Posts: 11

View user's profile Send private message Send e-mail

setup_uart(); not working
PostPosted: Fri Feb 11, 2005 7:19 pm     Reply with quote

When I use the setup_uart function I get an 'undefined identifier' error when I try to compile. I'm using RS232 at the top. Ijust understand why it doesn't like it. I am fairly new at PICS so any help greatly appreciated.

#include <16F628a.h>
#fuses XT,NOWDT,NOPROTECT
#use delay(clock=4000000) //External clock rate = 4MHz
#use rs232(baud=9600, xmit=PIN_B1, rcv=PIN_B2)


// Declare variables
int Data;
Char Data_String;


void main() {

// Set PortA as discrete input
SET_TRIS_A(0xFF); // All i/o set as inputs (1111 1111)

// Turn UART on
setup_uart(TRUE);

// Read Port A inputs
Data = input_a();
}
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Feb 11, 2005 7:57 pm     Reply with quote

The reason is because you have the pins reversed. Pin B2 is the transmit
and pin B1 is the receive. Example:
Code:
#use rs232(baud=9600, xmit=PIN_B2, rcv=PIN_B1, ERRORS)

Also it's a good idea to add the ERRORS parameter, as I've shown above.
It will prevent the UART from locking up if you get receive overrun
errors.

A few other tips:

1. Add NOLVP to the end of your #fuses statement. Only a small
number of home-built programmers available on the net use Low
Voltage Programming. It's unlikely that you're using it.
The PIC can lock up if you don't use NOLVP. You should use it.
Example:
Code:
#fuses XT, NOWDT, NOPROTECT, NOLVP   


2. You don't have to set the TRIS if you use the built-in CCS i/o
functions, such as output_low(), output_high(), output_float(),
input(), etc. It would make it easier in the beginning for you,
to not have to worry about TRIS, if you limited yourself to those
functions. See the CCS manual for a complete list.

3. You should place a while(1) statement right before the end of main(),
to prevent the PIC from going to sleep when the program falls off the
end of main. CCS puts a hidden SLEEP instruction right at that point.
Example:

main()
{

// Put your code here.

while(1); // Prevent the PIC from going to sleep.
}
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