;****************************************************************************** ; ECE331 Lab 3 Part 1 ; File: sqwave.asm (by KEH) August 2004 ; Square Wave Generating Program that calls "wait_y_667ns" subroutine ; to generate a 100 Hz square wave on pin PM0 that is 5 ms high and 5 ms low. ;****************************************************************************** XDEF debounce ; Export 'program entry point' symbol ABSENTRY debounce ; For absolute assembly: mark this as application entry point INCLUDE 'mc9s12c32.inc' ; Include 9S12C32 register symbol definitions. ORG $4000 debounce: lds #$1000 ; Initialize program stack pointer to point to one location above ; end of RAM block ($800 - $FFF) movb #2,DDRM ; Make PM0 an input and PM1 an output bclr PTM,%00000010 ; Turn off LED intially waitswup: brset PTM,1,waitswup ; Wait here while SW is up (PM0 hi) ldy #60000 jsr wait_y_2us waitswdn: brclr PTM,1,waitswdn ; Wait here while SW is down (PM0 low) jsr wait_y_2us ldaa PTM eora #2; staa PTM ; Toggle LED bra waitswup ; Do this in endless loop wait_y_2us: pshd bset TSCR1,$80 ; Turn on 16-bit timer (TEN = 1) bset TSCR2,%00000100 ; bclr TSCR2,%00000011 ; Set prescaler to divide internal ; bus clock by 16, so TCNT increments ; once every 16/24 = 2/3 microsec. bset TIOS,%00000100 ; Configure Timer Channel #2 as an "output compare" reg bclr TIE, %00000100 ; Disable interrupts on Timer Channel 2 tfr y,d addd TCNTHi std TC2Hi ; Schedule Output Compare Event in 2/3 micosec movb #4,TFLG1 ; Clear channel 2 output compare flag wtoc2: brclr TFLG1,%00000100,wtoc2 ;Wait here till output compare occurs puld rts ORG $FFFE fdb debounce ; Initialize Reset Vector