Sei sulla pagina 1di 8

list

p=18f2550

#include <p18f2550.inc>
;....................
;.................... CONFIGURACIN DE FUSIBLES;
;..... consultar C:\Program Files (x86)\Microchip\MPASM
Suite\hlpPIC18ConfigSet.chm

config PLLDIV = 2

; 8 MHz

config CPUDIV = OSC1_PLL2


config USBDIV = 1
config FOSC = HSPLL_HS
config FCMEN
config IESO

config BOR
config BORV

External oscillator

= ON

= ON

config PWRT

; Oscillator Switchover mode enabled

= OFF
= OFF
=2

config VREGEN = ON
config WDT

; USB Voltage Regulator


= OFF

config WDTPS

= 32768

config MCLRE

= ON

; disable watchdog timer

; MCLEAR Pin on

config LPT1OSC = OFF


config PBADEN = OFF
; config CCP2MX = ON
config STVREN = ON
config LVP
for debugging)

= OFF

; Low-Voltage programming disabled (necessary

; config ICPRT

= OFF

; Dedicated In-Circuit Debug/Programming

config XINST

= OFF

; Extended Instruction Set

config DEBUG
config CP0

= OFF
= OFF

; Disable Debug Mode

config CP1

= OFF

; config CP2

= OFF

; config CP3

= OFF

config CPB

= OFF

; config CPD

= OFF

config WRT0

= OFF

config WRT1

= OFF

; config WRT2

= OFF

; config WRT3

= OFF

config WRTB

= OFF

config WRTC

= OFF

; config WRTD

= OFF

config EBTR0

= OFF

config EBTR1

= OFF

; config EBTR2

= OFF

; config EBTR3

= OFF

config EBTRB

= OFF

; Boot Block Write Protection

;....................
;.................... INICIO DEL CDIGO;
ORG

0x1000

;....................
;.................... ENCENDER LA MITAD DE LEDS PUERTO B;

;....................
;.................... INICIALIZACIN GENERAL;
Configuracion:
CLRF TBLPTRU
FUSIBLES

;0'S

-> TBLPTRU DESHABILITA EL ACCESO A LOS

BCF
RCON,7
PRIORIDAD DE INTERRUPCIONES

;0

-> RCON.7 DESHABILITA LA

CLRF
DE MEMORIA

FSR0H

;0S

-> FSR0H

DIRECCIONAMIENTO DE BANCO

CLRF
DE MEMORIA

FSR0L

;0S

-> FSR0L

DIRECCIONAMIENTO DE BANCO

MOVF

ADCON1,W

ANDLW

0xC0

;W AND 0xC0 -> W

IORLW

0x0F

;W OR_EX 0x0F -> W

MOVWF
ANALOGICOS
MOVLW
MOVWF
COMPARADORES

;ADCON1

ADCON1

;W

-> W

-> ADCON1 CONFIG. CANALES

0x07
CMCON

;0X07 -> CMCON

CONFIG. MODULO

;inicia codigo y asignacione


movlw b'00000000'
;
set PORTB all outputs (A '0'
means output, A '1' means input. We can set each
movwf TRISB
individualy. Each port having 8-bits or 8 pins.
movlw b'00100000'
bit 5. Bit 5 is an input ONLY pin.
movwf TRISA

We can set each bit

set PORTA all outputs except for

No puede ser Output

we want all LED's off to start

setup
movlw b'11111111'
with
movwf PORTB

'0' to turn an LED on

begin
starts.

This is where our main program

movlw b'11000000'
combination so that

Turn the LED's in such a

movwf PORTB

we display the number '0'

call Delay
for a moment.

;and now call the delay to hold that number there

movlw b'11111001'
combination so that

movwf PORTB
call Delay
for a moment.

movwf PORTB
;

movlw b'10110000'
combination so that

we display the number '2'

and now call the delay to hold that

movwf PORTB
;

Turn the LED's in such a


;

call Delay
number there for a moment.

Turn the LED's in such a


;

we display the number '3'

and now call the Delay to hold that number there

movlw b'10011001'
combination so that

movwf PORTB

Turn the LED's in such a


;

call Delay
number there for a moment.

movlw b'10010010'
combination so that
movwf PORTB
call Delay
there for a moment.

we display the number '1'

; and now call the delay to hold that number there

movlw b'10100100'
combination so that

call Delay
for a moment.

Turn the LED's in such a

and now call the delay to hold that

Turn the LED's in such a


;

we display the number '4'

we display the number '5'

and now call the delay to hold that number

movlw b'10000010'
combination so that

movwf PORTB

Turn the LED's in such a


;

we display the number '6'

call Delay
that number there for a moment.

and now call the delay to hold

movlw b'11111000'
combination so that

Turn the LED's in such a

movwf PORTB

call Delay
number there for a moment.

movlw b'10000000'
combination so that

and now call the delay to hold that

movwf PORTB
;

movlw b'10011000'
combination so that

the end, even if we don't want the program

countI set 0

;Method to count Slow

; Counter Varible for Cycle

count2 set 1 ; Counter Varible for Cycle

MLoop set 2

we display the number '9'

and now call the delay to hold that number

goto begin

Delay

Turn the LED's in such a


;

we display the number '8'

and now call the delay to hold that

movwf PORTB
call Delay
there for a moment.

Turn the LED's in such a


;

call Delay
number there for a moment.

we display the number '7'

and repeat!

We always need to have end at

movlw .9
movwf MLoop
movlw 1

;moving .9 to MLoop

; 1 is asigned to w

inicioCicloTres
cpfsgt MLoop
method
goto finCicloTres

cuerpoCicloTres

; it is more than and cause to go to the next


;it is no operation goes 3 and 1 more to cause interuption

; ------------- 2 Cycle

iniciaVarContExt
movlw .255 ; asigns .255
movwf countI
movlw 1

; Makes count .255

; Asigns 1 to w

inicioCicloExt
cpfsgt countI; it is more than and cause to go to EndF method
goto finCicloExt
interuption

cuerpoCicloExt

; it is no operation goes 255 and 1 more to cause

; ------Last Cycle

iniciaVarContCiclo
movlw 0
movwf count2
movlw .255

; Asigns 0 to w
; Makes countx 0
; asigns .255

iniciaCiclo
cpfslt count2 ; it is more than and cause to go to final method

goto finCiclo ; it is no operation goes 255 and 1 more to cause interuption

cuerpoCiclo

; No Opertion value tends to loop method maybe optional

nop

modificaVarCont ; Maybe optional


incf count2

; Increments MLoop Value

goto iniciaCiclo

; goes or loops to the method

finCiclo

;No Operation acts as a bucle

modificaVarContExt
decf countI

; Decrements MLoop Value

movlw 1

;Asigns 1 to w

goto inicioCicloExt

; goes or loops to the method

; For the Cycle


; 3 CM = 3 (0.00000008333) = 0.00000024999 sec
; CycleI
; 7 * 255 + 3 = 1788
; 1788(0.00000008333 sec) = 0.000149 sec

finCicloExt

;Cycle ends

modificaVarContTres
decf MLoop
movlw 1

; Decrements MLoop Value


;Asigns 1 to w

goto inicioCicloTres ; goes or loops to the method

finCicloTres ;Cycle ends

return

; Delay Ends

end

; Program Ends

Potrebbero piacerti anche