CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

Problem with Uart in pic18f45K20

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
andys



Joined: 23 Oct 2006
Posts: 175

View user's profile Send private message

Problem with Uart in pic18f45K20
PostPosted: Wed Mar 27, 2013 7:01 am     Reply with quote

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: 9182
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Wed Mar 27, 2013 7:13 am     Reply with quote

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: 19390

View user's profile Send private message

PostPosted: Wed Mar 27, 2013 7:31 am     Reply with quote

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

View user's profile Send private message

Problem with Uart in pic18f45K20
PostPosted: Wed Mar 27, 2013 12:13 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Wed Mar 27, 2013 12:43 pm     Reply with quote

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
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
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