Cronometro em asembly
;e o botão RB1 zera a contagem. Os displays de 7 segmentos alternam com uma freqüência de 100Hz.
;#include
;#INCLUDE
; __CONFIG _CP_OFF & _CPD_OFF & _DEBUG_OFF & _LVP_OFF & _WRT_ENABLE_OFF &
; _BODEN_OFF & _PWRTE_ON & _WDT_OFF & _XT_OSC
#INCLUDE
__CONFIG _CP_OFF & _CPD_OFF & _DEBUG_OFF & _LVP_OFF & _WRT_OFF & _BODEN_OFF & _PWRTE_ON & _WDT_OFF & _XT_OSC
CBLOCK 0X20 ;Área de RAM para variáveis TEMP TEMP1 B_TEMP W_TEMP S_TEMP DECIMO SEGUNDO ENDC
ORG 0X00 GOTO INICIO
;Vetor de interrupção ORG 0X04 MOVWF W_TEMP ;salva W e STATUS SWAPF STATUS,W MOVWF S_TEMP BTFSS INTCON,2 ;verifica se foi int de tmr0 GOTO OUTRA_INT BCF INTCON,2 MOVLW .217 MOVWF TMR0 BTFSC PORTB,4 GOTO MOSTRA_S MOVF DECIMO,W CALL DISP MOVWF PORTD MOVLW B'00010000' MOVWF PORTB GOTO OUTRA_INT
MOSTRA_S MOVF SEGUNDO,W CALL DISP MOVWF PORTD BSF PORTD,7 MOVLW B'00100000' MOVWF PORTB
OUTRA_INT BTFSS PIR1,0 GOTO SAI_INT BCF PIR1,0 MOVLW 0XCF MOVWF TMR1H MOVLW 0X2C MOVWF TMR1L MOVF DECIMO,W XORLW .9 BTFSC STATUS,2 GOTO ZERA_INT INCF DECIMO,F GOTO SAI_INT
ZERA_INT CLRF DECIMO MOVF SEGUNDO,W XORLW .9 BTFSC STATUS,2 GOTO ZERA_INT1 INCF SEGUNDO,F GOTO SAI_INT
ZERA_INT1 CLRF SEGUNDO
SAI_INT SWAPF S_TEMP,W ;restaura os valores de MOVWF STATUS ;W e STATUS SWAPF W_TEMP,F SWAPF W_TEMP,W RETFIE
;Rotina principal
INICIO MOVLW B'00100000' ;muda p/ banco 1 MOVWF STATUS CLRF TRISA MOVLW B'00000011' MOVWF TRISB CLRF TRISC CLRF TRISD CLRF TRISE MOVLW B'11010110' MOVWF OPTION_REG ;T0=1us X 128 X 39 = 5ms MOVLW B'00000001' MOVWF PIE1 CLRF STATUS ;volta p/ banco 0 CLRF PORTA MOVLW B'00010000' MOVWF PORTB CLRF PORTC CLRF PORTE MOVLW .217 MOVWF TMR0 MOVLW B'00110100' ;T1=1us X 8 X 12500 = 100ms MOVWF T1CON MOVLW 0XCF