Maker Pro
Maker Pro

Motorola 68Hc08 programming help

M

Marcel R.

Jan 1, 1970
0
Hi
I'm trying to create a robot that i will be able to program with a Motorola
68HC08 MCU, I have allready done some projects like this using the same MCU
but programming it in Assembly, I would like to try and program it in C this
time, but I can't find information on how to load/store some stuff from the
accumulator, or change regestry values is there anyone that could give me
some information on how to program the MCU in C language?
Thanks
e-mail backlash15@*nospamplease*hotmail.com
or reply to the post
 
N

News 2 Me

Jan 1, 1970
0
Marcel said:
Hi
I'm trying to create a robot that i will be able to program with a Motorola
68HC08 MCU, I have allready done some projects like this using the same MCU
but programming it in Assembly, I would like to try and program it in C this
time, but I can't find information on how to load/store some stuff from the
accumulator, or change regestry values is there anyone that could give me
some information on how to program the MCU in C language?

If you are programming in C, you don't have to worry about what is in
the accumulator or the registers. That is one of the benefits of using
a higher level language: you don't have to be aware of the CPU
architecture, although it often makes your C code more efficient if you
are, especially with simple, 8-bit CPUs. What is it you are trying to
do in C that requires you to manipulate the CPU registers?

NM
 
M

Marcel R.

Jan 1, 1970
0
Actualy I guess maybe I do not need to manipulate the registers or
accumulator, all i need to do realy is be able to control the ports, i need
to be able to read if there is a Vcc applied to certain pins of a port and
then from what is entendered in one port change the values of an other port,
but to do that wouldn't i need to change the values of the registers that
control the ports?
Thanks

Marcel
 
N

News 2 Me

Jan 1, 1970
0
Marcel said:
Actualy I guess maybe I do not need to manipulate the registers or
accumulator, all i need to do realy is be able to control the ports, i need
to be able to read if there is a Vcc applied to certain pins of a port and
then from what is entendered in one port change the values of an other port,
but to do that wouldn't i need to change the values of the registers that
control the ports?

How you declare the I/O registers depends on the C compiler you are
using. For the open-source SDCC compiler, you do it like this:

volatile unsigned char __at 0x00 PORTA;
volatile unsigned char __at 0x04 DDRA;

For the Metrowerks CodeWarrior compiler, it's like this:

volatile unsigned char PORTA _IO_AT(0x00);
volatile unsigned char DDRA _IO_AT(0x04);

SDCC is free. There is a demo version of CodeWarrior available for free
that will do up to 4K of object code and a maximum of 16 sources files,
IIRC. If you're using another C compiler, RTFM. Both SDCC and
CodeWarrior have header files that define all the registers, so all you
need to do is something like:

#include "mc68hc908gp32.h"

to define all the I/O registers for the GP32. Once you have declared
your I/O registers, it's as easy as:

unsigned char somevar; /* declare an unsigned char */
DDRA = 0x00; /* make Port A an input port */
somevar = PORTA; /* read the value on Port A */
DDRA = 0xFF; /* make Port A an output port */
PORTA = 0xAA; /* output alternating 1s & 0s to Port A */

Hope this helps.

NM
 
M

Marcel R.

Jan 1, 1970
0
Thanks ALOT! NM
I should be able to make some sence out of it, I'm just wondering like when
you put something like 0x00 it represents 8 bits? so like you said 0xAA
would be 10101010 wherever i put that, so if I put DDRA = 0xAA pin 0,2,4,6
will be output and 1,3,5,7 input?
Thanks again this is finaly starting to make a bit of progress! :)
Marcel
 
N

News 2 Me

Jan 1, 1970
0
Marcel said:
Thanks ALOT! NM
I should be able to make some sence out of it, I'm just wondering like when
you put something like 0x00 it represents 8 bits? so like you said 0xAA
would be 10101010 wherever i put that, so if I put DDRA = 0xAA pin 0,2,4,6
will be output and 1,3,5,7 input?

Freescale got it backwards: 1 = Output and 0 = Input. So putting 0xAA
in DDRA makes the even bits inputs and the odd bits outputs.

How many bits a variable (or register) contains depends on how it is
declared.

unsigned char var1; /* var1 is 8 bits */
unsigned short int var2; /* var2 is probably 16 bits, RTFM */
unsigned int var3; /* var3 might be 16 bits, RTFM */
unsigned long int var4; /* var4 is probably 32 bits, RTFM */

With standard C, shorts are 16 bits, ints are 32 bits, and longs are 64
bits, but C compilers for smaller 8-bit and 16-bit CPUs tend to deviate
from standard C making shorts and ints 16 bits and longs 32 bits, due to
smaller CPUs having to work harder with larger bit sizes. As always,
Read The Fine Manual for your C compiler.

With constants, as long as the value fits into the variable, things will
be fine:

var4 = 0xAA; /* sets var4 to 0x000000AA */
var2 = 0x55; /* sets var2 to 0x0055 */
var1 = 0xAAAA; /* generates a compile-time error, as you can't
fit a 16-bit value into a 8-bit variable. */

Or you could make the constant the size of the variable as a reminder as
to the size of the variable:

var4 = 0x000000AA;
var2 = 0x0055;

NM
 
N

News 2 Me

Jan 1, 1970
0
Marcel said:
Thanks ALOT! NM
I should be able to make some sence out of it, I'm just wondering like when
you put something like 0x00 it represents 8 bits? so like you said 0xAA
would be 10101010 wherever i put that, so if I put DDRA = 0xAA pin 0,2,4,6
will be output and 1,3,5,7 input?

PS: You should look at the header files for the C compiler you are
using. They are probably in a directory like <install
path>\lib\include. These will show you how to declare registers and
even the individual bits in them. If you don't already have a compiler,
download SDCC from http://sdcc.sourceforge.net/ and take a look at the
header files. SDCC is relatively small (~5MB) and has header files to
declare the registers on four or five Freescale MCUs. Codewarrior has
include files for almost every Freescale MCU, as well as a ton of other
features, but it is a HUGE download (~150 MB), so unless you have
broadband, don't even think about it.

NM
 
Top