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

PIC18F14K50 UART Problem

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



Joined: 01 Nov 2007
Posts: 9

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

PIC18F14K50 UART Problem
PostPosted: Fri Jun 12, 2009 7:33 am     Reply with quote

Hi,
I have made a small Eval board for PIC18F14K50 :
I have a PicKit 2 Programmer.
I use CCS Compiler v4.088.
I Uuse Proteus ISIS v7.4 SP3 for Simulation.

My problem is when I use Port_B5 to receiving a RS232 data it don't work on ISIS and on my Eval Board, but when I use another port like Port_B6 it work fine on ISIS and on my Eval board!!
Can someone help me if I have an error in my source code?

CCS source Code to transmit a receiver character:
Code:
#include <18F14K50.h>
#fuses NOWDT,NOPROTECT,NOLVP
#fuses HS
#FUSES CPUDIV1
#use delay(clock=20M)
#use rs232(baud=57600,parity=N,xmit=PIN_B7,rcv=PIN_B6,bits=
#use fast_io (B)

void main()
{
char a;
while(1)
{
a=getc();
putc(a);
}
}
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Jun 12, 2009 11:39 am     Reply with quote

The problem is that your version of the compiler does not have the
correct start-up code. It does not set all pins to be for digital i/o.
Also, the setup_adc_ports() function doesn't do this in your version.
So you have to fix it by writing directly to the ANSEL and ANSELH
registers. Add the lines shown in bold below:
Quote:

#include <18F14K50.h>
#fuses HS,NOWDT,NOPROTECT,NOLVP
#use delay(clock=20000000)
#use rs232(baud=57600,xmit=PIN_B7,rcv=PIN_B6)

#byte ANSEL = 0xF7E
#byte ANSELH = 0xF7F


//====================================
void main()
{
char a;

ANSEL = 0;
ANSELH = 0;


while(1)
{
a = getc();
putc(a);
}

}

Also, you are selecting "fast i/o" mode on Port B, but you are not
setting the TRISB register. You're supposed to do that.

My advice is, don't use fast i/o. Leave it in "standard i/o" mode, which
is the default mode of the compiler. Then the compiler will set the TRIS
for you, automatically. You don't need to worry about 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