Code Module #1 - Delay Millisecond Subroutine

EMICROS - Embedded Micro Software, Last Update: 11/08/08

Introduction
This module introduces the tools for developing software for the CANTEC11 board. 
Assembler
The software for the CANTEC11 is written in assembly language and uses the 68HC11 Freeware Assembler AS11.EXE (click here to download). Instructions for assembling each code module is contained in the header comments (first section of the file).
Delay Millisecond Introduction
The first subroutine we will look at is a subroutine to delay a certain number of milliseconds. This is a simple example and is intended to aquaint the user with the CANTEC11 Development System.

The requirements for the subroutine are as follows;

  • Register B contains the number of milliseconds to delay
  • Instruction cycles are counted for delay, no timers are used
  • Interrupts are not disabled
  • Registers used in the subroutine must be restored
Delay Millisecond Subroutine
*---------------------------------------------------------
* subroutine:	DelayMilliSec
* description:	This subroutine delays the number of 
*		milliseconds specified in B.
* input:		B = #milliseconds
* output:		B = 0
* uses:		X used as counter, stack saved/restored
*
* Notes:		Loop multiplier is .001sec/InnerLoopTime
*		InnerLoopTime = 8 cycles/2mhz = 4 usec
*		Loop multiplier = .001/.000004 = 250
*---------------------------------------------------------
DelayMilliSec
	pshx		* 4 * Save X register
dm1	ldx	#250	* 3 * Set loop multiplier
dm0	dex		* 3 * Decrement the loop counter
	nop		* 2 * Use time so loop counter is integer
	bne	dm0	* 3 * Branch if loop counter not 0
	decb		* 2 * Decrement the millisecond counter
	bne	dm1	* 3 * Branch if not 0
	pulx		* 4 * Restore X register
	rts		* 5 * Return from subroutine
Delay Millisecond Test Program
The delay.src file contains a test program that executes the DelayMilliSec subroutine to flash the LED at a 5 hz rate. Assemble the program using AS11.EXE and download to the CANTEC11 board using the CANTEC11 Downloader.

Last Update: 11/08/08