#include <p16f877a.inc> ; incluir arquivo
__CONFIG _CP_OFF & _WDT_OFF & _PWRTE_ON & _XT_OSC
contador EQU 0X20
ORG 0x00
org 0x00 ; reset vector
goto Main ;
org 0x04 ; interruption vector
goto Main ; don't has interruption routine
Main
;--------------------------------------------;
; 7-segments ;
;--------------------------------------------;
BSF STATUS,5
MOVLW B'00001111'
MOVWF ADCON1
MOVLW B'00001111'
MOVWF TRISA
MOVLW B'00000000'
MOVWF TRISB
bcf STATUS,5
clrf PORTB
;--------------------------------------------;
; LCD ;
;--------------------------------------------;
BCF STATUS,RP1 ; select bank 1
BSF STATUS,RP0
CLRF TRISB ; bank b as output (LCD)
CLRF TRISD ; port d as output (RD0-R/S, RD1-E)
MOVLW b'00000111'
MOVWF OPTION_REG ; Configuração do registrador OPTION_REG para TMR0 1:256
BCF STATUS,RP0 ; select bank 0
CLRF PORTB ;
CLRF PORTD ;
CALL InicializaLCD
LOOP2
CALL CONVERTEBINPHEX
GOTO LOOP2
;-------------------------------------------;
REINICIO
clrf contador
;clrf PORTA
IMPRIME
MOVF PORTA,w ; read in A 4 bits.
movf contador,w
CALL tabela
movwf PORTB
incf contador, f ; +1 on table
movlw d'16' ;
xorwf contador
BTFSS STATUS,Z
goto IMPRIME ; z=0 a xor /=0, isso significa que o contador não chegou a 16 posições da tabela
goto REINICIO ; z=1 a xor = 0, isso significa que o contador chegou a 16 posições da tabela e inicia novamente a tabela.
tabela
ADDWF PCL,f ;
RETLW B'11111100' ; imprime 0
RETLW B'01100000' ; imprime 1
RETLW B'11011010' ; imprime 2
RETLW B'11110010' ; imprime 3
RETLW B'01100110' ; imprime 4
RETLW B'10110110' ; imprime 5
RETLW B'11111010' ; imprime 6
RETLW B'11100000' ; imprime 7
RETLW B'11111110' ; imprime 8
RETLW B'11100110' ; imprime 9
RETLW B'11101110' ; imprime A
RETLW B'11111111' ; imprime B
RETLW B'11110000' ; imprime C
RETLW B'11111101' ; imprime D
RETLW B'10011110' ; imprime E
RETLW B'10001110' ; imprime F
;tempo1s
;////////////////////////////////////////////////////////////////////////////////////////////////////
InicializaLCD
BCF PORTD,RD0 ; Define RS como 0 para enviar comandos ao LCD
CALL DELAY_5ms
MOVLW b'00000001' ; clean display
MOVWF PORTB
CALL Enable
CALL DELAY_5ms
MOVLW b'00111000' ;
MOVWF PORTB
CALL Enable
CALL DELAY_5ms
MOVLW b'00001111' ; Display on off
MOVWF PORTB
CALL Enable
CALL DELAY_5ms
MOVLW b'00000110' ;
MOVWF PORTB
CALL Enable
CALL DELAY_5ms
RETURN
EscreveCaracter
BCF PORTD,RD0 ; Define RS as 0 to sent enviar data to LCD
MOVLW b'00000001' ; Set home cursor
CALL Escreve
MOVLW b'00000010' ; Set home cursor
CALL Escreve
BSF PORTD,RD0 ; Define RS as 1 to sent data to LCD
CALL DELAY_5ms
BCF STATUS,RP1 ;select bank 1
BSF STATUS,RP0
CLRF TRISB ;port b as output (LCD)
CLRF TRISD ;port d as output (RD0-R/S, RD1-E)
MOVLW b'00000111'
MOVWF OPTION_REG ;Configuração do registrador OPTION_REG para TMR0 1:256
BCF STATUS,RP0 ;Select bank 0
CLRF PORTB
CLRF PORTD
CALL InicializaLCD
LOOP2
CALL CONVERTEBINPHEX
GOTO LOOP0
;-------------------------------------------------------------------;
CONVERTEBINPHEX
table
ADDWF PCL,f ;
RETLW B'00000000' ; print 0
RETLW B'00000001' ; print 1
RETLW B'00000010' ; print 2
RETLW B'00000011' ; print 3
RETLW B'00000100' ; print 4
RETLW B'00000101' ; print 5
RETLW B'00000110' ; print 6
RETLW B'00000111' ; print 7
RETLW B'00001000' ; print 8
RETLW B'00001001' ; print 9
RETLW B'00001010' ; print A
RETLW B'00001011' ; print B
RETLW B'00001100' ; print C
RETLW B'00001101' ; print D
RETLW B'00001110' ; print E
RETLW B'00001111' ; print F
END