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

Trouble with 16f88 UART

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







Trouble with 16f88 UART
PostPosted: Wed Jul 14, 2004 7:29 am     Reply with quote

Hello. I am trying to use the hardware UART on the pic16F88. The issue seems to be that kbhit continues to find something in the buffer. Pressing a letter "k" returns the following:
"Letter kLetter LLetter e" then the pic freezes here.

#include <16F88.h>
#use delay(clock=38400)
#use rs232(baud=300,parity=N,xmit=PIN_B5,rcv=PIN_B2,bits=8)
#define IRRXPWR PIN_A0
#byte PIR1 = 0x0c
#byte PORTB = 0x06
#byte PORTA = 0x05

void main()
{
int i,j;

set_tris_A (0x21);
set_tris_B (0x47);
setup_adc(ADC_OFF);
setup_comparator(NC_NC_NC_NC);
port_b_pullups(FALSE);
setup_spi(FALSE);
enable_interrupts(GLOBAL);
setup_uart(TRUE);

while(1){
for(i=0; i<100; i++){
if(kbhit()){
j = getc();
delay_ms(300);
printf("Letter %C",j);
delay_ms(300);
}

}
}
}
Ttelmah
Guest







Re: Trouble with 16f88 UART
PostPosted: Wed Jul 14, 2004 7:50 am     Reply with quote

tbsnake2 wrote:
Hello. I am trying to use the hardware UART on the pic16F88. The issue seems to be that kbhit continues to find something in the buffer. Pressing a letter "k" returns the following:
"Letter kLetter LLetter e" then the pic freezes here.

#include <16F88.h>
#use delay(clock=38400)
#use rs232(baud=300,parity=N,xmit=PIN_B5,rcv=PIN_B2,bits=8)
#define IRRXPWR PIN_A0
#byte PIR1 = 0x0c
#byte PORTB = 0x06
#byte PORTA = 0x05

void main()
{
int i,j;

set_tris_A (0x21);
set_tris_B (0x47);
setup_adc(ADC_OFF);
setup_comparator(NC_NC_NC_NC);
port_b_pullups(FALSE);
setup_spi(FALSE);
enable_interrupts(GLOBAL);
setup_uart(TRUE);

while(1){
for(i=0; i<100; i++){
if(kbhit()){
j = getc();
delay_ms(300);
printf("Letter %C",j);
delay_ms(300);
}

}
}
}

I think the terminal program you are using, is echoing the characters back. You are seeing the first two characters of the word 'Letter'...
With the delays in your loop, the receive hardware buffer in the UART, then overflows, and since you have not specified 'ERRORS' (which would clear this), the UART, is then hung.
Find out why the characters are being echoed back, and if you are going to delay in the receive code, consider using an interrupt driven serial buffer (look in the examples for how to do this).

Best Wishes
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