Micro-Projeto: Utilizando tempo de Carga de Capacitor...
Autor: Tico | Publicado: 2009-10-26T17:54:00-07:00

Esse fim de semana estava estudando algumas aplicacoes para microcontroladores e me deparei com uma ideia que achei fantastica... em cima disso criei um micro-projeto para apresentar essa ideia...
Como de costume deixo um video aqui para voces darem uma olhada..
(pic utilizado: PIC16F628A)



Bom vamos ao que interessa: 



O esquema utilizado foi o seguinte:




Como voces podem ver os pinos RB0,RB1,RB2,RB3,RB4,RB5,RB6 foram ligados no display de 7 segmentos, e dependendo do valor da resistencia no potenciometro, o mesmo ira apresentar um digito.
O pino RA5 foi ligado a uma chave para executar o master reset quando apertado... resetando todo o sistema.

e o mais famoso dos pinos é o RA2, local onde a magica acontece...heheheh
no codigo quando eu executo o comando "call c_limpa",o mesmo faz o pino Ra2 virar saida (output) e coloca o seu nivel logico em 0, garantindo assim que o capacitor seja totalmente descarregado...
logo em seguida executo o seguinte codigo "call c_verifica" onde la a primeira coisa a fazer é deixar o ra2 como imput novamente e logo em seguida ja comeco a roda o contador de tempo que fica analizando a o pino Ra2 ir para NL alto (5V) atraves dos comandos:
&nbsp;&nbsp;&nbsp; btfss&nbsp;&nbsp;&nbsp; porta,2&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; ;Verifica se o RA2 ja foi para NL =1&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; 
&nbsp;&nbsp;&nbsp; goto&nbsp;&nbsp;&nbsp; $-1&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; ;fica verificando ate ser estourado 
enquando ele esta aqui verificando, o contador TMR0 esta rodando e toda vez que o mesmo estoura (passa de FFh para 00h), ocorre entao uma interrupcao que sera tratada no end 0004h onde la é incrementado o a parte mais significativa do countHI.
quando finalmente o pino ra2 for para NL alto, o TMR0 é armazenado em countLO...
apos isso conforme o valor de count LO e countHI um digito sera atribuido ao contador que sera apois isso colocado no display de 7 segmentos...
.....
Mas como o capacitor demora diferentes tempos para carregar?
Simples atraves do circuito RC serie...
Quando colocamos um resistor em serie com um capacitor o mesmo ira demorar um determinado tempo&nbsp; para se carregar:
Tcarga=R*C*ln(Ve/(Ve-Vc))
portanto para ter uma nocao mais ou menos do tempo que iria demorar eu utilizei o produto RC que eu queria (quando se faz R*C o valor encontrado representa o tempo necessario para o capaciotr carregar-se com 63% do valor da fonte...)
sabendo que iria utiliza um capacitor de 0.1uF montei a seguinte tabela abaixo:






( sabendo que o TMR0 conta de 0 a 255, pude verificar que o mesmo demora aproximadamente 275us para estourar, em cima disso criei uma logica...)


Como mostrado no video ao envez de utilizarmos um potenciomentro, podemos utilizar um LDR ou qualquer outra coisa que varia a sua resistencia de acordo com algum fator externo.. podendo assim modificar o tempo de carga do capacitor e gerar um dado referente ao mesmo...

Codigo em ASM (por causa da perda de formatacao coloquei o arquivo fonte no rapidshare):
http://rapidshare.com/files/298393643/codigo_v1_0_b.asm

