;******************************************************************************
;    ECE331 Lab 3 Part 1 
;    File: sqwave.asm (by KEH) August 2009 
;    Square Wave Generating Program that calls "wait_y_4us" subroutine
;    to generate a 50 Hz square wave on pin PM3 that is 10 ms high and 10 ms low.
;******************************************************************************
            XDEF sqwave             ; Export 'program entry point' symbol
  
            ABSENTRY sqwave         ; For absolute assembly: mark this as application entry point
            INCLUDE 'mc9s12c128.inc'; Include 9S12C128 register symbol definitions.
            ORG $4000
sqwave:     lds  #$1000             ; Initialize program stack pointer to point to one location above
                                    ; end of RAM block ($400 - $FFF)
            movb #%1000,DDRM        ; Make PM3 an output.
            ldy  #2500              ; Note that 2500*4 us = 10 ms delay time
next_cycle:	bset PTM,%1000          ; Set PM3 high
          	jsr wait_y_4us          ; Delay for 10 ms		
						bclr PTM,%1000          ; Set PM3 low
            jsr wait_y_4us          ; Delay for 10 ms
						bra next_cycle          ; go back to create next cycle of 50 Hz sq wave
wait_y_8us: 
*************** FILL IN THE CODE FOR THE DELAY SUBROUTINE HERE ***********
            rts
  		        ORG       $FFFE
            	fdb  sqwave             ; Initialize Reset Vector