Tengo que codificar el ejemplo típico de 8 LED que se encienden y se apagan, y luego todos se encienden en un bucle.
Obtuve un PIC 18F4550 y codifiqué esto:
List P=18F4550 ;Microcontrolador a utilizar
include <P18F4550.inc> ;Definiciones de constantes
;********** Palabra de conficuración *******************************************
CONFIG FOSC = INTOSC_EC ;INTOSC_EC ; Internal oscillator
CONFIG PWRT= ON ; Power-up Timer Enable bit
CONFIG BOR=OFF ; Brown-out Reset disabled in hardware and software
CONFIG WDT=OFF ; WDT disabled
CONFIG MCLRE=ON ; MCLR pin enabled
CONFIG PBADEN=OFF ; PORTB<4:0> pins are configured as digital I/O
CONFIG LVP=OFF ; Single-Supply ICSP disabled
CONFIG DEBUG = OFF ; Background debugger disabled
CONFIG XINST = OFF ; Extended Instruction disabled
;******************************Variables***********************************
conta equ 0x00
;**********************************************************************************
org 0x0000
movlw 0x62
movwf OSCCON
clrf TRISD
CICLO
bcf PORTD,0
call RETARDO
bsf PORTD,0
bcf PORTD,1
CALL RETARDO
bcf PORTD,1
call RETARDO
bsf PORTD,1
bcf PORTD,2
CALL RETARDO
bcf PORTD,2
call RETARDO
bsf PORTD,2
bcf PORTD,3
CALL RETARDO
bcf PORTD,3
call RETARDO
bsf PORTD,3
bcf PORTD,4
CALL RETARDO
bcf PORTD,4
call RETARDO
bsf PORTD,4
bcf PORTD,5
CALL RETARDO
bcf PORTD,5
call RETARDO
bsf PORTD,5
bcf PORTD,6
CALL RETARDO
bcf PORTD,6
call RETARDO
bsf PORTD,6
bcf PORTD,7
CALL RETARDO
bcf PORTD,7
call RETARDO
bsf PORTD,7
bcf PORTD,0
CALL RETARDO
bra CICLO
RETARDO
movlw .255
movwf conta
CICLO2
DECFSZ conta,F
bra CICLO2
nop
nop
nop
nop
return
end
Cuando simulo, ese código casi funciona. A veces se encienden y apagan uno tras otro comenzando por el primer LED, pero a veces la secuencia salta y algunos LED aleatorios se encienden inesperadamente.
Traté de agregar esta parte del código antes bra CICLO
para producir el efecto completo de los LED ON, pero solo hizo que se comportara peor.
bcf PORTD,0
bcf PORTD,1
bcf PORTD,2
bcf PORTD,3
bcf PORTD,4
bcf PORTD,5
bcf PORTD,6
CALL RETARDO
bsf PORTD,1
bsf PORTD,2
bsf PORTD,3
bsf PORTD,4
bsf PORTD,5
bsf PORTD,6
bsf PORTD,7
CALL RETARDO
Esta es una foto de mi simulación:
¿Qué estoy haciendo mal? ¿Cómo podría asegurarme, trabajando a 4 MhZ, de que los retrasos serán de 1 segundo?
Intente escribir en los respectivos registros LATDx, use solo PORTD para operaciones de lectura
bcf LATD,0
Esto debería solucionar tu problema.
bcf LATD,x
ybsf LATD,x
ricardo