C and Assembly programs to flash LEDs on PORTA, and wait using the
timer overflow
Flowchart:
Assembly Program:
; Program to increment Port A using the HC12 timer subsytem ; to time delays prog: equ $0800 TSCR: equ $0086 ; Timer System Control Register TMSK2: equ $008D ; Timer Interrupt Mask 2 TFLG2: equ $008F ; Timer Interrupt Flag 2 DDRA: equ $0002 ; Data Direction Register A PORTA: equ $0000 ; Port A Data CODE: section .text org prog lds #$0A00 ; set the stack pointer movb #$ff,DDRA ; Port A output clr PORTA ; 0 -> Port A movb #$80,TSCR ; Turn on timer movb #$02,TMSK2 ; Set timer overflow rate at 32 ms movb #$80,TFLG2 ; Clear TOF flag loop: brclr TFLG2,#$80,loop ; Wait for timer overflow inc PORTA movb #$80,TFLG2 ; Clear TOF flag bra loop ; Wait forever
C Program:
/* * Program to increment Port A using the HC12 timer subsytem * to time delays */ #include "hc12.h" main() { DDRA = 0xff; /* Make Port A output */ PORTA = 0x00; /* Clear Port A */ TSCR = 0x80; /* Turn on timer */ TMSK2 = 0x02; /* Set timer overflow rate */ /* at 32 ms */ TFLG2 = 0x80; /* Clear timer overflow flag */ while (1) /* Repeat forever */ { while (!(TFLG2 & 0x80)) ; /* Wait for TOF flag */ PORTA = PORTA + 1; /* Increment Port A */ TFLG2 = 0x80; /* Clear timer overflow flag */ } }