;################################# - TITULO - ##########################
;#&nbsp; Display 7 Segs, ativado de acordo com o tempo de carga do capacitor#
;#&nbsp; Usando capacitor, potenciomentro, Resistencia,display de 7seg&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; #
;#&nbsp; inicio do projeto : 24/10/2009&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp; #
;# &nbsp;&nbsp;&nbsp; Pic utilizado 16f628A (possui 16pinos de I/O)&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp; #
;#######################################################################
;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; Definicoes de hardware
;----------------------------------------------------------------------=
;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; Mapa do Display (Catodo Comum)&nbsp;&nbsp; 1= acende&nbsp;&nbsp;&nbsp; 0=Apaga
;
;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; A
;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; ########
;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; #&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; #&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; pino12&nbsp;&nbsp;&nbsp; RB6 --------A
;&nbsp;&nbsp;&nbsp; &nbsp;F #&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; # B&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; pino11&nbsp;&nbsp;&nbsp; RB5 --------B&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; 
;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; #&nbsp;&nbsp; G&nbsp;&nbsp;&nbsp; #&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; pino10&nbsp;&nbsp;&nbsp; RB4 --------C
;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; # ###### #&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; pino9 &nbsp;&nbsp;&nbsp; RB3 --------D
;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; #&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; #&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; pino8&nbsp;&nbsp;&nbsp; RB2 --------E
;&nbsp;&nbsp;&nbsp; &nbsp;E #&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; # C&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; pino7&nbsp;&nbsp;&nbsp; RB1 --------F
;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; #&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; #&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; pino6&nbsp;&nbsp;&nbsp; RB0 --------G
;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; ########
;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; D
;
;
;Positivo do capacitor ligado no pino RA2 ---- pino 1 do pic
;
;VCC ligado no pino 14
;GND ligado no pino 5
;
;RA5 pino 4
;
;Portas livres : RA0,RA1,RA3,RA4,RA6,RA7,RB7
;
;------------------------- DIRETIVAS PARA O COMPILADOR -----------------

&nbsp;&nbsp;&nbsp; lIST &nbsp;&nbsp;&nbsp; P=16f628A
&nbsp;&nbsp;&nbsp; RADIX&nbsp;&nbsp;&nbsp; DEC&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; ;Todo numero digitado ser interpretado como decimal
&nbsp;&nbsp;&nbsp; INCLUDE&nbsp;&nbsp;&nbsp; 
&nbsp;&nbsp;&nbsp; __CONFIG _CP_OFF &amp; _DATA_CP_OFF &amp; _LVP_OFF &amp; _BOREN_OFF &amp; _MCLRE_ON&nbsp;&nbsp;&nbsp; &amp; _WDT_OFF &amp; _PWRTE_OFF &amp; _INTOSC_OSC_NOCLKOUT&nbsp;&nbsp;&nbsp; 


;----------------------- VARIAVEIS E EQUIVALENCIAS ---------------------


w_temp&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; equ&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; 0x23&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; ;Quando eu precisar de 2 valores 

contador&nbsp;&nbsp;&nbsp; equ&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; 0x24&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; ;contador que armazena o valor a ser mostrado no lcd
countLO&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; equ&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; 0x25
countHI&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; equ&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; 0x26



;------------------------------ ENDEREÇO 00000 ---------------------------------

&nbsp;&nbsp;&nbsp; org&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; 0x0000
&nbsp;&nbsp;&nbsp; goto&nbsp;&nbsp;&nbsp; INICIO

;----------------------------- INTERRUPCAO -------------------------------------
&nbsp;&nbsp;&nbsp; org&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; 0x0004
&nbsp;&nbsp;&nbsp; incf&nbsp;&nbsp;&nbsp; countHI
&nbsp;&nbsp;&nbsp; bcf&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; intcon,T0IF
&nbsp;&nbsp;&nbsp; retfie&nbsp;&nbsp;&nbsp; 

;----------------------- INICIALIZAÇÃO DO PROGRAMA ---------------------

&nbsp;&nbsp;&nbsp; 
INICIO
&nbsp;&nbsp;&nbsp; movlw&nbsp;&nbsp;&nbsp; 0x07&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; ;Desativa a opcao de comparadores nos pinos
&nbsp;&nbsp;&nbsp;&nbsp; movwf&nbsp;&nbsp;&nbsp; cmcon&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; ;Ra0-Ra3 (datasheet pag63-64)que
&nbsp;&nbsp;&nbsp; 
&nbsp;&nbsp;&nbsp; bsf&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; status,rp0&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; ;Vai para o banco 1 da RAM a'
&nbsp;&nbsp;&nbsp; clrf&nbsp;&nbsp;&nbsp; trisb&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; ;Portb todo como OUTPUT
&nbsp;&nbsp;&nbsp; movlw&nbsp;&nbsp;&nbsp; 0xff
&nbsp;&nbsp;&nbsp; movwf&nbsp;&nbsp;&nbsp; trisa&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; ;port A inteiro como INPUT&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; 
&nbsp;&nbsp;&nbsp; bsf&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; option_reg,PSA&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; ;prescale para o Timer0&nbsp;&nbsp;&nbsp; 
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; ;como o option_reg inteiro fica em nl=1 ao iniciar, o prescale esta para o wdt,&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; 
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; ;que no caso nao sera utilizado.
&nbsp;&nbsp;&nbsp; bcf&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; option_reg,T0CS&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; ;utiliza o clock interno para fazer a contagem...

