![](templates/subSilver/images/CCSLogo.jpg) |
![CCS C Software and Maintenance Offers](templates/subSilver/images/forumAd6.jpg) |
View previous topic :: View next topic |
Author |
Message |
tbsnake2 Guest
|
Trouble with 16f88 UART |
Posted: Wed Jul 14, 2004 7:29 am |
|
|
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);
}
}
}
} |
|
![](templates/subSilver/images/spacer.gif) |
Ttelmah Guest
|
Re: Trouble with 16f88 UART |
Posted: Wed Jul 14, 2004 7:50 am |
|
|
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 |
|
![](templates/subSilver/images/spacer.gif) |
|
|
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
|