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

Programming the 18f452

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



Joined: 17 Nov 2003
Posts: 7

View user's profile Send private message

Programming the 18f452
PostPosted: Wed Jan 28, 2004 6:07 am     Reply with quote

I’m trying to transfer a program from PIC 16F627 to PIC 18F452 and I’m having some trouble. All I want to do at the minute is set up a simple serial connection to the computer. I have it set up with a 20Mhz crystal and I’m using the same circuit board we set up for the 16f627. I think that should be ok, it’s a MAX232 to do the level shifting and we’re running the PIC at around 3.5 to 4 V

The program is :

#include <18f452.h>
#include <stdio.h>

#fuses nowdt,noprotect,hs
#FUSES NOBROWNOUT,NOLVP

#use delay (clock=20000000)

#define PC_RATE 19200
#define PC_TXD pin_b5 // RS232 Transmit
#define PC_RXD pin_b4 // RS232 Receive

#use rs232(baud = PC_RATE, xmit = PC_TXD, rcv = PC_RXD, bits = 8, ERRORS, stream = PC)

void put_PC(int8 c);

void put_PC (int8 c)
{
int high, low;

high = 0xf & (c >> 4);
low = 0xf & c;

if (high<=9)
{
fputc(48+high, PC);
}

else
{
fputc(55+high, PC);
}
delay_ms(1);

if (low<=9)
{
fputc(48+low, PC);
}

else
{
fputc(55+low, PC);
}

delay_ms(1);

fputc(0x20, PC); //puts a space between each of the hex numbers
delay_ms(1);
}

void main(void)
{
put_PC(0x20);

for (;;)
{
put_PC(0x20);
}
}



It should be really simple but it’s just not doing what it should. It works fine on the 16f627. Are there things to conisder when transferring designs from one device to another?

Can you help, I’m really stuck.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Jan 28, 2004 1:01 pm     Reply with quote

I'm feeling feisty this morning, so I will do a "strict regime"
commentary on your post. Smile

Quote:
We’re running the PIC at around 3.5 to 4 V

According to the 18Fxx2 data sheet, in Figure 22-1, the
18F452 requires a minimum Vdd of 4.2v to run at any frequency.
So 3.5v to 4v is out of spec. You have to use the "LF" part
to run at less than 4.2v (See figure 22-2).

Quote:
it’s a MAX232 to do the level shifting

What voltage are you running the MAX232 at ?
According to the MAX232 data sheet the minimum supply
voltage is 4.5v.

Quote:
#define PC_TXD pin_b5 // RS232 Transmit
#define PC_RXD pin_b4 // RS232 Receive

The 18F452 has a hardware USART on pins C6 and C7.
I would use it.

Quote:
#use rs232(baud = PC_RATE, xmit = PC_TXD, rcv = PC_RXD, bits = 8, ERRORS, stream = PC)

You're using the ERRORS directive, but it has no effect with a
software USART.

Quote:
void put_PC(int8 c);
etc.

When bringing up a new chip, I would do everything as simply
as possible. I would use this "one liner", instead of your routine:
printf("%x", c);

Quote:
void main(void)
{
put_PC(0x20);

for (;;)
{
put_PC(0x20);
}
}

Here, in your main routine, you're not even calling your putc_PC()
routine. All you're doing is putting out spaces. You wouldn't see
any characters on the terminal window. This could give the
appearance that the program is not working.
kennethkearney



Joined: 17 Nov 2003
Posts: 7

View user's profile Send private message

PostPosted: Wed Jan 28, 2004 3:06 pm     Reply with quote

Thanks PCM Programmer.

I'm not sure about the voltage (Vdd) thing, don't have the data sheet in front of me.

The max 232 is tried and tested, I didn't design the circuit but the output voltages are correct and it's the same circuit we used to power a PIC 16F627 we used to use so I presume it's ok (dangerous assukmption I know)

The put_PC() command is a function I made up myself. It doesn't output the ASCII(0x20) but the number 20. It takes each nibble and does a conversion according to the ASCII table and that's how it works.

As far as the program itself is concerned, today I found out that there's a bug in the CCS compiler in that it doesn't like PIC18 code too much. I'm using an older version and there's a bug in the assembler I think. I saw some threads on this site relating to it. When I leave out the 'for' loops, the program works fine but when we introduce any kind of loop, it crashes.

Don't know exactly why this is, will have to look into it further. Has anyone heard of this before and is there a fix? I bought the software in 2002 so my update period is long over, don't want to have to spend another $450 just to be able to use PIC18 devices!!

Any help would be great
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Jan 28, 2004 3:29 pm     Reply with quote

Do you have PCH or PCWH ? What version are you using ?

You could order the one-year's maintenance for less than
buying a new compiler. Check the prices on this page:
http://www.ccsinfo.com/ccscorder.shtml
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