&nbsp;&nbsp;&nbsp; bcf&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; status,rp0&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; ;Volta para o banco 0
&nbsp;&nbsp;&nbsp; clrf &nbsp;&nbsp;&nbsp; intcon&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; ;todas as interrupcoes desativas
&nbsp;&nbsp;&nbsp; bsf&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; intcon,T0IE&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; ;Habilita a interrupacao do timer0
&nbsp;&nbsp;&nbsp; 
&nbsp;&nbsp;&nbsp; 
&nbsp;&nbsp;&nbsp; 
;-------------------------- PROGRAMA PRINCIPAL ----------------------------------
&nbsp;&nbsp;&nbsp; clrf&nbsp;&nbsp;&nbsp; contador&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; ;zera o contador

principal&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; 
&nbsp;&nbsp;&nbsp; movf&nbsp;&nbsp;&nbsp; contador,w&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; 
&nbsp;&nbsp;&nbsp; call&nbsp;&nbsp;&nbsp; decodifica&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; ;pega o valor a ser impresso no display que seja correspondente ao valor de contador
&nbsp;&nbsp;&nbsp; movwf&nbsp;&nbsp;&nbsp; portb&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; ;atualiza display
&nbsp;&nbsp;&nbsp; call&nbsp;&nbsp;&nbsp; atualiza_contador&nbsp;&nbsp;&nbsp; ;vai ver a situacao do potenciometro
&nbsp;&nbsp;&nbsp; goto &nbsp;&nbsp;&nbsp; principal
&nbsp;&nbsp;&nbsp; 
;----------------------- Sub Rotina - Delay - ------------------------------------


atualiza_contador
&nbsp;&nbsp;&nbsp; call&nbsp;&nbsp;&nbsp; c_limpa&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; ;garante que o capacitor tera 0V antes de comecar a carregar
&nbsp;&nbsp;&nbsp; call&nbsp;&nbsp;&nbsp; c_verifica&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; ;atualiza os valor de countHI e countLO
&nbsp;&nbsp;&nbsp; movlw&nbsp;&nbsp;&nbsp; 0x08&nbsp;&nbsp;&nbsp; 
&nbsp;&nbsp;&nbsp; subwf&nbsp;&nbsp;&nbsp; countHI,w&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; ;countHI-9=&gt;w
&nbsp;&nbsp;&nbsp; btfsc&nbsp;&nbsp;&nbsp; status,c&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; ;Se o valor der negativo entao tudo bem pois c=0 entao pula a proxima linha 
&nbsp;&nbsp;&nbsp; goto&nbsp;&nbsp;&nbsp; estouro_countHI
&nbsp;&nbsp;&nbsp; movf&nbsp;&nbsp;&nbsp; countHI,w&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; ;joga o valor de countHI em w
&nbsp;&nbsp;&nbsp; call&nbsp;&nbsp;&nbsp; arruma_countHI
&nbsp;&nbsp;&nbsp; movwf&nbsp;&nbsp;&nbsp; contador&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; ;
&nbsp;&nbsp;&nbsp; btfsc&nbsp;&nbsp;&nbsp; countLO,7&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; ;O TMR0 chegou ate a metade aproximadamente 128???
&nbsp;&nbsp;&nbsp; incf&nbsp;&nbsp;&nbsp; contador&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; ;se sim entao soma uma no contador para ser atualizado corretamente
&nbsp;&nbsp;&nbsp; retlw &nbsp;&nbsp;&nbsp; 0x00&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; ;Retornapara o principal





