You are on page 1of 5

;**************************************** ;* AHC08 Demo Program - GP32 * ;**************************************** XDEF Entry, main, AtoD_ISR, T_ISR Include 'derivative.

inc' initStack Limit: ADC_Channel ADC_ENABLE_INT DEFAULT_RAM: var1: var2: var3: var4: variable: temp_long: temp_word: temp_byte: Timeout1: ich Timeout2: Timeout3: tmp: DEFAULT_ROM: EQU EQU EQU EQU $0200 23 $05 $40

SECTION SHORT ds.b ds.b ds.b ds.b ds.b ds.b ds.b ds.b ds.b 1 1 1 1 1 4 2 1 1

; Allows three timeout routines to be called each of wh ; can run for up to ~ 1/2 second.

ds.b 1 ds.b 1 ds.b 1 SECTION

************************************************************** * Init_SCI - Turns on the asyncronous communications port * * for "transmitting only" at 9600 baud N81. * ************************************************************** Sci_Init: ;configuracion de el modulo de transmision serial mov #$03,SCBR ; Baud Rate = 9600 mov #$40,SCC1 ; Enable the SCI peripheral mov #$08,SCC2 ; Enable the SCI transmitter rts ************************************************************** * Init_AtoD - Sets up the AtoD clock + turns it on * ************************************************************** Init_AtoD: ;cionfiguracion de nodulo adc mov #$30,ADCLK ; Bus Clock / 2 mov ADC_Channel,ADSCR ; Enable the ADC peripheral rts ************************************************************** * Init_Timer - Turns on timer 1 channel 0 for an Output * * Compare in approximately 2ms. The timer * * interrupt service routine continually sets * * the next interrupt to occur 2ms later. *

************************************************************** Init_Timer: mov #$36,T1SC ; Timer 1 - Cleared + Stopped. ; Clicks once every 64 BUS Cycles ; 77t Clicks ~ 2ms mov mov mov mov rts #$0,T1CH0H #4D,T1CH0L #$54,T1SC0 #$06,T1SC ; Set Output Compare to happen 77T clicks ; after we start the timer. (~2ms). The ; timer interrupt will set OC for another ~2ms. ; Timer 1 Channel 0 ; Set for Output Compare operation. ; Start the timer

************************************************************** * ; Main - This is the point where code starts executing * * ; after a RESET. * ************************************************************** Entry: main: ldhx #$23F ;cargo 23F a H:X txs ; Initialize Stack Pointer clra ; Initialize A,X so that interrupt clrx ; processing doesnt stop with ; uninitialized register warning ; when push A,X on the stack ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; BRCLR 5,PCTL,* LDA #$00 ; Set STA PCTL LDA #$02 ; Set STA PCTL LDA #$D1 ; Set STA PMSL LDA #$03 STA PMSH LDA #$D0 ; Set ; Turn Off PLL P=0 for PRE[1:0] E=2 for VPR[1:0] N=977 for MUL[11:0]

L=208 for VRS[7:0]

STA PMRS LDA #$01 ; Set R=1 for RDS[3:0] STA PMDS BSET 5,PCTL ; Turn On PLL BSET 7,PBWC ; Enable Auto Bandwidth Control BRCLR 6,PBWC,* ; Loop until LOCK bit set BSET 4,PCTL ; Select VCO clock as system clock NOP NOP mov mov mov mov mov mov mov #$00,PCTL #$00,PMSL #$00,PMSH #$00,PMRS #$00,PMDS #$02,CONFIG2 #$39,CONFIG1

mov #$0f,DDRA s entrada mov #$f0,PTAPUE ta del puerto a mov #$02,INTSCR ;bsr ;bsr ;bsr ;clr ;clr ;clr ;cli Sci_Init Init_AtoD Init_Timer Timeout1 Timeout2 Timeout3

; la parte baja del puerto a es salida, parte alta e ; se activa la resistencia de pull-up en la parte al

; Initialize peripherals ; Initialize timeouts (0=off) ; Allow interrupts to happen ; Start an AtoD conversion in 3*2ms=6ms

;mov #3,Timeout1 mov #$00,variable mov variable,PTA bsr retardo main_loop: brset 4,PTA,prueba bra main_loop prueba: bsr retardo

; salta si es uno

brset 4,PTA,* ;salta a la misma direccion hasta que no se cumpla la instruccion, solo continuara si ya se desconecto el boton inc variable mov variable,PTA ;incremento la variable

bra main_loop

;dec variable ;mov variable,PTA ;bsr retardo ;sta COPCTL register to prevent reset ;bra main_loop ************************************************************** retardo: mov #$0f,var1 ;F ; service cop control

seguir: mov #$02,var2 ;f unix: mov #$02,var3 fas: mov #$02,var4 fase: dbnz var4,fase dbnz var3,fas dbnz var2,unix dbnz var1,seguir

rts ************************************************************** * AtoD_ISR - ADC Conversion Complete Interrupt * * Transmit ADC value out serial port (PTE0) * ************************************************************** AtoD_ISR: lda here: brclr sta sta rti ADR 7,SCS1,here SCDR temp_byte ; Get the converted value ; wait until xmitter is ready. ; Xmit it our serial port ; save it in temp_byte

************************************************************** * T_ISR - Timer Interrupt Service Routine. * * after a RESET. * ************************************************************** T_ISR: pshh lda T1SC0 and #$7f sta T1SC0 ; Clear O.C. Flag ldhx T1CH0H aix #$4D ; Setup another interrupt in ~2ms sthx T1CH0H pulh Check_t1: tst beq dec bne jsr Check_t2: tst beq dec bne Timeout1 Check_t2 Timeout1 Check_t2 t1_handler Timeout2 Check_t3 Timeout2 Check_t3

; Is Timeout 1 currently active? ; yes ; Did it just finish counting down? ; Yes - Execute Timeout 1 handler

; Is Timeout 2 currently active? ; yes ; Did it just finish counting down?

jsr t2_handler Check_t3: tst beq dec bne jsr done_tisr: rti Timeout3 done_tisr Timeout3 done_tisr t3_handler

Yes - Execute Timeout 2 handler

; Is Timeout 3 currently active? yes ; Did it just finish counting down? ; Yes - Execute Timeout 3 handler ;

**************************************************************** * Timeout Handlers - All the user has to do is set one of the * * timeout variables to any number n (1-255) * * and the timeout handler will be executed * * in 2*n milliseconds. Setting the timeout * * variable from within the handler will * * cause a periodic timeout as shown in * * timeout 1. * **************************************************************** t1_handler: lda #(ADC_ENABLE_INT ADC_Channel) sta tmp mov tmp,ADSCR ; #$45 Start a single ADC conversion ; which will generate an interrupt. mov #$3,Timeout1 rts t2_handler: rts t3_handler: rts END ; Setup next t1_handler event in 3*2ms=6ms

* This source is (C)opyright 2002, P&E Microcomputer Systems, Inc. * Visit us at http://www.pemicro.com

You might also like