Specifications

42
This section of code is simply written to show and name all of the available addresses of
ports etc inside the Motorola HC12. Credit for this section of code goes to Mr Terry
Byrnes. The rest of the program then references these address names for ease of
reading, understanding and debugging. For instance the code to output hexadecimal 10
would be MOVB #$10, PORTA
This is much easier to understand than a code that says
MOVB #10, $00
Without knowing the addresses of every single port it would be near impossible to
decipher the assembly language code.
4.6.2 Variable Definition
The next step in the code is variable definition. This simply defines all of the variables
that will be used throughout the program and defines a location for their storage in
memory. The variables start at address $0200 and list onwards from this address.
;*************VARIABLE DEFINITION***********************************
ORG $0200 START DEFINITION AT ADDRESS $0200
ODMA DC.B 0
ODMB DC.B 0 ;DEFINE VARIABLES
COUNT DC.B 0
4.6.3 Main Program
After variable definition is the main program control loop. This section is responsible
for initialising all of the hardware and ports. The bottom tight loop is responsible for
ensuring the robot drives straight and also that the sensors are checked frequently for
object detection.
;**************MAIN PROGRAM..CONTROL LOOP************************
;NOTE: NO ACTION WILL OCCUR UNTIL THE IRQ INTERRUPT IS ACTIVATED UNLESS
FRONT SENSOR IS TRIGGERED
ORG $0400 ;START PROGRAM STORE AT $0400
MAIN LDS #$0700 ;SET STACK POINTER