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
Didn't find your answer? Ask the community — no account required.
N
News 2 Me
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.
N
News 2 Me
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:
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.
N
News 2 Me
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
PS: You should look at the header files for the C compiler you are using. They are probably in a directory like \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
formatting link
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
Join the Discussion
Have something to add? Share your thoughts — no account required.
Didn't find your answer?
Ask the community — no account required
Report Content
You are reporting this content to the moderators. They will look at it
ASAP.