
74 CHAPTER 6. TIMING USING POLLING
We can use this to create a
30.52
2
Hz square wave by toggling an output pin every
time counter rolls over. Here is the code (you have to fill in the details!)
; Various defines go here ...
ORG $D000 don’t forget the $
ME FCC /Your name/
FCB 10
FCC /ECE 372/
FCB 10
FCC /Date the program was last changed/
FCB 10, 10, 4
ORG $C000 DONT FORGET THE $
LDX #ME
JSR OUTSTRG ; MAKE SURE YOU HAVE EQU FOR OUTSTRG
LOOP1
; CLEAR THE FLAG. NO HARM IS DONE IF IT IS ALREADY CLEARED
LDAA #%10000000
STAA TFLAG2
;WAIT FOR THE FLAG TO BE SET
LOOP2
LDAA TFLAG2
ANDA #%10000000
BEQ LOOP2
;NOW TOGGLE PA4
LDAA #%00010000
EORA PORTA
STAA PORTA
;DO IT ALL OVER AGAIN
BRA LOOP1
Type and run the above program. Connect the LED to PA4 (pin #5) and you
should see it flicker. Connect the pin to a oscilloscope and verify that you are
generating a square wave. Verify that the frequency is correct.
Comentarios a estos manuales