;------------------------------------- ; HC908 Example #2 ;------------------------------------- ;Filename: example2.asm ;Written by Kenrick Chin ;2003.12.20 - first writing ;2004.02.25 - modified using LDHX/STHX ;This example is used to test the operation ;of the assembler and download process. ;Assembled code is placed in SRAM ;and then executed directly from SRAM ;No flash locations are used. ;An external oscillator at 9.8304MHz is assumed. ;The timer prescaler bits in the TIM Status and Control ;Register (TSC) are set to binary 110 to select divide by 64. ;The 16-bit timer modulo registers are set to 19230 ;causing the timer overflow flag (TOF) to be set ;once every 500ms. ;The output pins will flash once every second. ;------------------------------------- ; MCU Definitions ;------------------------------------- SRAM EQU $80 PORTA EQU $00 PORTB EQU $01 DDRA EQU $04 DDRB EQU $05 INTSCR EQU $1D CONFIG2 EQU $1E CONFIG1 EQU $1F OSCTRIM EQU $38 TSC EQU $20 TCNTH EQU $21 TCNTL EQU $22 TMODH EQU $23 TMODL EQU $24 TOF EQU 7 COPD EQU 0 RSTEN EQU 0 ;------------------------------------- ; Start of Bootstrap ;------------------------------------- ORG SRAM boot BOOT BSET COPD CONFIG1 ;turn off watchdog BSET RSTEN CONFIG2 ;enable RESET pin ;initialize PORTA and PORTB as outputs MOV #$FF DDRA MOV #$FF DDRB ;initialize timer ;set for MOD 19230 = $4B1E LDHX #19230 STHX TMODH ;same as doing ; MOV #$4B TMODH ; MOV #$1E TMODL ;start timer, divide by 64 clock MOV #%00010110 TSC ;------------------------------------- ; main program loop ;------------------------------------- LDA #$FF main1 BRCLR TOF TSC main1 ;wait for overflow flag BCLR TOF TSC ;clear flag STA PORTA STA PORTB main2 BRCLR TOF TSC main2 ;wait for overflow flag BCLR TOF TSC ;clear flag CLR PORTA CLR PORTB BRA main1 ENDB boot END ;------------------------------------- ; End of Example #2 ;-------------------------------------