estouro_countHi
&nbsp;&nbsp;&nbsp; movlw&nbsp;&nbsp;&nbsp; 0x10
&nbsp;&nbsp;&nbsp; movwf&nbsp;&nbsp;&nbsp; contador&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; ;faz o countHi ficar obrigatoriamente com o valor 9
&nbsp;&nbsp;&nbsp; retlw&nbsp;&nbsp;&nbsp; 0x00
&nbsp;&nbsp;&nbsp; 
arruma_countHI
&nbsp;&nbsp;&nbsp; 
&nbsp;&nbsp;&nbsp; addwf&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; PCL&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; ;Faz com que o programa "Pule" para a linha
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; ;com o codigo deseja
&nbsp;&nbsp;&nbsp; retlw&nbsp;&nbsp;&nbsp; 0x00
&nbsp;&nbsp;&nbsp; retlw&nbsp;&nbsp;&nbsp; &nbsp;0x02
&nbsp;&nbsp;&nbsp; retlw&nbsp;&nbsp;&nbsp; &nbsp;0x04
&nbsp;&nbsp;&nbsp; retlw&nbsp;&nbsp;&nbsp; &nbsp;0x06
&nbsp;&nbsp;&nbsp; retlw&nbsp;&nbsp;&nbsp; &nbsp;0x08
&nbsp;&nbsp;&nbsp; retlw&nbsp;&nbsp;&nbsp; &nbsp;0x0A
&nbsp;&nbsp;&nbsp; retlw&nbsp;&nbsp;&nbsp; &nbsp;0x0C
&nbsp;&nbsp;&nbsp; retlw&nbsp;&nbsp;&nbsp; &nbsp;0x0E


c_verifica
&nbsp;&nbsp;&nbsp; bsf&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; status,rp0&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; ;vai para o banco 1
&nbsp;&nbsp;&nbsp; movlw&nbsp;&nbsp;&nbsp; 0xff&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; ;deixa o porta como imput
&nbsp;&nbsp;&nbsp; movwf&nbsp;&nbsp;&nbsp; trisa
&nbsp;&nbsp;&nbsp; bcf&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; status,rp0&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; ;volta para banco 0
&nbsp;&nbsp;&nbsp; clrf&nbsp;&nbsp;&nbsp; countHI&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; ;zera a parte mais significativa do Counter
&nbsp;&nbsp;&nbsp; clrf&nbsp;&nbsp;&nbsp; TMR0&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; ;zera o contador
&nbsp;&nbsp;&nbsp; bcf&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; intcon,T0IF&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; ;garante que o bit de estouro do timer0 esteja em 0 quando ativado as int.
&nbsp;&nbsp;&nbsp; bsf&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; intcon,GIE&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; ;incia interrupcao
&nbsp;&nbsp;&nbsp; btfss&nbsp;&nbsp;&nbsp; porta,2&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; ;Verifica se o RA2 ja foi para NL =1&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; 
&nbsp;&nbsp;&nbsp; goto&nbsp;&nbsp;&nbsp; $-1&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; ;fica verificando ate ser estourado
&nbsp;&nbsp;&nbsp; movf&nbsp;&nbsp;&nbsp; TMR0,w&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; ;joga o valor de TMR0 para countLO
&nbsp;&nbsp;&nbsp; bcf&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; intcon,GIE&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; ;desabilita interrupcoes
&nbsp;&nbsp;&nbsp; btfsc&nbsp;&nbsp;&nbsp; intcon,GIE&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; ;espera de fato a mesma ser concretizada
&nbsp;&nbsp;&nbsp; goto&nbsp;&nbsp;&nbsp; $-2
&nbsp;&nbsp;&nbsp; movwf&nbsp;&nbsp;&nbsp; countLO&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; ;armazena a parte baixa do contador
&nbsp;&nbsp;&nbsp; retlw&nbsp;&nbsp;&nbsp; 0x00&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; ;volta zerando o w
&nbsp;&nbsp;&nbsp; 

