Sie sind auf Seite 1von 4

;*******************************************************************

;* This stationery serves as the framework for a user application. *


;* For a more comprehensive program that demonstrates the more *
;* advanced functionality of this processor, please see the *
;* demonstration applications, located in the examples *
;* subdirectory of the "Freescale CodeWarrior for HC08" program *
;* directory. *
;*******************************************************************

; Include derivative-specific definitions


INCLUDE 'derivative.inc'

; export symbols
XDEF _Startup, main
; we export both '_Startup' and 'main' as symbols. Either can
; be referenced in the linker .prm file or from C/C++ later on

XREF __SEG_END_SSTACK ; symbol defined by the linker for the end of


the stack

; variable/data section
MY_ZEROPAGE: SECTION SHORT ; Insert here your data definition

ORG $90
LEDS: DS.B 1 ;Reservamos espacio para una variable
contador llamada LEDS

; code section
MyCode: SECTION
main:
_Startup:
LDHX #__SEG_END_SSTACK ; initialize the stack pointer
TXS

INICIALIZAR:
MOV #$0,LEDS ; Inicializamos el contador en 0.

CONFIGURAR_ADC:
MOV #$20,ADCSC1 ; Enable
continouos conversion, hardware triggered, Set channel PTA
MOV #$00,ADCCFG_MODE0 ; Set 8 bits mode

MOV #$00,PTADD ; Configuramos los


pines del puerto A como entrada
; LDA #%00001100
; STA PTAPE ; Se habilitan los
pullups

; MOVE #$00,PTDDD ; Configuramos los


pines del puerto D como entrada
; LDA #%00001100
; STA PTDPE ; Se habilitan los
pullups

CONFIGURAR_RTC:
LDA #$00
STA RTCMOD ; Configuramos el contador en 0 ya que se
cuenta cada 0.1s
LDA #$1E ;
STA RTCSC ; Configuramos el registro RTCSC
; RTDPS = 1101, RTCLKS = 00 para
configurar el reloj del contador en 0.1s
; RTIE = 1 para activar
interrupciones

CONFIGURAR_SCI:
LDA #$00
STA SCI1C1 ; 8-bit mode. Normal operation
LDA #$2C
STA SCI1C2 ; Receiver interrupt enable. Transmitter
and receiver enable
LDA #$00
STA SCI1C3 ; Disable all errors interrupts
LDA #$1A ; This register and the SCI1BDH are used
to configure the SCI baud rate
STA SCI1BDL ; * BUSCLK
4MHz *
LDA #$00 ; * Baud rate = -------------------------
= ----------- = 9600bps *
STA SCI1BDH ; * [SBR12:SBR0]
x 16 26 x 16 *

CONFIGURAR_PUERTOS:
MOV #$FF,PTCDD ; Configuramos los pines del puerto
C como salida.
MOV #$FF,PTCD ; inicializamos los Leds del Puerto
C en 1 (Logica negada), para apagarlos.

MOV #$FF,PTEDD ; Configuramos los pines del puerto


E como salida.
MOV #$FF,PTED ; inicializamos los Leds del Puerto
E en 1 (Logica negada), para apagarlos.

CLI ; enable interrups


mainLoop:
; Insert your code here
NOP
feed_watchdog
BRA mainLoop

;********************************************************************
;Rutinas de interrupciones
;********************************************************************

ISR_RTC:

LDA #$80
ORA RTCSC
STA RTCSC ; Bajamos la Bandera de interupcion de
RTC

JSR captura

COM LEDS ; Invertimos el valor del contador para


mostrarlo por los leds (Logica Negada)
STA LEDS
MOV LEDS,PTCD ; Mostramos el numero por los leds
MOV LEDS,PTED ; Mostramos el numero por los leds
COM LEDS ; Volvemos a invertir para incrementarlo
luego

STA SCI1D
BRCLR SCI1S1_TDRE,SCI1S1,*
LDA SCI1S1

RTI ; Salimos de la interrupcion

;****************************************************************
;* Application Subrutines *
;****************************************************************

captura: ; Subrutine => capture


potenciometer voltage
MOV #$20,ADCSC1 ; Start a new conversion
CH0

wait: BRCLR ADCSC1_COCO,ADCSC1,wait ; Wait for conversion end


LDA ADCRL ; Copy ADCRL to ACC
RTS ; Return from
subrutine, ACC have conversion value

;**************************************************************
;* spurious - Spurious Interrupt Service Routine. *
;* (unwanted interrupt) *
;**************************************************************
spurious: ; placed here so that security value
NOP ; does not change all the time.
RTI

;**************************************************************
;* Interrupt Vectors *
;**************************************************************
ORG Vtpm3ovf
DC.W spurious ; TPM3 overflow
DC.W spurious ; TPM3 CH5
DC.W spurious ; TPM3 CH4
DC.W spurious ; TPM3 CH3
DC.W spurious ; TPM3 CH2
DC.W spurious ; TPM3 CH1
DC.W spurious ; TPM3 CH0
DC.W ISR_RTC ; RTC
DC.W spurious ; SCI2 Tx
DC.W spurious ; SCI2 Rx
DC.W spurious ; SCI2 Error
DC.W spurious ; Analog comparator X
DC.W spurious ; ADC
DC.W spurious ; Keyboard
DC.W spurious ; IICx Control
DC.W spurious ; SCI1 Tx
DC.W spurious ; SCI1 Rx
DC.W spurious ; SCI1 Error
DC.W spurious ; SPI1
DC.W spurious ; SPI2
DC.W spurious ; TPM2 overflow
DC.W spurious ; TPM2 CH2
DC.W spurious ; TPM2 CH1
DC.W spurious ; TPM2 CH0
DC.W spurious ; TPM1 overflow
DC.W spurious ; TPM1 CH2
DC.W spurious ; TPM1 CH1
DC.W spurious ; TPM1 CH0
DC.W spurious ; Low Voltage
DC.W spurious ; IRQ
DC.W spurious ; SWI
; DC.W _Startup ; Reset ;Se elimina Vreset esta definido wn
proyect.prn en otro sitio

Das könnte Ihnen auch gefallen