$BASE 10T                              ;SET DEFAULT TO DECIMAL NUMBER FORMAT
$PAGELENGTH 64T                        ;SET LISTING FILE PAGE LENGTH = 64 LINES
$PAGEWIDTH 132T                        ;SET LISTING FILE PAGE WIDTH = 132 CHARS

$INCLUDE "K1DEF.ASM"                   ;INCLUDE K1 DEFINITION FILE

; 68HC705K1 SAMPLE PROGRAM - "SAMPLE.ASM"
;
; TWO LEDS ARE CONNECTED TO PORT PINS PA7 & PA6.
; A PUSHBUTTON SWITCH IS CONNECTED TO PA0.
;
; RUNNING THE PROGRAM FLASHES THE LED CONNECTED TO PA7.
; PRESS THE SWITCH AND THE LED CONNECTED TO PA6 FLASHES INSTEAD.
; RELEASE THE SWITCH AND THE FIRST LED FLASHES AGAIN.

;===================================
; SET UP MASK OPTION REGISTER (MOR)
;===================================
;
         ORG    MOR                    ;$0017
         FCB    $00                    ;SOFTWARE PULLDOWN ENABLED
                                       ;TWO PIN CRYSTAL OSCILLATOR
                                       ;NO WATCHDOG

;================
; POWER UP RESET
;================
;
         ORG    ROM                    ;START OF PROGRAM MEMORY ($0200 - $03EF)

START    LDA    #$FF                   ;TURN OFF BOTH LEDS
         STA    PORTA
         LDA    #%11111110             ;PA0 = INPUT, PA1-7 = OUTPUTS
         STA    DDRA

; HERE IF SWITCH IS RELEASED (NOT PRESSED)
;
CHECKSW  BRSET  PA0,PORTA,SWITCHON     ;BRANCH IF SWITCH IS PRESSED
         BCLR   PA7,PORTA              ;TURN ON LED 1
         BSR    DELAY                  ;CALL SOFTWARE DELAY ROUTINE
         BSET   PA7,PORTA              ;TURN OFF LED 1
         BRSET  PA0,PORTA,SWITCHON     ;BRANCH IF SWITCH IS PRESSED
         BSR    DELAY
         BRCLR  PA0,PORTA,CHECKSW      ;BRANCH IF SWITCH IS NOT PRESSED

; HERE IF SWITCH IS PRESSED
;
SWITCHON BCLR   PA6,PORTA              ;TURN ON LED 2
         BSR    DELAY
         BSET   PA6,PORTA              ;TURN OFF LED 2
         BRCLR  PA0,PORTA,CHECKSW      ;BRANCH IF SWITCH IS RELEASED
         BSR    DELAY
         BRCLR  PA0,PORTA,CHECKSW      ;BRANCH IF SWITCH IS RELEASED
         BRA    SWITCHON               ;SWITCH IS PRESSED - CONTINUE

; SOFTWARE TIMING LOOP
;
; LOADS THE "X" REGISTER WITH $FF AND DECREMENTS IT TO ZERO
;
DELAY    LDX    #$10                   ;PRE-LOAD THE TIMING COUNTER
DELAY1   LDA    #$10
DELAY2   DECA
         BNE    DELAY2
         DECX                          ;DECREMENT TIMING COUNTER
         BNE    DELAY1                 ;LOOP UNTIL COUNTER REACHES ZERO
         RTS                           ;EXIT

; DUMMY "RETURN FROM INTERRUPT" HERE
;
RETINT   RTI

;===================
; INTERRUPT VECTORS
;===================
;
         ORG    VECTORS                ;$03F8

         FDB    RETINT                 ;TIMER INTERRUPT    - NOT USED
         FDB    RETINT                 ;EXTERNAL INTERRUPT - NOT USED
         FDB    RETINT                 ;SOFTWARE INTERRUPT - NOT USED
         FDB    START                  ;RESET

         END
