AnsweredAssumed Answered

CodeWarrior 8- & 16-bit tools: HC08 Instructions

Question asked by Marc Paquette Employee on Jan 27, 2006
To help you find solutions to problems that have already been solved, we have posted this message. It contains an entire topic ported from a separate forum. The original message and all replies are in this single message.
 
Posted: Mar 02, 2005 - 08:43 PM 
 
Hi I'm Begining with CW3.0. I need to know where to find the instructions to program the GP32. Some one told me to use an ANSI C manual but I cant find commands to check if a bit is set or clear or to rotate the byte or rutines to write the eeprom.
 
Does any one know where to find this?

 
Posted: Mar 03, 2005 - 06:50 AM   
 
You need to read Freescale manuals - the CPU08 Reference for the assembly code and the user data guide for the GP32. Probably the easiest way for you to get these would be to register at Freescale.com and access the Embedded Learning Center.
 
The multimedia online HC08 tutorial has links to downloading both of the two guides that you need on one of the early slides - the second, I think.
_________________
Gary Schnabl
(Southwest) Detroit - 2 miles NORTH! of Canada -- Windsor, that is...

 
Posted: Mar 03, 2005 - 09:05 PM   
 
Thanx but Waht about the C instructions? how to set or clear a bit in a register and how to write a byte in the ee memory? Where can I find the rutine to write a byte in the eeprom?
 

 
Posted: Mar 03, 2005 - 09:09 PM   
 
if i can set multiple bits with the following instruction, how can I clear multiple?
T2SC = TOIE | TSTOP | TRST | Prescaler_by_1

 
Posted: Mar 03, 2005 - 10:01 PM   
 
Hi
In your example
Quote:
T2SC = TOIE | TSTOP | TRST | Prescaler_by_1;
 

you are setting AND clearing bits - ie the ones you don't set, you end up clearing.
If you want to set these and leave the others alone you should do something like
T2SC |= TOIE | TSTOP | TRST | Prescaler_by_1;

If you wanted to clear the same bits you would do:
T2SC &= ~(TOIE | TSTOP | TRST | Prescaler_by_1);
The only thing to be careful about is how good the optimiser is, I would generally do this:
T2SC &= (unsigned char)~(TOIE | TSTOP | ...etc.);
The reason being that some compilers extend the result of the complement operation to an int and you end up with wasted ROM.
Can't answer your question regarding EEPROM - I don't know if Metrowerks supports this directly. Generally speaking I roll my own because then I have more control over its interaction with my architecture.
Hope this helps a little.
Colin H

 
 Mar 03, 2005 - 10:08 PM   
 
Quote:
Thanx but Waht about the C instructions? how to set or clear a bit in a register and how to write a byte in the ee memory? Where can I find the rutine to write a byte in the eeprom?
 
For that you can go to the Metrowerks site for the HC08 and get the 60 MB of CW_Examples:
http://www.metrowerks.com/MW/Develop/Embedded/HC08/Downloads >> Self-installing Examples.
After you make that installation you should navigate to:
...(CodeWarrior_Examples)\HC08\Tutorials\C_for_Embedded_Systems
There you will find a PowerPoint presentation for C and a folder containing 15 Labs for you to work on and keep you busy...
With what I suggested, you should have

(1) the manual for the assembly code
(2) the CP32 data book
(3) A PPT about C programming with CodeWarrior
(4) over a dozen programming labs
 
The next thing that you should do is to download version 3.1 as an upgrade for your version 3.0. I'd do that first. I believe that those CW_Examples I pointed out are probably already preinstalled in the download version. You now know where they would be in that case.
_________________
Gary Schnabl
(Southwest) Detroit - 2 miles NORTH! of Canada -- Windsor, that is...

 
Posted: Oct 03, 2005 - 07:47 PM   
 
Examples:
PTB^=0x02; //toggle the bit 1 port b , change the state
*******************
T1SC1&=(~0x80); //-- to deactivate the interrupt flag in timmer 1 channel 1
**********************
while(!(SCS1 & 0x20)); // to wait a '1' in Flag (Bit 5) in SCS1 reg
*******************

 
Posted: Oct 04, 2005 - 03:48 AM   
 
Just be careful with those bitwise |= assignments when clearing status/flag registers by writing 1 to a bit! (Such as timer flag registers). The compiler will probably use read-modify-write and destroy every flag in the register. The correct way of clearing such a flag is to write
 
REGNAME = 0x01;
 
Not ANSI C, but what can you do... 
 

Outcomes