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

PIC18f14K22 and uart problems

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



Joined: 03 Jul 2009
Posts: 8

View user's profile Send private message

PIC18f14K22 and uart problems
PostPosted: Fri Aug 12, 2011 9:28 am     Reply with quote

Hi,
I'm trying to test this simple debug program to do an echo function on the serial port:

Code:
#INCLUDE <18f14k22.h>
#FUSES NOMCLR,INTRC,NOWDT
#USE DELAY(CLOCK=1000000)
#USE RS232(BAUD=9600,XMIT=PIN_B7,RCV=PIN_B5)

void main(){
char tmp;   
setup_oscillator(OSC_1MHZ);
printf("\n\rDEBUG LINE\n\r);
while (1){
    tmp=getc();
    printf("%c",tmp);
    }
}

On hyperterminal I see the line "DEBUG LINE" but by pressing a key my program does nothing.
The pic14fk22 works with 2V and between rs232 port there are two level translators that interfaces a max232 that works at 3.3V (from 3.3 to 2V for TX PC's line and 2.2 to 3.3V for RX PC's line).
With my oscilloscope I can see that by pressing a key on hyperterminal I see the 0-2V signal directly on a B5 pin....so I don't understand where is the problem.
There's something wrong on my code?
Thanks!
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Aug 12, 2011 12:58 pm     Reply with quote

Post your compiler version.
hexfet13



Joined: 03 Jul 2009
Posts: 8

View user's profile Send private message

PostPosted: Sun Aug 14, 2011 2:20 am     Reply with quote

Thanks for your reply.
My compiler version is 4.093.

At this time the problem is not solved yet; i don't understand what's wrong.
hexfet13



Joined: 03 Jul 2009
Posts: 8

View user's profile Send private message

PostPosted: Sun Aug 14, 2011 3:54 am     Reply with quote

I tried this simple code:

Code:
#INCLUDE <18f14k22.h>
#fuses NOWDT, NOMCLR, INTRC
#use delay(clock=1000000)

void main(){
setup_oscillator(OSC_INTRC|OSC_1MHZ);

while (1){
    output_bit(PIN_B7,input(PIN_B5));
    }   
}


With mplab sim, applying a stimulus directly on pin B5, B7 follow exactly the signal on the input.
My pic with this code behaves in a strange mode: I measure correctly 2V on B5 but B7 remains always to 0V. Seems that the pin internally does not to be read .....I don't understand: this micro is correctly powered with +2.0V and gnd.
Any suggestion?
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sun Aug 14, 2011 4:06 pm     Reply with quote

You have an older version of the compiler and it doesn't completely
support the 18F14K22. For example, the CCS standard is to configure
PortA as all digital in their start-up code. They don't do this in vs. 4.093.
Also, setup_adc_ports(NO_ANALOGS) doesn't work in that version. That
should properly set all analog pins on Ports A and B to be all digital. But it
doesn't. So to fix it, you can add the lines shown in bold below to your program:
Quote:

#include <18F14K22.h>
#fuses NOWDT, NOMCLR, INTRC_IO
#use delay(clock=1M)

void make_all_pins_digital(void)
{
#byte ANSEL = getenv("SFR:ANSEL")
#byte ANSELH = getenv("SFR:ANSELH")

ANSEL = 0;
ANSELH = 0;
}


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



while(1);
}


Explanation of why it's happening:
The PIC data sheet explains what will happen if you try to read a digital
pin that is still configured as analog. To fix this problem, add the code
shown in bold above to your program. The data sheet says:
Quote:

10.7 Port Analog Control

Setting an ANSx bit high will disable the associated digital input
buffer and cause all reads of that pin to return ‘0’ while allowing
analog functions of that pin to operate correctly.
hexfet13



Joined: 03 Jul 2009
Posts: 8

View user's profile Send private message

PostPosted: Tue Aug 16, 2011 7:17 am     Reply with quote

Yes, you are perfectly right, my compiler version does not support at 100% this micro.
Thanks for helping me
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