Here is more detail about my problem, First I want to focus on issue 1, adding an offset to the return value.
Information on the compiler:
ANSI-C/cC++ Compiler for HC08 V-5.0.24 Build 7134, May 15 2007
Common Module V-5.0.8, Date May 15 2007
User Interface Module, V-5.0.25, Date May 15 2007
ANSI-C/cC++ Front End, V-5.0.6, Date May 15 2007
Tree CSE Optimizer, V-5.0.1, Date May 15 2007
Compiler Common Module, V-5.0.1, Date May 15 2007
Generic ICG Back End V-5.0.2, Date May 15 2007
Compiler Back Common, V-5.0.2, Date May 15 2007
HC08 ICG Back End V-5.0.24, Date May 15 2007
Encryption Module, V-5.0.3, Date May 15 2007
Info on the Target:
The code is targeted toward a MC68HC908QY4 8 bit micro.
Here are the code files.
SysClock.c
-------------------------------------------------------------------------------------------------
/*****************************INCLUDE*******************************/
#include "MC68HC908QY4.h"
#include "SysClock.h"
/*****************************Variables******************************/
static unsigned long SystemClock = 0;
/*****************************Defines********************************/
#define emulator
/*******************************CODE*********************************/
void SysClockInit(void){
SystemClock = 0;
//Setup the overflow counter for 10 milliseconds
#ifdef emulator
TMOD = 14050;
#else
TMOD = 32000;
#endif
//Setup the TSC register
TSC_TSTOP = 0;
TSC_TOF = 0;
TSC_TSTOP = 1;
TSC_TRST = 1;
TSC_TOIE = 1;
TSC_TSTOP = 0;
} //End void SysClockInit(void)
unsigned long GetSysMSec(void){
return(SystemClock);
} //End unsigned long GetSysMSec(void)
void interrupt VectorNumber_TIMOvr TimOverflow(void){
SystemClock += 10;
TSC_TOF = 0;
} //end void interrupt VectorNumber_TIMOvr TimOverflow(void)
-------------------------------------------------------------------------------------------------
SysClock.h
-------------------------------------------------------------------------------------------------
#ifndef __SysClock_h__
#define __SysClock_h__
void SysClockInit(void);
unsigned long GetSysMSec(void);
void interrupt VectorNumber_TIMOvr TimOverflow(void);
#endif
-------------------------------------------------------------------------------------------------
main.c
-------------------------------------------------------------------------------------------------
/***************************************Defines*********************************/
#define emulator
/***************************************Includes**********************************/
#include <hidef.h> /* for EnableInterrupts macro */
#include "derivative.h" /* include peripheral declarations */
#include "TypeDefs.h"
/******************************Module Includes***********************************/
#include "main.h"
#include "SysClock.h"
//#include "PWM.h"
//#include "Display.h"
/***********************************Variables**************************************/
float tmpDC;
static unsigned long DelayTime;
/*************************************CODE*****************************************/
/*********************************************************************************/
/*********************************************************************************/
/*main */
/*********************************************************************************/
void main(void) {
asm{
rsp
}
initCPU();
asm{
rsp
}
EnableInterrupts;
SysClockInit();
//PWMInit();
//MainLoop
while(1){
DelayTime = GetSysMSec() + 2000;
}//End MainLoop
} /* end void main(void)*/
/*********************************************************************************/
/*********************************************************************************/
/*********************************************************************************/
/*********************************************************************************/
/*initCPU */
/*********************************************************************************/
void initCPU(void){
//setup the config registers
CONFIG2 = 0x00;
CONFIG1 = 0x39;
#ifdef emulator
OSCTRIM = 0x00;
#else
//trim the oscillator
OSCTRIM = Optional;
#endif
//Ram test
asm{
RAM_TST:
clrh ; Clear index register H
lda #$FF ; Load accum with test pattern
RAM_0:
ldx #0x80 ; Load index register with beginning of RAM address
RAM_1:
sta ,X ; Store test pattern in RAM location
incx ; Increment RAM location
cpx #$FE ; If index register not at last RAM location,
bcs RAM_1 ; Then continue to load RAM with test pattern
ldx #$80 ; Else, check that RAM location holds correct test pattern
RAM_2:
cmp ,X ; If RAM location doesn't hold correct test pattern,
bne RAM_TST ; Then try loading RAM locations again with original test pattern (Watchdog will timeout if RAM error)
incx ; Increment RAM location
cpx #$FE ; If index register not at last RAM location,
bcs RAM_2 ; Then continue testing RAM test pattern
cmp #$00 ; If test pattern equal to zero,
beq RAM_X ; Then exit routine
sub #$55 ; Else, subtract pattern for new test pattern
jmp RAM_0 ; Load RAM with new test pattern
RAM_X:
} //end asm Ram Test
} /* end void initCPU(void) */
/*********************************************************************************/
/*********************************************************************************/
-------------------------------------------------------------------------------------------------
main.h
-------------------------------------------------------------------------------------------------
void initCPU(void);
-------------------------------------------------------------------------------------------------
So I have these 4 files
main.c
main.h
SysClock.c
SysClock.h
SysClock.c contains a timer overflow interrupt that generates a 10ms clock stored within the unsigned long variable SystemClock, which is initialized to 0. The function GetSysMSec() is also a part of this file and simply returns SystemClock.
During emulation using the FSICEBASE I get the following:
When I put the following snippit of code whithin the main loop
DelayTime = GetSysMSec();
DelayTime will follow SystemClock
SystemClock = 0
DelayTime = 0
SystemClock = 0x1E
DelayTime = 0x1E
But when I try to add an offset of 2 seconds
DelayTime = GetSysMSec() + 2000;
I get the following:
DelayTime is 0 just prior to the line call for the first time
DelayTime = 0x028407D0 is the return value when SystemClock is 0
I expect that DelayTime should be 0x000007D0.
Now as SystemClock is changing value for example when SystemClock reaches 0x0000008C (140mS)
The same line call
DelayTime = GetSysMSec() + 2000;
should assignd the value of 0x0000085C to DelayTime, instead I get DelayTime = 0x028407D0, the same value as before. Nothing happens to DelayTime from this point forward no matter what the value for SystemClock is.
Now just as a little note, 0x0284 just happens to be the value of memory locations 0x0000 and 0x0001, which are registers set aside for PortA and PortB.