; ram

          org $0000

#include hc11.inc       ;NEEDED TO DEFINE REGISTERS W/O MANUALLY DEFINING REG.

;Timer Overflow Counter
Sec_Temp        rmb 1                ;counter 32.77mSec [0-15]
Sec_count       rmb 1                ;counter 0.5Sec [0-255]

LED_COUNT       rmb 1
MSG_COUNT       rmb 1


;rom

        org $B000
        
        JMP main
msg             fcc '   Welcome To   '
msg_2           fcc '                Engineering Technology                '

outa        equ $ffb8
LEDs        equ $1404
LCD_INI         EQU     $080F ;$FF70
LCD_LINE1       EQU     $0812 ;$FF73
LCD_LINE2       EQU     $0815 ;$FF76


        
main:   lds #$01ff

        LDX #TMSK2                ;turn on TOF interrupt
        bset 0,x #$80
	cli
	
        jsr LCD_INI
	ldx #msg
        jsr LCD_LINE1

	ldab #00
        STAB LED_COUNT
        STAB MSG_COUNT
        
fred:   ldaa #1
        jsr pause

        LDAB LED_COUNT
        stab LEDs
        incb
        STAB LED_COUNT
        
        LDX #msg_2
        LDAB MSG_COUNT
        ABX
        JSR LCD_LINE2
        LDAB MSG_COUNT
        INCB
        cmpb #38
        bne OK
        LDAB #0
OK:     STAB MSG_COUNT

        jmp fred

        rts
        
        


        


;**************************************************************************
;Name:                Pause
;Author:        Dan Kohn
;Date:                Dec 19, 2005
;Functions:        Pause for multiple of 0.5 sec 
;                (setup for a 0.5 sec counter)
;
;On call:        Reg A Contains the number of 0.5 sec to pause
;
;On Return;        Sec_Count and Sec_Temp were changed (cleared at start of 
;               pause.
;**************************************************************************

Pause:          psha
                pshb
                ldab #$00
                stab SEC_TEMP
                stab SEC_COUNT
                
PauseL1:        ldab sec_count
                cba
                bne PauseL1
                
                pulb
                pula
                rts
                



;**************************************************************************
;Name:                TOF_CNT
;Author:        Dan Kohn
;Date:                Dec 14, 2005
;Functions:        count every 0.5 sec.  
;
;On Return:        Count of 0.5 sec intervals is in SEC_count
;               Count of 32.77mSec intervals is in Sec_Temp
;**************************************************************************

TOF_CNT         ldaa #$80
                staa TFLG2        
                
                ldaa Sec_temp                ;count # of times overflow occures (32.77ms)
                inca 
                staa Sec_temp

                cmpa #15                ;if ~0.5sec has NOT gone by -> exit
                blo TOF_exit                ;      [15*32.77mSec = 0.49155 Sec]


                ldaa #$00                ;if ~0.5sec has gone by -> clear Sec_temp
                staa Sec_temp                ;and add one to the Sec_count

                ldaa Sec_count
                inca 
                staa Sec_count
                
TOF_exit        RTI

;interrupt vector table
TOFIV           ORG $ffde              ;$00d0
		;FCB $7e
		FDB TOF_CNT
		
START           ORG $FFFE
		FDB MAIN
		end