c_limpa
&nbsp;&nbsp;&nbsp; bsf&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; status,rp0&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; ;vai para banco 1
&nbsp;&nbsp;&nbsp; clrf&nbsp;&nbsp;&nbsp; trisa&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; ;deixa o porta como saida
&nbsp;&nbsp;&nbsp; bcf&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; status,rp0&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; ;volta para o banco0
&nbsp;&nbsp;&nbsp; clrf&nbsp;&nbsp;&nbsp; porta&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; ;garante que o pino ligado ao capacitor va para 0 descarregando assim o capacitor
&nbsp;&nbsp;&nbsp; retlw&nbsp;&nbsp;&nbsp; 0x00&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; ;volta para a chamada principal com w=0


;------------------------------------------------------------


decodifica
&nbsp;&nbsp;&nbsp; addwf&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; PCL&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; ;Faz com que o programa "Pule" para a linha
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; ;com o codigo deseja
&nbsp;&nbsp;&nbsp; ;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; ABCDEFG
&nbsp;&nbsp;&nbsp; retlw&nbsp;&nbsp;&nbsp; B'01111110'&nbsp;&nbsp;&nbsp; ; 0
&nbsp;&nbsp;&nbsp; retlw&nbsp;&nbsp;&nbsp; &nbsp;B'00110000'&nbsp;&nbsp;&nbsp; ; 1
&nbsp;&nbsp;&nbsp; retlw&nbsp;&nbsp;&nbsp; &nbsp;B'01101101'&nbsp;&nbsp;&nbsp; ; 2
&nbsp;&nbsp;&nbsp; retlw&nbsp;&nbsp;&nbsp; &nbsp;B'01111001'&nbsp;&nbsp;&nbsp; ; 3
&nbsp;&nbsp;&nbsp; retlw&nbsp;&nbsp;&nbsp; &nbsp;B'00110011'&nbsp;&nbsp;&nbsp; ; 4
&nbsp;&nbsp;&nbsp; retlw&nbsp;&nbsp;&nbsp; &nbsp;B'01011011'&nbsp;&nbsp;&nbsp; ; 5&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; 
&nbsp;&nbsp;&nbsp; retlw&nbsp;&nbsp;&nbsp; &nbsp;B'01011111'&nbsp;&nbsp;&nbsp; ; 6
&nbsp;&nbsp;&nbsp; retlw&nbsp;&nbsp;&nbsp; &nbsp;B'01110000'&nbsp;&nbsp;&nbsp; ; 7
&nbsp;&nbsp;&nbsp; retlw&nbsp;&nbsp;&nbsp; &nbsp;B'01111111'&nbsp;&nbsp;&nbsp; ; 8
&nbsp;&nbsp;&nbsp; retlw&nbsp;&nbsp;&nbsp; &nbsp;B'01111011'&nbsp;&nbsp;&nbsp; ; 9
&nbsp;&nbsp;&nbsp; retlw&nbsp;&nbsp;&nbsp; &nbsp;B'01110111'&nbsp;&nbsp;&nbsp; ;A
&nbsp;&nbsp;&nbsp; retlw&nbsp;&nbsp;&nbsp; &nbsp;B'00011111'&nbsp;&nbsp;&nbsp; ;B
&nbsp;&nbsp;&nbsp; retlw&nbsp;&nbsp;&nbsp; &nbsp;B'01001110'&nbsp;&nbsp;&nbsp; ;C
&nbsp;&nbsp;&nbsp; retlw&nbsp;&nbsp;&nbsp; &nbsp;B'00111101'&nbsp;&nbsp;&nbsp; ;D
&nbsp;&nbsp;&nbsp; retlw&nbsp;&nbsp;&nbsp; &nbsp;B'01001111'&nbsp;&nbsp;&nbsp; ;E
&nbsp;&nbsp;&nbsp; retlw&nbsp;&nbsp;&nbsp; &nbsp;B'01000111'&nbsp;&nbsp;&nbsp; ;F
&nbsp;&nbsp;&nbsp; retlw&nbsp;&nbsp;&nbsp; &nbsp;B'00001000'&nbsp;&nbsp;&nbsp; ;_

;---------------------------- FIM --------------------------------

&nbsp;&nbsp;&nbsp; end