|
|
View previous topic :: View next topic |
Author |
Message |
Jomile
Joined: 06 Nov 2007 Posts: 5
|
Receiving RS-232 Data From HyperTerminal (16F877A) |
Posted: Tue Nov 06, 2007 4:56 pm |
|
|
Hello,
I have an 16F877A and MAX233 chip that i am using to communicate with a computer (hyperterminal).
I have no problem sending data to the computer using printf.
The problem I have is when trying to read data back from the computer. For example, in the code below, regardless of what character i get it is not displayed. The output in HT is "nextnextnext" as if there were no character stored in answer.
Code: |
while(TRUE){
answer=getc();
putc(answer);
printf("next");
} |
Ultimately I want to use the "gets" command so that I can send strings but that did not work so I went to the characters. Is there something wrong with my code? (see below). I have a 20Mhz crystal. 16F877, v. 4.057
Thanks
main.c
Code: |
#include "C:\Program Files\PICC\Projects\11-6-07\main.h"
#include <string.h>
void main()
{
char answer;
setup_adc_ports(NO_ANALOGS);
setup_adc(ADC_OFF);
setup_psp(PSP_DISABLED);
setup_spi(SPI_SS_DISABLED);
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DISABLED,0,1);
setup_comparator(NC_NC_NC_NC);
setup_vref(FALSE);
// TODO: USER CODE!!
printf("Welcome");
while(TRUE){
answer=getc();
putc(answer);
printf("next");
}
} |
MAIN.H
Code: |
#include <16F877A.h>
#device adc=8
#FUSES NOWDT //No Watch Dog Timer
#FUSES HS //High speed Osc (> 4mhz)
#FUSES NOPUT //No Power Up Timer
#FUSES NOPROTECT //Code not protected from reading
#FUSES NODEBUG //No Debug mode for ICD
#FUSES NOBROWNOUT //No brownout reset
#FUSES NOLVP //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#FUSES NOCPD //No EE protection
#FUSES WRT_50% //Lower half of Program Memory is Write Protected
#use delay(clock=20000000)
#use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8) |
|
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Tue Nov 06, 2007 5:29 pm |
|
|
Try a very simple test program:
Code: | #include <16F877A.h>
#fuses HS,NOWDT,NOPROTECT,BROWNOUT,PUT,NOLVP
#use delay(clock=20000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, ERRORS)
//============================
void main()
{
char c;
while(1)
{
c = getc();
putc(c);
}
}
|
|
|
|
Jomile
Joined: 06 Nov 2007 Posts: 5
|
|
Posted: Wed Nov 07, 2007 12:09 pm |
|
|
Thanks for the code.
I implemented it and still had the same problem. It turned out that the development board that I am using had a resistor between the max chip and the port. I shorted it out and now its fine.
FOLLOW UP:
When I use your test code and the printf function i can send data the hyperterminal. But when I use the PIC Wizard to make a new project my text gets cut off. For example, if i call printf("start") I get "Sta" in HT. I do not have a wdt enabled. See code below.
MAIN.C
Code: | #include "C:\Program Files\PICC\Projects\11-7-07\main.h"
#include <string.h>
void main()
{
setup_adc_ports(AN0_AN1_AN3);
setup_adc(ADC_CLOCK_INTERNAL);
setup_psp(PSP_DISABLED);
setup_spi(SPI_MASTER|SPI_H_TO_L|SPI_CLK_DIV_4);
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DISABLED,0,1);
setup_comparator(NC_NC_NC_NC);
setup_vref(FALSE);
// TODO: USER CODE!!
printf("Start");
}
|
MAIN.H
Code: |
#include <16F877A.h>
#device adc=8
#FUSES NOWDT //No Watch Dog Timer
#FUSES HS //High speed Osc (> 4mhz)
#FUSES NOPUT //No Power Up Timer
#FUSES NOPROTECT //Code not protected from reading
#FUSES NODEBUG //No Debug mode for ICD
#FUSES NOBROWNOUT //No brownout reset
#FUSES NOLVP //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#FUSES NOCPD //No EE protection
#FUSES WRT_50% //Lower half of Program Memory is Write Protected
#use delay(clock=20000000)
#use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8) |
|
|
|
frequentguest Guest
|
|
Posted: Wed Nov 07, 2007 12:25 pm |
|
|
Your PIC is going to sleep before it finishes transmitting. There is a hidden sleep instruction that is put at the end of main().
Put a while(TRUE); statement after your printf to keep this from happening.
Code: | printf("start");
while(TRUE); |
|
|
|
|
|
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
|