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

Strange pic16f886 usart problem

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



Joined: 19 Sep 2012
Posts: 9

View user's profile Send private message

Strange pic16f886 usart problem
PostPosted: Sun Apr 03, 2016 12:50 pm     Reply with quote

Hello, I'm using pic 16f886 to produce uart output. It looks good in uart terminal, but not good at rs232 terminal, i got strange chars.
Code:

#include <16f886.h>
#include "../h/spi.h"
#use delay(clock=8000000)
#include "../h/fuses.h" 
#use rs232(baud=1200, xmit=PIN_B6, rcv=PIN_B7)


 void init(){
   setup_oscillator(OSC_8MHZ);
   SET_TRIS_B(0x82);
   SET_TRIS_C(0x10);
}

 
void main (){
    init();
   printf( "2teste...\r\n");
   for(;;){
     printf( "2teste...\r\n");
     
   delay_ms(1000);
   }
}

and fuses


#FUSES NODEBUG
#FUSES NOLVP
#FUSES NOFCMEN
#FUSES NOIESO
#FUSES NOBROWNOUT
#FUSES NOPROTECT
#FUSES NOCPD
#FUSES MCLR
#FUSES NOPUT
#FUSES NOWDT
#FUSES INTRC_IO

Can anyone help me?

Thanks a lot
temtronic



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

View user's profile Send private message

PostPosted: Sun Apr 03, 2016 1:22 pm     Reply with quote

For Rs-232 you need to have a MAX232 or similar chip between PIC and the other RS232 device( PC ?)

Also you need to add 'errors' to the USERS232(...options...) so that the UART will not 'hang' when receiving data. I know you're only transmitting now...but ...eventually you'll want to get data.

Also use
#FUSES PUT //enable Power Up Timer

While this adds a very small delay it allows the PIC to Power Up in a neat,orderly fashion.

And.... usually there's no need to specifically use Set_tris...... as the compiler will handle the DDR as required.

Jay
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