C– – Efficiency

Mainasm.asm contains the most complex assembly. It is responsible for initializing assembly variables, enabling or disabling interrupts, and setting up any timers or I/O ports. It also enables the interrupts. The part that is important to the project, _goasm, is called at the beginning of the C–– main routine.

;****************************************************************

;Main program

;Set i/o for any peripherals (eg ADC chip, flash card or LCD)

;and initialize variables as necessary. All user code should

;start here. ;****************************************************************

;clear the seconds passed counter

zac a0

mov *seconds_passed,a0

;Set TIMER2 to run from the RTO/CTO (32 kHz) and with a 1000ms period. Set this by

;loading TIM2 with (32768 x 1000/1000), minus 1.

in

a0,IntGenCtrl

 

 

or

a0,TIM2REFOSC

 

;set bit 9, CTO clock (32 kHz)

and a0,~TIM2ENABLE

 

;clear bit 11, TIM2 enable

out IntGenCtrl,a0

 

 

mov a0,32768 – 1

 

;setup a 250ms period

out TIM2,a0

;load TIM2 and PRD2 in one step

in

a0,IntGenCtrl

 

 

or a0,TIM2IMR + TIM2ENABLE

;set bit 2 (TIM2 interrupt

;enable) and bit 11

 

 

out IntGenCtrl,a0

 

 

inte ret

In this example, it clears seconds_passed, which was used in the first file (timer2_isr.asm), sets up timer2 to run at a 1Hz interval, and enables the interrupts.

The fifth important file is cmm1.asm. This file is responsible for supporting C–– to assembly function calls. It takes parameters passed on the stack, processes them, and returns a 16-bit value in A0. In C–– the 16-bit return value is always of type int.

;****************************************************************

;CMM1.ASM

;Revision 1.00 ;****************************************************************

rorg 0x0

global _getSecondsPassed

include ”ram\ram.irx”

;retrieve the seconds that have passed, and reset the counter _getSecondsPassed

rpt2–2 ; interrupt can still fire for 2 cycles

intd ; leaving these out can cause loss of a second mov a0~, *seconds_passed

zac a0

Code Development Tools

5-43

Page 339
Image 339
Texas Instruments MSP50C6xx manual CMM1.ASM