Foro de elhacker.net

Informática => Electrónica => Mensaje iniciado por: EIVL14 en 27 Noviembre 2016, 01:55 am



Título: Encender un led cada 0.5 segundos usando temporizador en ensamblador
Publicado por: EIVL14 en 27 Noviembre 2016, 01:55 am
Buenas a todos, tengo el siguiente código asm (ensamblador) que consiste en simplemente encender y apagar un led cada 0.5 segundos en el PICF84A , pero lo necesito usando un TMR0 como temporizador. Soy totalmente nuevo en esto de programación de microcontroladores, sobre todo micros de la familia PIC, así que si alguien me puede echar una mano se los agradecería  :(

Código:
LIST	P=16F84A
INCLUDE <P16F84A.INC>
CBLOCK 0x0C ; In this position starts user´s RAM.
ENDC
#DEFINE LED PORTB,0

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

ORG 0x00
INICIO
bsf STATUS,RP0                    ; Access to bank 1
bcf LED                                    ; LED line configurated like OUTPUT
bcf STATUS,RP0                    ; Access to Bank 0.
PRINCIPAL
bsf LED                                    ; Turn on the LED
call Retardo_200ms                    ; while the sum of this time
call Retardo_200ms                    
bcf LED                                      ; It turns off while the sum of the next retardos
call Retardo_200ms  
call Retardo_100ms
goto PRINCIPAL

; Subrutinas "Retardo_200ms" y "Retardo_100ms"-------------------------------------------

CBLOCK
R_ContA                              ; Counters for the retardos
R_ContB
ENDC

Retardo_200ms                     ; The named "call" aports 2 machine cycles.
movlw d'200'             ; It Aports 1 machine cycle. This is the value of "M".
goto Retardos_ms             ; It aports 2 machine cycles.
Retardo_100ms                     ; The named "call" aports 2 machine cycles.
movlw d'100'             ; It aports 1 machine cycle.This is the value of "M".
goto Retardos_ms             ; It aport 2 machine cycles.
Retardo_1ms                     ; The named "call" aports 2 machine cycles.
movlw d'1'                     ; It aports 1 machine cycle. This is the value of "M".

Retardos_ms
movwf R_ContB             ; It aports 1 machine cycle.
R1ms_BucleExterno
movlw d'249'             ; It aports Mx1 machine cycles. This is the value of "K".
movwf R_ContA             ; It aports Mx1 machine cycles.
R1ms_BucleInterno
nop                                     ; It aports KxMx1 machine cycles.
decfsz R_ContA,F             ; (K-1)xMx1 cm (when it doesn´t jump) + Mx2 cm (when it jumps).
goto R1ms_BucleInterno           ; It aports (K-1)xMx2 machine cycles.
decfsz R_ContB,F             ; (M-1)x1 cm (when it doesn´t jump) + 2 cm (when it jumps).
goto R1ms_BucleExterno          ; It aports (M-1)x2 machine cycles.
return                             ; The return Jump aports 2 machine cycles.

END


Título: Re: Encender un led cada 0.5 segundos usando temporizador en ensamblador
Publicado por: Meta en 30 Diciembre 2016, 07:49 am
Hola:

Intentas hacer lo mismo pero con el Timer0.

¿Te atreves?

Es más preciso y el PIC no se queda en esclavo.

Saludos.