|
|
View previous topic :: View next topic |
Author |
Message |
Guest
|
RS232 Dosn't work on PIC18F4520 Development Kit |
Posted: Thu Apr 24, 2008 2:04 pm |
|
|
Can't seem to get the Rs232 port to work correctly. I have the CCS PIC18F4520 Development Kit (prototype board).
The following code will compile and execute, but I don't get the results I expect. Using Hyperminal (9600-N-1-8) with the supplied CCS RS232 cable, I can run the program and the GREEN LED turns on and waits for a kbhit. So far so good. Then I tap any key on the heyboard and the YELLOW LED turns on. Great ! But the key that I tap is not the ASCII data I see in the debugger ( variable char c). I get garbage. Also... nothing on the Hyperterminal screen (I guess since the data is garbage and non printable).
I have also tried using printf putc, etc. No luck.
It's gotta be something simple. Any suggestions ?
Marc
Here's the C code:
#include "main.h"
#define GREEN_LED PIN_A5
#define YELLOW_LED PIN_B4
#define RED_LED PIN_B5
void main()
{
char c;
c = 'K';
output_low(GREEN_LED);
setup_wdt(WDT_OFF);
setup_timer_0(RTCC_INTERNAL);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DISABLED,0,1);
setup_timer_3(T3_DISABLED|T3_DIV_BY_1);
while(TRUE)
{
if(kbhit(L1) )
{
output_low(YELLOW_LED);
c = getc(L1);
fputc('D',L1);
}
}
}
// HERE'S My Inlcude File
/****************************************
#include <18F4520.h>
#device ICD=TRUE
#device adc=8
#FUSES NOWDT //No Watch Dog Timer
#FUSES WDT128 //Watch Dog Timer uses 1:128 Postscale
#FUSES LP //Low power osc < 200 khz
#FUSES NOPROTECT //Code not protected from reading
#FUSES BROWNOUT //Reset when brownout detected
#FUSES BORV20 //Brownout reset at 2.0V
#FUSES NOPUT //No Power Up Timer
#FUSES NOCPD //No EE protection
#FUSES STVREN //Stack full/underflow will cause reset
#FUSES NODEBUG //No Debug mode for ICD
#FUSES LVP //Low Voltage Programming on B3(PIC16) or B5(PIC18)
#FUSES NOWRT //Program memory not write protected
#FUSES NOWRTD //Data EEPROM not write protected
#FUSES IESO //Internal External Switch Over mode enabled
#FUSES FCMEN //Fail-safe clock monitor enabled
#FUSES PBADEN //PORTB pins are configured as analog input channels on RESET
#FUSES NOWRTC //configuration not registers write protected
#FUSES NOWRTB //Boot block not write protected
#FUSES NOEBTR //Memory not protected from table reads
#FUSES NOEBTRB //Boot block not protected from table reads
#FUSES NOCPB //No Boot Block code protection
#FUSES LPT1OSC //Timer1 configured for low-power operation
#FUSES MCLR //Master Clear pin enabled
#FUSES NOXINST //Extended set extension and Indexed Addressing mode disabled (Legacy mode)
#use delay(clock=20000000,RESTART_WDT)
#use rs232(stream=L1,baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8)
*************************************/ |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Thu Apr 24, 2008 2:16 pm |
|
|
Quote: | #FUSES LP //Low power osc < 200 khz |
Change this to the HS fuse. Notice the comment.
You want to run at 20 MHz. You can't use the LP fuse to do that.
The HS ("High Speed") oscillator fuse is required.
Change this to NOLVP. Do that in all your programs. |
|
|
|
|
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
|