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 support@ccsinfo.com

serial port PLEASE HELP

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








serial port PLEASE HELP
PostPosted: Mon Mar 08, 2004 11:08 am     Reply with quote

Hello,
I'm trying to do a simple test on the serial port using a pic18F6520. I'm using windows hyperterminal and I'm not getting anything coming through. Can someone please tell me what I'm doing wrong? This is my code:

/***********************************************************/
#include <18F6520.h>
#use delay(clock = 40000000)
#use rs232(baud=9600, xmit=PIN_G1, rcv=PIN_G2) //set up SERIAL PORT on USART2
#fuses XT,NOWDT,PUT,NOBROWNOUT,NOLVP

#BYTE PORTA = 0XF80 //PORTA - PIC18F6520
#BYTE PORTB = 0xF81 //PORTB - PIC18F6520
#BYTE PORTC = 0xF82 //PORTC - PIC18F6520
#BYTE PORTD = 0xF83 //PORTD - PIC18F6520
#BYTE PORTE = 0xF84 //PORTE - PIC18F6520
#BYTE PORTF = 0xF85 //PORTF - PIC18F6520
#BYTE PORTG = 0xF86 //PORTG - PIC18F6520

#BYTE TRISG = 0xF98 //TRISG - PIC18F6520

#BYTE PIE2 = 0xFA0 //Peripheral interrupt enable reg.
#BYTE RCSTA1 = 0xFAB //Receive status control register for USART1
#BYTE TXSTA1 = 0xFAC //Transmit status control register for USART1
#BYTE RCSTA2 = 0xF6B //Receive status control register for USART2
#BYTE TXSTA2 = 0xF6C //Transmit status control register for USART2
#BYTE TXREG2 = 0xF6D //Transmit buffer register for USART2
#BYTE SPBRG2 = 0xF6F //Baud rate generator for USART2
#BYTE BAUDCON2 = 0xF7C //Baud rate control register for USART2

//Serial Port definitions
#bit TXIE = PIE2.4 //transmit interrupt enable bit
#bit RCIE = PIE2.5 //receive interrupt enable bit
#bit TX9 = TXSTA2.6 //9-bit transmit enable bit
#bit TXEN = TXSTA2.5 //transmit enable bit
#bit SYNC = TXSTA2.4 //synchronous mode
#bit TRMT = TXSTA2.1 //TSR status bit
#bit SPEN = RCSTA2.7 //serial port enable pin
#bit RX9 = RCSTA2.6 //9-bit reception enable bit
#bit CREN = RCSTA2.1 //reception enable bit
#bit BRGH2 = TXSTA2.2 //baude rate generator high bit enable
#bit BRG16 = BAUDCON2.3 //16-bit transfer mode enable bit

void main(){
/*----------configure all the ports-------*/

PORTA = 0;
PORTB = 0;
PORTC = 0;
PORTD = 0;
PORTE = 0;
PORTF = 0;
PORTG = 0;

BRGH2 =0; // low baude rate
BRG16 =0; // 8-bit transfer mode
SPBRG2 = 64; // 9600 bit/s at 40MHz clock speed
SYNC = 0; // ASYNCHRONOUS MODE
SPEN = 1; // ENABLE SERIAL PORT PINS
CREN = 1; // ENABLE RECEPTION
TXIE = 0; // DISABLE TRANSMIT INTERRUPTS
RCIE = 0; // DISABLE RECEIVE INTERRUPTS
TX9 = 0; // 8-BIT TRANSMIT MODE
RX9 = 0; // 8-BIT RECEIVE MODE
TXEN = 0; // RESET TRANSMITTER
TXEN = 1; // ENABLE TRANSMITTER

bit_set(TRISG,2);
BIT_CLEAR(TRISG,1);

#asm
clrwdt
#endasm

/*-----------set PIC registers------------*/

delay_ms(10);
printf("Hello World\r");
delay_ms(500);
printf("Goodbye World\r");

}//end main
/**********************************************************/

Thanks,
Emily
Neutone



Joined: 08 Sep 2003
Posts: 839
Location: Houston

View user's profile Send private message

PostPosted: Mon Mar 08, 2004 11:25 am     Reply with quote

#use delay(clock = 40000000)
#use rs232(baud=9600, xmit=PIN_G1, rcv=PIN_G2) //set up SERIAL PORT on USART2
#fuses XT,NOWDT,PUT,NOBROWNOUT,NOLVP

Do you really have 40Mhz and the fuse set to XP?
mle



Joined: 12 Sep 2003
Posts: 10

View user's profile Send private message

PostPosted: Mon Mar 08, 2004 11:39 am     Reply with quote

NO! That should have been HS.

Thanks you so much!

Emily
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