View previous topic :: View next topic |
Author |
Message |
andys
Joined: 23 Oct 2006 Posts: 175
|
Problem with Uart in pic18f45K20 |
Posted: Wed Mar 27, 2013 7:01 am |
|
|
I did the following code to connect the pic18f45k20 with the pc via module max232. What is the problem ? :
Code: |
#include <18F45K20.h>
#FUSES NOWDT //No Watch Dog Timer
#FUSES WDT128 //Watch Dog Timer uses 1:128 Postscale
#FUSES XT //Crystal osc <= 4mhz for PCM/PCH , 3mhz to 10 mhz for PCD
#FUSES PROTECT //Code protected from reads
#FUSES BROWNOUT //Reset when brownout detected
#FUSES BORV18
#FUSES PUT //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)
#FUSES NODELAYINTOSC
#use delay(clock=4000000)
#use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8)
void main()
{
while(1)
{
puts("AAAA");
puts("\n");
puts("HELO");
puts("\n");
printf("ABCD");
puts("\n");
output_low(pin_D0);
delay_ms(450);
output_high(pin_D0);
delay_ms(450);
}
}
|
|
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9246 Location: Greensville,Ontario
|
|
Posted: Wed Mar 27, 2013 7:13 am |
|
|
hard to tell as you do not say what happens, what you expect to happen...
one item..
LVP fuse is selected...
99.999999% of programmers do NOT use this.......
You should try the example that CCS supplies in the examples folder or in the FAQ section of the help files...
hth
jay |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19552
|
|
Posted: Wed Mar 27, 2013 7:31 am |
|
|
Some other comments:
1) Add ERRORS to the RS232 declaration. This must always be used with the hardware UART, unless you do your own error handling code. Without this the UART can get hung.
2) Move the delay to the start of the loop. The capacitors on the max232 take a short time to charge, and you need to allow this to happen before starting to send.
3) You could do the entire output with one printf statement:
Code: |
printf("AAAA\nHELO\nABCD\n");
|
Best Wishes |
|
|
andys
Joined: 23 Oct 2006 Posts: 175
|
Problem with Uart in pic18f45K20 |
Posted: Wed Mar 27, 2013 12:13 pm |
|
|
Ttelmah , according the second
"2) Move the delay to the start of the loop. The capacitors on the max232 take a short time to charge, and you need to allow this to happen before starting to send."
you mean to remove the delay from here :
Code: |
output_low(pin_D0);
delay_ms(450);
output_high(pin_D0);
delay_ms(450);
|
if yes how to create a blinking LED?[/code] |
|
|
ezflyr
Joined: 25 Oct 2010 Posts: 1019 Location: Tewksbury, MA
|
|
Posted: Wed Mar 27, 2013 12:43 pm |
|
|
andys,
I've been biting my tongue ever since I saw you post this new thread this morning...... It seems like we've been down this same road with you before? In fact,
here is the thread: http://www.ccsinfo.com/forum/viewtopic.php?t=49363
But, my god, this question:
Quote: |
if yes how to create a blinking LED?
|
absolutely drove me over the edge...... That question, and many others just like it, have already been covered in your old thread. You sure didn't learn anything that time did you? Frankly, I've written you off as a 'time sink', and a total waste of time!!
Cheers,
John |
|
|
|