C Programming for the HC08 Family - PowerPoint PPT Presentation

1 / 14
About This Presentation
Title:

C Programming for the HC08 Family

Description:

Some produce very inefficient code which will use processor resources ... Intel and AMD processors and different generations of a particular brand share ... – PowerPoint PPT presentation

Number of Views:23
Avg rating:3.0/5.0
Slides: 15
Provided by: robynve
Category:

less

Transcript and Presenter's Notes

Title: C Programming for the HC08 Family


1
C Programming for the HC08 Family
  • Up until now we have used assembly programming as
    a way of specifying the operation of the
    microcontroller
  • This has the disadvantage of being rather
    cumbersome to program in
  • High level programming languages such as C
    provide a more natural way of programming
  • C is the most popular high level language for
    microcontrollers

2
C Compilers
  • There are several different C compilers for the
    HC08 family of microcontrollers
  • These include Cosmic, Keil and others
  • Compilers differ in the way that they compile the
    C code and therefore are all not equally as good
  • Some produce very inefficient code which will use
    processor resources

3
C Compilers Cont.
  • C compilers do have some disadvantages
  • These include the following
  • They are expensive, there are some free compilers
    but these often have limited functionality
  • In the case of the HC(S)08 family they limit
    their final code size to 16kB (this is the same
    size as the GT16s flash)
  • They also often limit the number of files you can
    have per project
  • In order to keep you code efficient you need to
    make sure you know which data types you are using
    and how these are translated into machine code
  • The C complier which we will be using is the
    CodeWarrior C compiler

4
PC Platform
  • We have seen how a program compiles on a PC
    platform, we now need to consider the differences
    between the process on the PC and a
    microcontroller
  • PCs have an operating system which most
    microcontrollers do not. This is used to organise
    and arrange files etc.
  • There is also a lot of standardisation of
    hardware in PCs
  • Intel and AMD processors and different
    generations of a particular brand share the same
    instruction sets and address modes
  • This means that C compilers for PCs are
    relatively easy to set up

5
Microcontroller Platform
  • Microcontrollers are some what different to PCs
  • There are many different families which require
    different compilers because they each have their
    own instruction set and addressing modes
  • Within these families there are many different
    variants each with their own memory maps,
    peripheral sets and hardware
  • For this reason the compiler needs to be
    configured correctly
  • There isnt one setup for all microcontrollers

6
Process of Compilation
  • Setting up the compiler requires some knowledge
    of the process of compilation
  • The basic steps are shown here
  • Code editor ? Compiler ? Assembler ? Linker ?
    Flash Programming/Debugger

7
Code Editor
  • The code editor is where you edit and write you
    code
  • This include source and header files
  • This is done in the CodeWarrior Environment for
    the GT16 microcontroller

8
Compiler
  • A compiler converts each file in your program
    into assembly code
  • The assembly files produced by the compiler
    usually have the extension .lst
  • These files can be viewed using a text editor
  • Sometimes this maybe useful in debugging and
    improving the efficiency of your code

9
Assembler
  • The assembler takes all of the assembly files
    produced by the compiler and converts them to a
    machine code output.
  • These files are called object files and have an
    .o extension

10
Linker
  • The linker file is used to tie all of the object
    code files together to create one set of linked
    code
  • All cross references are checked and tied
    together
  • All of the symbolic labels, variable names etc
    are converted into absolute addresses
  • All C library references are tied together

11
Linker
  • The linker needs to know several things about
    your system
  • It needs to know where to place code in memory
  • This means it needs to know where you Flash
    memory is located
  • It also needs to know where to place variables
  • And where to place the interrupt vector table
  • It then needs to know which files to link
    together
  • All of this information is stored in the linker
    parameter file which has the file extension .prm

12
Linker File
  • / This is a linker parameter file for the GT16
    /
  • NAMES END / CodeWarrior will pass all the needed
    files to the linker by command line. But here
    you may add your own files too. /
  • SEGMENTS / Here all RAM/ROM areas of the device
    are listed. Used in PLACEMENT below. /
  • ROM READ_ONLY 0xC000 TO 0xFBAF
  • Z_RAM READ_WRITE 0x0080 TO 0x00FF
  • RAM READ_WRITE 0x0100 TO 0x047F
  • ROM1 READ_ONLY 0xFFC0 TO 0xFFCB
  • END
  • PLACEMENT / Here all predefined and user
    segments are placed into the SEGMENTS
    defined above. /
  • DEFAULT_RAM INTO
    RAM
  • DEFAULT_ROM, ROM_VAR, STRINGS INTO
    ROM / ROM1 In case you want to use ROM1 as
    well, be sure the option -OnBb is passed to
    the compiler. /
  • _DATA_ZEROPAGE, MY_ZEROPAGE INTO
    Z_RAM
  • END
  • STACKSIZE 0x50
  • VECTOR 0 _Startup / Reset vector this is the
    default entry point for an application. /

13
Segments Directive
  • As you can see this is not a C file
  • The syntax and keywords are defined by
    CodeWarrior
  • The segments directive is used to define a
    segment of memory
  • There are various types of memory segments. These
    include
  • ROM This is read only flash memory where your
    program is stored (C000 to FFAF)
  • Z_RAM This is the direct page or zero page RAM,
    this area of RAM is used for variable storage. It
    is therefore read/write memory. (0080-00FF)
  • RAM This refers to the entire RAM space on the
    micro which does not fall within the direct page
  • ROM1 This is a small piece of flash memory just
    below the interrupt vector table

14
Other Directives
  • The placement directive specifies which parts of
    the code go into which segments
  • The stacksize directive tells the linker how much
    space to allocate for the stack. This can be
    modified
  • The VECTOR 0_Startup line specifies the 0th
    vector in the interrupt table
  • This means that when the GT16 starts up it will
    go into a piece of code called _startup
Write a Comment
User Comments (0)
About PowerShow.com