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

Pic18F452 and Serial (USART) and PicDem2 Plus

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







Pic18F452 and Serial (USART) and PicDem2 Plus
PostPosted: Fri Jul 15, 2005 10:40 am     Reply with quote

Hi all,

I'm sure this has been asked a million times, and I did look in the forum, but could not get a 100% answer...

Here is my setup:

#1. Microchip PicDem2 Plus board w/Pic18F452
#2. I am NOT uisng the J7 jumper (4.0 chrystal), so it is inactive(?)
#3. Using CCS Windows compilers.

When I run my sample program, it pushed data to the serial, but junk! If I use the slower speed in delay (2000000) I only see the high nibble, if I set the delay to 4000000, I see all 8 bits but junk!

Any thoughts?!

Code:


#include <18F452.h>

#fuses HS,NOWDT,NOPROTECT,NOLVP
//#use delay(clock=20000000)
#use delay(clock = 3686400)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, parity=N, bits=8)

void main()
{
    while(TRUE)
    {
      printf("Kam Was Here!!");
      delay_us(1000);
    }
}


Any help, advice and suggestions would be GREATLY appriciated!

~Kam (^8*
MikeValencia



Joined: 04 Aug 2004
Posts: 238
Location: Chicago

View user's profile Send private message Send e-mail Yahoo Messenger

PostPosted: Fri Jul 15, 2005 11:20 am     Reply with quote

J7 is only used if you have that huge oscillator. If u have a crystal, then yes, you would keep it off.

You know what the problem is? Your PIC goes to sleep before your done RS232'ing. (Sleep is the instruction inserted by CCS at the end)

Try replacing your delay_us() instruction with a "while (1);" instruction. It should take care of it for you.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Jul 15, 2005 11:30 am     Reply with quote

On the PicDem2-Plus, jumper J7 enables or disables the External RC
oscillator components, which are R4 and C3.

The PicDem2-Plus comes with a 4.0 MHz oscillator in location Y2.
This looks like a rectangular metal can. Normally, this is the
oscillator that you should use. The only way to disable it is
by removing it from the socket. Hopefully, you have it installed.

There is one very important idea you need to know. The speed
of the PIC is not set by the #use delay() statement speed. It is
set by the crystal or oscillator that you are using. The #use delay()
statement should be set to the same speed as the oscillator on the
PicDem2-Plus board. You need to set it like this:
Code:
#use delay(clock=4000000)
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Jul 15, 2005 11:36 am     Reply with quote

Quote:
J7 is only used if you have that huge oscillator. If u have a crystal, then yes, you would keep it off.

Go here, and download the PicDem2-Plus User's Guide.
http://ww1.microchip.com/downloads/en/DeviceDoc/51275b.pdf
Go to page 19 and zoom in on the right side of the schematic.
Note that oscillator Y2 is always connected to the PIC.
Jumper J7 connects or disconnects the junction of R4-C3 to
the PIC. J7 controls whether or not the External RC oscillator
is to be used. Oscillator Y2 can only be disabled by pulling it out
of its socket.
kam



Joined: 15 Jul 2005
Posts: 59

View user's profile Send private message

Hmmm....
PostPosted: Fri Jul 15, 2005 11:45 am     Reply with quote

Thanks all for the replies...

I have the oscillator on y2, and the jumper on J7 is off, and I do NOT have anything attached to C4...

Thanks for the delay definition, I did assume it was mapped to the chip speed! Thanks.

Now, when I run my sample program (above) with the delay of 4000000, I see chars but they are garbage...I can run an asm sample, and it works just fine (same cable, same terminal etc)...

Any thoughts?

~Kam (^8*
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Jul 15, 2005 11:52 am     Reply with quote

Read the label printed on the top of oscillator Y2. Does it say that
it's 4.0 MHz ? I got a 4.0 MHz oscillator with my PicDem2-Plus board,
but it's possible that Microchip could change it. So check it to be sure.

Also, count the number of zeros in your #use delay statement.
Make sure there are 6 zeros after the 4.
#use delay(clock=4000000)
Guest








PostPosted: Fri Jul 15, 2005 12:06 pm     Reply with quote

MikeValencia wrote:
J7 is only used if you have that huge oscillator. If u have a crystal, then yes, you would keep it off.

You know what the problem is? Your PIC goes to sleep before your done RS232'ing. (Sleep is the instruction inserted by CCS at the end)

Try replacing your delay_us() instruction with a "while (1);" instruction. It should take care of it for you.


EDITED:
Oops. i see that you are already in a WHILE(TRUE) loop
kam



Joined: 15 Jul 2005
Posts: 59

View user's profile Send private message

yippeeee!
PostPosted: Fri Jul 15, 2005 12:28 pm     Reply with quote

Okay,

I had made an error in the speed! I had an extra 0!

Thanks everyone!

~Kam (^8*
Mark



Joined: 07 Sep 2003
Posts: 2838
Location: Atlanta, GA

View user's profile Send private message Send e-mail

PostPosted: Fri Jul 15, 2005 2:06 pm     Reply with quote

Anonymous wrote:
MikeValencia wrote:
J7 is only used if you have that huge oscillator. If u have a crystal, then yes, you would keep it off.

You know what the problem is? Your PIC goes to sleep before your done RS232'ing. (Sleep is the instruction inserted by CCS at the end)

Try replacing your delay_us() instruction with a "while (1);" instruction. It should take care of it for you.


EDITED:
Oops. i see that you are already in a WHILE(TRUE) loop


Remember that login edit/delete thing Very Happy
MikeValencia



Joined: 04 Aug 2004
Posts: 238
Location: Chicago

View user's profile Send private message Send e-mail Yahoo Messenger

PostPosted: Fri Jul 15, 2005 4:39 pm     Reply with quote

Remember that login edit/delete thing Very Happy[/quote]

That is why from now on I will try not to post as "valemike", for which I forgot my password, email address to retrieve it is long lost too, etc.
Mark



Joined: 07 Sep 2003
Posts: 2838
Location: Atlanta, GA

View user's profile Send private message Send e-mail

PostPosted: Fri Jul 15, 2005 4:41 pm     Reply with quote

I just set mine to auto and forget about it Smile
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