Thanks Peg,
Your suggestion worked. I moved TPM1C1SC and changed the LDA/STA's to MOV's. The code is at the bottom of this post.
As I'm sure is obvious, I'm a novice programmer. May I ask another question?
I attempted to set the busclk frequency to 8MHz, but from the period of the LED blink, it appears to be closer to 6MHz. Also, when I run the program from Codewarrior certain info displays in the "Command" window. The last few lines that appear are listed below. Is this the busclk frequency and why does it change?
Postload command file correctly executed.
Frequency change to ~6004612hz.
STARTED
Frequency change to ~4175752hz.
RUNNING
Frequency change to ~5079600hz.
Frequency change to ~6428550hz.
Frequency change to ~4235805hz.
Frequency change to ~6698722hz.
Frequency change to ~5884507hz.
Frequency change to ~4235805hz.
Frequency change to ~5995177hz.
Potential Reset occurred
in>
Also, I'd like to ask about the forum. I'm determined to learn assembly language and build a weather station using the Demo9S08LL16. I will have lots of questions. Is it proper to use the forum in this way? Also, I'm anxious to learn the best pogramming practices, so everyone is welcome to critique my code.
Thanks again,
John Allen
The code that works:
; variable/data section
MY_ZEROPAGE: SECTION SHORT ; Insert here your data definition
DELAY1: DS.B 1 ; LED flash rate, DELAY1=16 -> 65.3 ms w/10 MHz busclk.
TEMP1: DS.B 1 ; Count buffer.
; code section
MyCode: SECTION
main:
_Startup:
LDHX #__SEG_END_SSTACK ; initialize the stack pointer
TXS ; Transfer the index register to the stack pointer.
CLI ; enable interrupts by clearing the interupt mask bit.
MOV #$04,ICSC1 ;FLL selected,Ref Clock/1, IRC selected.
MOV #$40,ICSC2 ; BDIV = 2, Range = Low
MOV #$0B,ICSTRM ; Use maximum period -> 31.25 KHz.
MOV #$10,ICSSC ; Default, DMX32=0,busclk=8MHz, FLL factor=512.
MOV #$0F,TPM1SC ; Clock = busclk, PRESCALE = 128.
MOV #$38,TPM1C1SC ; Edge aligned, high true pulse.
MOV #$FE,TPM1MODL ;
MOV #$FF,TPM1MODH ; Divide TPM clock by 65535->Period~=1.04 sec.
MOV #$FF,TPM1C1VL ; Low byte for duty cycle (TPM1C1H).
MOV #$AF,TPM1C1VH ; High byte for duty cycle (7FFF).
MOV #$FF,PTCDD ; Set PTC as an output.
MOV #$FF,PTCD ; Store $FF in PTCD.
MOV #16,DELAY1 ; STore blink rate in DELAY1.
; (Lower # -> higher blink rate) 16=65.3ms blink rate.
mainLoop:
NOP
LDA #$10 ; Bit 4 in the accumulator is set to 1.
EOR PTCD ; Invert the PTC4 state.
STA PTCD ; Put result on PTC.
JSR DELAY ; DELAY.
JMP mainLoop ; Start over again.
;Subroutines
DELAY: MOV DELAY1,TEMP1 ; Store delay count in TEMP1.
feed_watchdog
DLY1: LDX #255 ; Load X w/255.
feed_watchdog
DLY2: LDA #255 ; Load A w/255.
DLY3: DBNZA DLY3 ; Decrement A until zero then continue.
DBNZX DLY2 ; Decrement X & branch if not zero to DLY2.
DEC TEMP1 ; Decrement delay count.
BNE DLY1 ; continue until delay count is zero.
feed_watchdog
RTS ;Return from subroutine.
END