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

Problems with UART 18F45k22

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



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Nov 09, 2010 2:25 pm     Reply with quote

I was able to make it work. But vs. 4.112 does have a bug, compared to
vs. 4.114. In the 18F45K22, all the i/o pins come up in Analog mode after
a power-on reset. In vs. 4.114, CCS loads all the ANSEL registers with 0
in their start-up code. This sets all the i/o pins to be in digital mode.
But in your version (4.112) CCS doesn't do this.

So to fix it, I added a short routine that emulates the behavior of 4.114.
It sets all ports to be Digital i/o. Just call this routine at the beginning of
of main() as shown in the program below. Then it should work. I did this
and it worked at both 300 baud and at 9600 baud.

The program below just echoes a character that you type in a terminal
window, such as TeraTerm. Whatever you type, will be received by the
PIC and sent back to the PC where you can see it on the screen.
Code:

#include <18F45K22.h>
#fuses INTRC_IO,NOWDT,PUT,BROWNOUT,NOLVP
#use delay(clock=4000000)
//#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, ERRORS)
#use rs232(baud=300, UART1, ERRORS)

void make_all_pins_digital(void)
{
#byte ANSELA = 0xF38
#byte ANSELB = 0xF39
#byte ANSELC = 0xF3A
#byte ANSELD = 0xF3B
#byte ANSELE = 0xF3C

ANSELA = 0;
ANSELB = 0;
ANSELC = 0;
ANSELD = 0;
ANSELE = 0;
}


#int_rda
void rda_isr(void)
{
int8 c;

c = getc();
putc(c);
}

//======================================
void main(void)
{
make_all_pins_digital();

printf("Start:  ");

enable_interrupts(INT_RDA);
enable_interrupts(GLOBAL);

while(1);
}
mcr1981



Joined: 27 Oct 2010
Posts: 28

View user's profile Send private message

Thanks for this info
PostPosted: Wed Nov 17, 2010 3:51 am     Reply with quote

Maybe I was lost in all this bit-byte madness and did not see that configuration.

Will try your suggestion tomorrow and will keep you posted.

Should one go back to 4.110? I need to renew my licence but will like it to be more stable with this new PICs.

Thanks.


PS: I did not get a notification for your response, had to search the forum again for it.
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