Está en la página 1de 5

1.

Disear un programa en MPLAB para encender y apagar un led conectado al pin RA0
del Microcontrolador PIC16F84A.

Solucin:

LIST P=16F84A C1
INCLUDE <P16F84A.INC>
CONT1 EQU 0X20 1nF
CONT2 EQU 0X21 X1 U1
ORG 0x00 C2
16
OSC1/CLKIN RA0
17
15 18
GOTO INICIO OSC2/CLKOUT RA1
1
ORG 0x05 RA2
4 2
MCLR RA3
INICIO bsf STATUS,RP0 1nF
RA4/T0CKI
3 R2
clrf TRISA 330
6
bcf STATUS,RP0 RB0/INT
ENCLED bsf PORTA,0
R1 RB1
7
10k 8
RB2
call RETARDO RB3
9
bcf PORTA,0 RB4
10 D1
11
call RETARDO RB5
12
GOTO ENCLED RB6
13
RB7
RETARDO movlw 0xff
movwf CONT1 PIC16F84A
REP1 movlw 0xff
movwf CONT2
REP2 decfsz CONT2,1
GOTO REP2
decfsz CONT1,1
GOTO REP1
RETURN
END
2. Disear un cdigo en MPLAB para obtener por el puerto B el dato del puerto A
intercambiado los nibles alto y bajo.

Solucin:

LIST P=16F84A R2 R3 R4 R5 R6
INCLUDE <P16F84A.INC>
10k 10k 10k 10k 10k

;...
INTERCAMB EQU 0X0C U1
ORG 0X00 16
15
OSC1/CLKIN
OSC2/CLKOUT
RA0
RA1
17
18

GOTO INICIO
1
RA2
4 2
MCLR RA3
3
ORG 0X05
RA4/T0CKI
6
RB0/INT
;..... R1
RB1
RB2
7
8
9
INICIO bsf STATUS,5
10k RB3
10
RB4
11
RB5
movlw 0xff RB6
RB7
12
13

movwf TRISA PIC16F84A

clrf TRISB
bcf STATUS,5
; R7 R8 R9 R10R11R12R13R14
330 330 330 330 330 330 330 330
BUCLE movf PORTA,0
movwf INTERCAMB
swapf INTERCAMB,0
movwf PORTB
GOTO BUCLE
END
3. Disear un cdigo en MPLAB para un contador binario ascendente visualizar por el
puerto B.

Solucin:

; Inicio del programa


LIST P=16F84A
INCLUDE <P16F84A.INC>
; Declaracin de registros de
propsito general U1
CONTA1 EQU 0X0F 16 17
OSC1/CLKIN RA0
CONTA2 EQU 0X10 15
OSC2/CLKOUT RA1
18
1
; Ubicacin en la memoria de 4
RA2
2
MCLR RA3
programa RA4/T0CKI
3

ORG 0x00 6
RB0/INT
GOTO INICIO RB1
7

ORG 0x05 R1 RB2


8
10k 9
RB3
; Configuracin de puertos RB4
10
11
INICIO bsf STATUS,5 RB5
12
RB6
clrf TRISB RB7
13

bcf STATUS,5 PIC16F84A


; Poner a cero el puerto B
clrf PORTB
CALL RETARDO
; Incrementar puerto B
BUCLE incf PORTB,1 R7 R8 R9 R10R11R12R13R14
CALL RETARDO 330 330 330 330 330 330 330 330

GOTO BUCLE
; Retardo para conteo ascendente
RETARDO clrf CONTA1
REP1 clrf CONTA2
REP2 incfsz CONTA2,1
GOTO REP2
incfsz CONTA1,1
GOTO REP1
RETURN
END
4. Disee un contador de 8 bits, que se incrementa cada vez que se pulsa P (RA0).
Visualice el resultado por el puerto B. Activar un led (RA1), cuando el contador
llegue a D120 y apagarlo cuando llegue a D200. Repetir el ciclo.

Solucin:
List P=16F84A
INCLUDE "P16F84A.INC"
CONTA1 EQU 0X0C
CONTA2 EQU 0X0D
CONTADOR EQU 0X0E U1
16 17
ORG 0x00 15
OSC1/CLKIN
OSC2/CLKOUT
RA0
RA1
18
1
GOTO INICIO 4
RA2
1
2
ORG 0x05 MCLR RA3
RA4/T0CKI
3

6
RB0/INT
INICIO bsf STATUS,5 RB1
7
8
bsf TRISA,0 RB2
9
RB3
bcf TRISA,1 RB4
10
11
clrf TRISB RB5
RB6
12
bcf STATUS,5 RB7
13

clrf CONTADOR PIC16F84A


clrf PORTB
movf CONTADOR,0
movwf PORTB

EXPLORA btfsc PORTA,0


goto EXPLORA
goto SI
SI incf CONTADOR,1
Call RETARDO
movf CONTADOR,0

movwf PORTB
sublw .120
btfss STATUS,Z
goto VALOR2
bsf PORTA,1
goto EXPLORA
VALOR2 movf CONTADOR
sublw .200
btfss STATUS,Z
goto EXPLORA
bcf PORTA,1
clrf CONTADOR
clrf PORTB
goto EXPLORA
RETARDO movlw 0xff
movwf CONTA1 decfsz CONTA1,1
REP1 movlw 0xff GOTO REP1
movwf CONTA2 RETURN
REP2 decfsz CONTA2,1 END
GOTO REP2
5. Disear un cdigo en MPLAB para un contador binario descendente visualizar por el
puerto B.

Solucin:

; Inicio del programa


LIST P=16F84A
INCLUDE <P16F84A.INC>
; Declaracin de registros de
propsito general U1
CONTA1 EQU 0X0F 16
15
OSC1/CLKIN RA0
17
18
CONTA2 EQU 0X10 OSC2/CLKOUT RA1
RA2
1
; Ubicacin en la memoria de 4
MCLR RA3
2
3
RA4/T0CKI
programa 6
ORG 0x00 RB0/INT
RB1
7
GOTO INICIO R1 RB2
8
9
10k RB3
ORG 0x05 RB4
10
11
; Configuracin de puertos RB5
RB6
12
INICIO bsf STATUS,5 RB7
13

clrf TRISB PIC16F84A

bcf STATUS,5
; Cargar datos al puerto B
movlw 0xff
movwf PORTB R7 R8 R9 R10R11R12R13R14
CALL RETARDO 330 330 330 330 330 330 330 330

; Inicio del bucle infinito


BUCLE decf PORTB,1
CALL RETARDO
GOTO BUCLE
; Retardo para conteo descendente
RETARDO clrf CONTA1
REP1 clrf CONTA2
REP2 incfsz CONTA2,1
GOTO REP2
incfsz CONTA1,1
GOTO REP1
RETURN
END

También podría gustarte