|
|
View previous topic :: View next topic |
Author |
Message |
jackie Guest
|
problem reading characters with getc() |
Posted: Tue Jan 11, 2005 11:16 am |
|
|
Can you help?
I am trying to read data using the getc() function. However I try the program simply waits at the command and never detects a character. To test the program, I programmed a PIC to constantly send out characters, and they are detected fine using hyperterminal, but when I try reading them with my program...NOTHING!
I have set the baud rate at 19200 and am using a 16MHz crystal. Here is the code...
// Standard Header file for the PIC16C74 device //
#include <C:\Program Files\PICC\Devices\16C74.H>
#fuses HS,NOPROTECT,NOWDT
//crystal settings
#use delay(clock=16000000)
#byte portb=6
#byte portc=7
//rs232 port setup
#use rs232(baud=19200,xmit=pin_c6,rcv=pin_c7,parity=n,RESTART_WDT)
// include LCD code
#include <C:\Program Files\picc\res\lcd_d.c>
int i;
char myChar;
void get(){
myChar = getc();
}
void send(){
lcd_gotoxy(i,1);
lcd_putc(myChar);
}
main(){
set_tris_c(0b01000000);
i = 1;
myChar = 'S';
//init lcd
lcd_init();
lcd_putc("\f");
send();
do{
get();
send();
i=i+1;
if (i>16){
i=1;
lcd_putc("\f");
}
delay_ms(100);
}while(true);
}
------------------------
Cheers, jackie x |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Tue Jan 11, 2005 12:06 pm |
|
|
Your program is too complicated for a test program.
You said that you have it working with the PIC transmitting
characters to the PC. Get it working both ways with
the PC. The following test program will echo any
character received from the PC back to the PC.
Try it.
Code: | #include <16C74.H>
#fuses HS, NOWDT, NOPROTECT, PUT
#use delay(clock=16000000)
#use rs232(baud=19200, xmit=PIN_C6, rcv=PIN_C7, ERRORS)
void main()
{
char c;
while(1)
{
c = getc(); // Wait for a char from the PC
putc(c); // Then send it back to the PC
}
} |
|
|
|
|
|
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
|