Escolar Documentos
Profissional Documentos
Cultura Documentos
V1
5V
+V
D2 R2
1N4148 10k (14)Vdd
MCLR\(4)
+
C3 (6)RB0
S1 10uF
R1
360R
PIC 16F628A
D1
LED1
(5)Vss
(15) (16)
Clk-in Clk-out
XTAL1
4.000MHZ
C1 C2
33pF 33pF
;------------------------------------------------------------------------------
;------------------------------------------------------------------------------
; MEMÓRIA DE PROGRAMA
;------------------------------------------------------------------------------
org 0 ; define inicio do programa a partir do end. 0h
goto início ; desvia o progrma para o label (rótulo) início
;------------------------------------------------------------------------------
; INÍCIO DA ROTINA DE INTERRUPÇÃO
;------------------------------------------------------------------------------
org 4 ; sempre inicia no end.4h as interrup.no PIC
; rotinas ...............................
retfie ; comando de retorno de interrupção
;------------------------------------------------------------------------------
; INÍCIO DO PROGRAMA
;------------------------------------------------------------------------------
início:
movlw 0 ; registrador w=0 (decimal)
movwf INTCON ; registrador INTCON=B'00000000', desabilito todas as interrupçoões
bcf STATUS, IRP ; clear no bit irp do reg.status, pré-seleciono banco 0 e 1
bcf STATUS, RP1 ; clear no bit RP1 (RP1=0)
bsf STATUS, RP0 ; set bit RP0 (RP0=1) com estas duas linhas seleciono o banco 1, onde está o TRISB e TRISA
;-------------------------------------------------------------------------------
; Poderia usar o comando BANKSEL que é uma diretiva para seleção de banco de memória do MPLAB
; ex. BANKSEL TRISB, não precisaria digitar as duas linhas anteriores
; Também poderia usar o comando: movlw B'001XXXXX' e após movwf STATUS, onde x = a qualquer valor;
; substituiriam as três linhas anteriores.
;-------------------------------------------------------------------------------
movwf TRISB ; registrador TRISB=0 (B'00000000') , OU SEJA, PINOS DO PORTB CONFIGURADOS COMO
SAÍDAS
movlw 0FFH ; w=B'11111111'
movwf TRISA ; TRISA=B'11111111'pinos configurados como entradas
movlw 24 ; w=B'00011000'
movwf OPTION_REG ; registrador OPTION_REG=B'00011000', verificar nos livros esta config.c/ estes valores
bcf STATUS, RP0 ; clear bit RP0, seleciono banco 0
movlw 0
movwf PORTB ; zero as saídas do PORTB
volta:
bsf PORTB,0 ; set pino PB0 do PORTB
call tempo
bcf PORTB,0 ; clear PB0 do PORTB
call tempo
goto volta
tempo: ; início da rotina de tempo (s/uso dos timers),label de chamada para a função call ou outra
movlw 2 ; onde t1 é um valor numérico, base numérica (1uS)
; em uso (decimal, hexa, binário etc.)
movwf x ; variável x, onde ficara c/ o valor x=t1 (1uS)
tempo1:
movlw 250 ; onde t2 é um valor numérico (1uS) y=250
movwf y ; varável y, onde y=t2 (1uS)
tempo2:
movlw 248 ; onde t3 é um valor numérico (1uS) m=248
movwf m ; varável m, onde m=248 (1uS)
tempo3:
nop ; queima 1Us,para o clock de 4MHz (1uS)
decfsz m ; decrem.z e se m=0 salta próxima instrução (1uS ou 2uS)
; (2uS se saltar ou 1US se não saltar)
goto tempo3 ; ir pra o label tempo3 (2uS)
decfsz y ; decrem.y e se y=0 salta próxima instrução (1uS ou 2uS)
goto tempo2 ; ir pra o label tempo2 (2uS)
decfsz x ; decrem.x e se x=0 salta próxima instrução (1uS ou 2uS)
goto tempo1 ; ir pra o label tempo1 (2uS)
return ; função de retorno de subrotina ou desvio (2uS)
end
D2 R2
1N4148 10k (14)Vdd
MCLR\(4)(7)RB1
+
C3 (6)RB0
S1 10uF
R1 R3
360R 360R
PIC 16F628A
D1 D3
LED1 LED2
(5)Vss
(15) (16)
Clk-in Clk-out
XTAL1
4.000MHZ
C1 C2
33pF 33pF
;------------------------------------------------------------------------------
; MEMÓRIA DE PROGRAMA
;------------------------------------------------------------------------------
org 0 ; define inicio do programa a partir do end. 0h
goto início ; desvia o progrma para o label (rótulo) início
;------------------------------------------------------------------------------
; INÍCIO DA ROTINA DE INTERRUPÇÃO
;------------------------------------------------------------------------------
org 4 ; sempre inicia no end.4h as interrup.no PIC
; rotinas ...............................
retfie ; comando de retorno de interrupção
;------------------------------------------------------------------------------
; INÍCIO DO PROGRAMA - inicialização do uC
;------------------------------------------------------------------------------
início:
movlw 0 ; registrador w=0 (decimal)
movwf INTCON ; registrador INTCON=B'00000000', desabilito todas as interrupçoões
bcf STATUS, IRP ; clear no bit irp do reg.status, pré-seleciono banco 0 e 1
bcf STATUS, RP1 ; clear no bit RP1 (RP1=0)
bsf STATUS, RP0 ; set bit RP0 (RP0=1) com estas duas linhas seleciono o banco 1, onde está o TRISB e TRISA
movwf TRISB ; registrador TRISB=0 (B'00000000') , OU SEJA, PINOS DO PORTB CONFIGURADOS COMO
SAÍDAS
movlw 0FFH ; w=B'11111111'
movwf TRISA ; TRISA=B'11111111'pinos configurados como entradas
movlw 24 ; w=B'00011000'
movwf OPTION_REG ; registrador OPTION_REG=B'00011000', verificar nos livros esta config.c/ estes valores
bcf STATUS, RP0 ; clear bit RP0, seleciono banco 0
movlw 0
movwf PORTB ; zero as saídas do PORTB
;--------------------------------------------------------------------------------
; programa principal - aplicação
;--------------------------------------------------------------------------------
volta:
bsf PORTB,0 ; set pino PB0 do PORTB
bcf PORTB,1 ; clear pino PB1
call tempo
bcf PORTB,0 ; clear PB0 do PORTB
bsf PORTB,1 ; set pino PB1
call tempo
goto volta
;---------------------------------------------------------------------------------
; Rotinas de tempo
;---------------------------------------------------------------------------------
tempo: ; início da rotina de tempo (s/uso dos timers),label de chamada para a função call ou outra
movlw 2 ; onde t1 é um valor numérico, base numérica (1uS)
; em uso (decimal, hexa, binário etc.)
movwf x ; variável x, onde ficara c/ o valor x=t1 (1uS)
tempo1:
movlw 250 ; onde t2 é um valor numérico (1uS) y=250
movwf y ; varável y, onde y=t2 (1uS)
tempo2:
movlw 248 ; onde t3 é um valor numérico (1uS) m=248
movwf m ; varável m, onde m=248 (1uS)
tempo3:
nop ; queima 1Us,para o clock de 4MHz (1uS)
decfsz m ; decrem.z e se m=0 salta próxima instrução (1uS ou 2uS)
; (2uS se saltar ou 1US se não saltar)
goto tempo3 ; ir pra o label tempo3 (2uS)
decfsz y ; decrem.y e se y=0 salta próxima instrução (1uS ou 2uS)
goto tempo2 ; ir pra o label tempo2 (2uS)
decfsz x ; decrem.x e se x=0 salta próxima instrução (1uS ou 2uS)
goto tempo1 ; ir pra o label tempo1 (2uS)
return ; função de retorno de subrotina ou desvio (2uS)
end
;------------------------------------------------------------------------------
; MEMÓRIA DE PROGRAMA
;------------------------------------------------------------------------------
org 0 ; define inicio do programa a partir do end. 0h
goto início ; desvia o progrma para o label (rótulo) início
;------------------------------------------------------------------------------
; INÍCIO DA ROTINA DE INTERRUPÇÃO
;------------------------------------------------------------------------------
org 4 ; sempre inicia no end.4h as interrup.no PIC
; rotinas ...............................
retfie ; comando de retorno de interrupção
;------------------------------------------------------------------------------
; INÍCIO DO PROGRAMA - inicialização do uC
;------------------------------------------------------------------------------
início:
movlw 0 ; registrador w=0 (decimal)
movwf INTCON ; registrador INTCON=B'00000000', desabilito todas as interrupçoões
bcf STATUS, IRP ; clear no bit irp do reg.status, pré-seleciono banco 0 e 1
bcf STATUS, RP1 ; clear no bit RP1 (RP1=0)
bsf STATUS, RP0 ; set bit RP0 (RP0=1) com estas duas linhas seleciono o banco 1, onde está o TRISB e TRISA
bcf STATUS, C ; clear carry . É IMPORTANTE ESTE CLEAR, POIS O COMANDO DE ROTAÇÃO
; (RLF) USA ESTE FLAG
movwf TRISB ; registrador TRISB=0 (B'00000000') , OU SEJA, PINOS DO PORTB CONFIGURADOS COMO
SAÍDAS
movlw 0FFH ; w=B'11111111'
movwf TRISA ; TRISA=B'11111111'pinos configurados como entradas
movlw 24 ; w=B'00011000'
movwf OPTION_REG ; registrador OPTION_REG=B'00011000', verificar nos livros esta config.c/ estes valores
bcf STATUS, RP0 ; clear bit RP0, seleciono banco 0
movlw 0
movwf PORTB ; zero as saídas do PORTB
;--------------------------------------------------------------------------------
; programa principal - aplicação
;--------------------------------------------------------------------------------
movlw 128 ; w=b'10000000'
movwf PORTB ; portb=w=b'10000000'
volta:
rlf PORTB, 1 ; desloca bit à esquerda no PORTB ( o f=1, atua sobre o próprio registro)
call tempo ; chama subrotina de tempo
goto volta ; ir para label volta
;---------------------------------------------------------------------------------
; Rotinas de tempo
;---------------------------------------------------------------------------------
tempo: ; início da rotina de tempo (s/uso dos timers),label de chamada para a função call ou outra
movlw 2 ; onde t1 é um valor numérico, base numérica (1uS)
; em uso (decimal, hexa, binário etc.)
movwf x ; variável x, onde ficara c/ o valor x=t1 (1uS)
tempo1:
movlw 250 ; onde t2 é um valor numérico (1uS) y=250
movwf y ; varável y, onde y=t2 (1uS)
tempo2:
movlw 248 ; onde t3 é um valor numérico (1uS) m=248
movwf m ; varável m, onde m=248 (1uS)
tempo3:
nop ; queima 1Us,para o clock de 4MHz (1uS)
decfsz m ; decrem.z e se m=0 salta próxima instrução (1uS ou 2uS)
; (2uS se saltar ou 1US se não saltar)
goto tempo3 ; ir pra o label tempo3 (2uS)
decfsz y ; decrem.y e se y=0 salta próxima instrução (1uS ou 2uS)
goto tempo2 ; ir pra o label tempo2 (2uS)
decfsz x ; decrem.x e se x=0 salta próxima instrução (1uS ou 2uS)
goto tempo1 ; ir pra o label tempo1 (2uS)
return ; função de retorno de subrotina ou desvio (2uS)
end
D9 R2
1N4148 10k (14)Vdd
(13)RB7
+
MCLR\(4)
C3 (6)RB0
S1 10uF
R1 R8
360R Total de 8 conjuntos 360R
PIC 16F628A ..........................
D1 D8
LED1 LED8
(5)Vss
(15) (16)
Clk-in Clk-out
XTAL1
4.000MHZ
C1 C2
33pF 33pF
;------------------------------------------------------------------------------
; TABELA DE DEFINIÇÕES DE RAM E CONSTANTES (defino nomes associados a valores)
;------------------------------------------------------------------------------
x equ 20h ; define variável auxiliar x no end.20h da RAM (hexadecimal)
y equ 21h ; define variável auxiliar y no end.21h da RAM(hexadecimal)
m equ 22h ; define variável auxiliar m no end.22h da RAM (hexadecimal)
S1 equ 0 ; sensor 1 que usara o pino 0 do PORTA
;------------------------------------------------------------------------------
;------------------------------------------------------------------------------
; MEMÓRIA DE PROGRAMA
;------------------------------------------------------------------------------
org 0 ; define inicio do programa a partir do end. 0h
goto início ; desvia o progrma para o label (rótulo) início
;------------------------------------------------------------------------------
; INÍCIO DA ROTINA DE INTERRUPÇÃO
;------------------------------------------------------------------------------
org 4 ; sempre inicia no end.4h as interrup.no PIC
; rotinas ...............................
retfie ; comando de retorno de interrupção
;------------------------------------------------------------------------------
; INÍCIO DO PROGRAMA - inicialização do uC
;------------------------------------------------------------------------------
início:
movlw 0 ; registrador w=0 (decimal)
movwf INTCON ; registrador INTCON=B'00000000', desabilito todas as interrupçoões
bcf STATUS, IRP ; clear no bit irp do reg.status, pré-seleciono banco 0 e 1
bcf STATUS, RP1 ; clear no bit RP1 (RP1=0)
bsf STATUS, RP0 ; set bit RP0 (RP0=1) com estas duas linhas seleciono o banco 1, onde está o TRISB e TRISA
bcf STATUS, C ; clear carry
movwf TRISB ; registrador TRISB=0 (B'00000000') , OU SEJA, PINOS DO PORTB CONFIGURADOS
; COMO SAÍDAS
movlw 0FFH ; w=B'11111111'
movwf TRISA ; TRISA=B'11111111'pinos configurados como entradas
movlw 24 ; w=B'00011000'
movwf OPTION_REG ; registrador OPTION_REG=B'00011000', verificar nos livros esta config.c/ estes valores
bcf STATUS, RP0 ; clear bit RP0, seleciono banco 0
movlw 7 ; w=B'00000111'
movwf CMCON ; cmcon=w, desligo o comparador analógico (o reset não faz isso)
movlw 0 ; w=0
movwf CCP1CON ; CCP1CON=W=, desliga o módulo CCP (o reset faz isso, mas forçar o sinal por garantia)
movwf PORTB ; zero as saídas do PORTB (PORTB=w=0)
;--------------------------------------------------------------------------------
; programa principal - aplicação
;--------------------------------------------------------------------------------
sensor1:
nop ; gasto um ciclo de máquina
btfss PORTA, S1 ; se o bit S1 do portA for igual a 1,pula a próxima instrução
goto sensor1 ; se esta aqui é porque S1=0, volta para sensor1 (fica testando o sensor S1)
bsf PORTB,0 ; liga o led 1 conectado em RB0
call tempo ; chama rotina de tempo (para deixar o sinalizador led 1 ligado por um tempo)
bcf PORTB,0 ; desliga o led 1
goto sensor1 ; desvia para o sensor1, volta a testar o sensor S1
;---------------------------------------------------------------------------------
; Rotinas de tempo
;---------------------------------------------------------------------------------
tempo: ; início da rotina de tempo (s/uso dos timers),label de chamada para a função call ou outra
movlw 2 ; onde t1 é um valor numérico, base numérica (1uS)
; em uso (decimal, hexa, binário etc.)
movwf x ; variável x, onde ficara c/ o valor x=t1 (1uS)
tempo1:
movlw 250 ; onde t2 é um valor numérico (1uS) y=250
movwf y ; varável y, onde y=t2 (1uS)
tempo2:
movlw 248 ; onde t3 é um valor numérico (1uS) m=248
movwf m ; varável m, onde m=248 (1uS)
tempo3:
nop ; queima 1Us,para o clock de 4MHz (1uS)
decfsz m ; decrem.z e se m=0 salta próxima instrução (1uS ou 2uS)
; (2uS se saltar ou 1US se não saltar)
goto tempo3 ; ir pra o label tempo3 (2uS)
decfsz y ; decrem.y e se y=0 salta próxima instrução (1uS ou 2uS)
goto tempo2 ; ir pra o label tempo2 (2uS)
decfsz x ; decrem.x e se x=0 salta próxima instrução (1uS ou 2uS)
goto tempo1 ; ir pra o label tempo1 (2uS)
return ; função de retorno de subrotina ou desvio (2uS)
end
V1
5V
+V
D2 R2 S1
1N4148 10k (14)Vdd
(17)RA0
MCLR\(4)
+
C3 (6)RB0
RESET 10uF
R1
360R
PIC 16F628A R3
D1 1k
LED1
(5)Vss
(15) (16)
Clk-in Clk-out
XTAL1
4.000MHZ
C1 C2
33pF 33pF
Entrada sinal
D2 R2
1N4148 10k (14)Vdd
(17)RA0 S1
MCLR\(4)
(6)RB0
+
C3
RESET 10uF (7)RB1
R4 R1
360R 360R
PIC 16F628A R3
D3 D1 1k
LED2 LED1
(5)Vss
(15) (16)
Clk-in Clk-out
XTAL1
4.000MHZ
C1 C2
33pF 33pF
;------------------------------------------------------------------------------
; FORMULÁRIO PADRÃO PARA USO EM PROGRAMAÇÃO COM MICROCONTROLADORES
; DA LINHA PIC ( MICROCHIP ). COM USO DO COMPILADOR MPASWIN.
;------------------------------------------------------------------------------
; ** Os registros da CPU serão escritas com letras maiúsculas, e a-
; pós " ; " os comentários não serão considerados pelo compilador.
;------------------------------------------------------------------------------
; PROJETO : Detector de nível de sinal DATA : 26/11/2008
;------------------------------------------------------------------------------
; AUTOR : Maurício Madeira Oliveira
;------------------------------------------------------------------------------
list p=16F628A ;para qual processador o código será gerado
radix dec ;padrão decimal para valores sem identificação
include <p16F628A.inc> ;anexa arquivo def.16F628A
__CONFIG _CP_OFF & _PWRTE_OFF & _BODEN_OFF & _MCLRE_ON & _INTRC_OSC_NOCLKOUT & _LVP_OFF
;------------------------------------------------------------------------------
; TABELA DE DEFINIÇÕES DE RAM E CONSTANTES (defino nomes associados a valores)
;------------------------------------------------------------------------------
x equ 20h ; define variável auxiliar x no end.20h da RAM (hexadecimal)
y equ 21h ; define variável auxiliar y no end.21h da RAM(hexadecimal)
m equ 22h ; define variável auxiliar m no end.22h da RAM (hexadecimal)
S1 equ 0 ; sensor 1 que usara o pino 0 do PORTA
;------------------------------------------------------------------------------
;------------------------------------------------------------------------------
; MEMÓRIA DE PROGRAMA
;------------------------------------------------------------------------------
org 0 ; define inicio do programa a partir do end. 0h
goto início ; desvia o progrma para o label (rótulo) início
;------------------------------------------------------------------------------
; INÍCIO DA ROTINA DE INTERRUPÇÃO
;------------------------------------------------------------------------------
org 4 ; sempre inicia no end.4h as interrup.no PIC
; rotinas ...............................
retfie ; comando de retorno de interrupção
;------------------------------------------------------------------------------
; INÍCIO DO PROGRAMA - inicialização do uC
;------------------------------------------------------------------------------
início:
movlw 0 ; registrador w=0 (decimal)
movwf INTCON ; registrador INTCON=B'00000000', desabilito todas as interrupçoões
bcf STATUS, IRP ; clear no bit irp do reg.status, pré-seleciono banco 0 e 1
bcf STATUS, RP1 ; clear no bit RP1 (RP1=0)
bsf STATUS, RP0 ; set bit RP0 (RP0=1) com estas duas linhas seleciono o banco 1, onde está o TRISB e TRISA
bcf STATUS, C ; clear carry
movwf TRISB ; registrador TRISB=0 (B'00000000') , OU SEJA, PINOS DO PORTB CONFIGURADOS
COMO SAÍDAS
movlw 0FFH ; w=B'11111111'
movwf TRISA ; TRISA=B'11111111'pinos configurados como entradas
movlw 24 ; w=B'00011000'
movwf OPTION_REG ; registrador OPTION_REG=B'00011000', verificar nos livros esta config.c/ estes valores
bcf STATUS, RP0 ; clear bit RP0, seleciono banco 0
movlw 7 ; w=B'00000111'
movwf CMCON ; cmcon=w, desligo o comparador analógico (o reset não faz isso)
movlw 0 ; w=0
movwf CCP1CON ; CCP1CON=W=, desliga o módulo CCP (o reset faz isso, mas forçar o sinal por garantia)
movwf PORTB ; zero as saídas do PORTB (PORTB=w=0)
;--------------------------------------------------------------------------------
; programa principal - aplicação
;--------------------------------------------------------------------------------
sensor1:
nop ; gasto um ciclo de máquina
btfss PORTA, S1 ; se o bit S1 do portA for igual a 1,pula a próxima instrução
goto sensor2 ; desvia para sensor2 (label), pois RA0 (S1) está em zero (nível baixo)
bsf PORTB,0 ; liga RB0 pois S1=1 (nível alto do sinal amostrado)
bcf PORTB,1 ; desliga RB1
goto sensor1 ; volta à sensor1 para continuar a testar o nível do sinal
sensor2:
bcf PORTB,0 ; desliga RB0, pois sinal amostrado têm nível baixo (zero)
bsf PORTB,1 ; liga RB0
goto sensor1 ; volta para sensor1
end
D2
1N4148 R2 Entada Gnd
10k
DISP1
MCLR\(4)
(14)Vdd R4
500R abcdefg.
PIC 16F628A
+
C3
S1 10uF
(03)RA4
(06)RB0
(07)RB1
(08)RB2
(09)RB3
(10)RB4
(11)RB5
(12)RB6
(13)RB7
(5)Vss
(15) (16)
Clk-in Clk-out
R3 R1
XTAL1 10k 360R
4.000MHZ
D1
C1 C2 LED1
33pF 33pF
;------------------------------------------------------------------------------
; INÍCIO DO PROGRAMA - inicialização do uC
;------------------------------------------------------------------------------
início:
movlw B'10000000' ; w=10000000b
movwf INTCON ; INTCON=w , GIE esta habilitada
bcf STATUS, IRP ; clear no bit irp do reg.status, pré-seleciono banco 0 e 1
bcf STATUS, RP1 ; clear no bit RP1 (RP1=0)
bsf STATUS, RP0 ; set bit RP0 (RP0=1) com estas duas linhas seleciono o banco 1, onde está o TRISB e TRISA
movlw 0
movwf TRISB ; registrador TRISB=0 (B'00000000') , OU SEJA, PINOS DO PORTB CONFIGURADOS
COMO SAÍDAS
movlw 0FFH ; w=B'11111111'
movwf TRISA ; TRISA=B'11111111'pinos configurados como entradas
movlw B'11111000' ; w=11111000b
movwf OPTION_REG
;(OPTION=w|RPBU\=1|INTEDEG=1|TOCS=1|TOSE=1|PSA=1|PS2=0|PS1=0|PS0=0|==>T0CS=1contagem por RA4...)
;---------------------------------------------------------------------------------
; Rotinas de tempo
;---------------------------------------------------------------------------------
tempo: ; início da rotina de tempo (s/uso dos timers),label de chamada para a função call ou outra
movlw 2 ; onde t1 é um valor numérico, base numérica (1uS)
; em uso (decimal, hexa, binário etc.)
movwf x ; variável x, onde ficara c/ o valor x=t1 (1uS)
tempo1:
movlw 250 ; onde t2 é um valor numérico (1uS) y=250
movwf y ; varável y, onde y=t2 (1uS)
tempo2:
movlw 248 ; onde t3 é um valor numérico (1uS) m=248
movwf m ; varável m, onde m=248 (1uS)
tempo3:
nop ; queima 1Us,para o clock de 4MHz (1uS)
decfsz m ; decrem.z e se m=0 salta próxima instrução (1uS ou 2uS)
; (2uS se saltar ou 1US se não saltar)
goto tempo3 ; ir pra o label tempo3 (2uS)
decfsz y ; decrem.y e se y=0 salta próxima instrução (1uS ou 2uS)
goto tempo2 ; ir pra o label tempo2 (2uS)
decfsz x ; decrem.x e se x=0 salta próxima instrução (1uS ou 2uS)
goto tempo1 ; ir pra o label tempo1 (2uS)
return ; função de retorno de subrotina ou desvio (2uS)
end
PIC 16F628A
+
C3
S1 10uF
(06)RB0
(07)RB1
(08)RB2
(09)RB3
(10)RB4
(11)RB5
(12)RB6
(13)RB7
(17)RA0
(18)RA1
(5)Vss
(15) (16)
Clk-in Clk-out
XTAL1
4.000MHZ
C1 C2
33pF 33pF
M equ 0x4D
I equ 0x49
;C equ 0x43 ; C não pode ser usada pois é nome p/ carry no uC
R equ 0x52
O equ 0x4F
N equ 0x4E
T equ 0x54
L equ 0x4C
A equ 0x41
D equ 0x44
U equ 0x55
S equ 0x53
E equ 0x45
# equ 0x23
; espaço em branco 0x20
;------------------------------------------------------------------------------
;------------------------------------------------------------------------------
; MEMÓRIA DE PROGRAMA
;------------------------------------------------------------------------------
org 0 ; define inicio do programa a partir do end. 0h
goto início ; desvia o progrma para o label (rótulo) início
;------------------------------------------------------------------------------
; INÍCIO DA ROTINA DE INTERRUPÇÃO
;------------------------------------------------------------------------------
org 4 ; sempre inicia no end.4h as interrup.no PIC
; rotnas
retfie ; comando de retorno de interrupção
;------------------------------------------------------------------------------
; INÍCIO DO PROGRAMA - inicialização do uC
;------------------------------------------------------------------------------
início:
movlw B'00000000' ; w=00000000b
movwf INTCON ; INTCON=w , desabilitada as interrupções
bcf STATUS, IRP ; clear no bit irp do reg.status, pré-seleciono banco 0 e 1
bcf STATUS, RP1 ; clear no bit RP1 (RP1=0)
bsf STATUS, RP0 ; set bit RP0 (RP0=1) com estas duas linhas seleciono o banco 1, onde está o TRISB e TRISA
;-------------------------------------------------------------------------------
; Poderia usar o comando BANKSEL que é uma diretiva para seleção de banco de memória do MPLAB
; ex. BANKSEL TRISB, não precisaria digitar as duas linhas anteriores
; Também poderia usar o comando: movlw B'001XXXXX' e após movwf STATUS, onde x= a qualquer valor
; substituiria as três linhas anteriores (o registro STATUS está presente nos 4 bancos).
;-------------------------------------------------------------------------------
movlw 0
movwf TRISB ; registrador TRISB=0 (B'00000000') , OU SEJA, PINOS DO PORTB CONFIGURADOS COMO
; SAÍDAS
movlw 0FCH ; w=B'11111100'
movwf TRISA ; TRISA=B'11111100'pinos configurados como entradas e PA.1 e PA.0 como saídas
movlw B'11011000' ; w=11011000b
movwf OPTION_REG ; OPTION=w ,|RPBU\=1|INTEDEG=1|TOCS=0|TOSE=1|PSA=1|PS2=0|PS1=0|PS0=0|==>ler
reg. p/ saber a config.
bcf STATUS, RP0 ; clear bit RP0, seleciono banco 0
movlw 7 ; w=B'00000111'
movwf CMCON ; cmcon=w, desligo o comparador analógico (o reset não faz isso)
movlw 0 ; w=0
movwf CCP1CON ; CCP1CON=W=, desliga o módulo CCP (o reset faz isso, mas forçar o sinal por garantia)
movwf PORTB ; zero as saídas do PORTB (PORTB=w=0)
movwf PORTA ; zero as saídas do PORTA
;--------------------------------------------------------------------------------
; programa principal - aplicação
;--------------------------------------------------------------------------------
bcf PORTA,con0
movlw 0x84 ; cursor na coluna 84 da linha 1
movwf PORTB
call time
bsf PORTA,con0 ; portA P0=1, RS=1 , LCD recebe dados
movlw 0x43 ; letra C
movwf PORTB
call time
movlw U
movwf PORTB
call time
movlw R
movwf PORTB
call time
movlw S
movwf PORTB
call time
movlw O
movwf PORTB
call time
movlw 0x20
movwf PORTB
call time
movlw D
movwf PORTB
call time
movlw E
movwf PORTB
call time
movlw 0x20
movwf PORTB
call time
bcf PORTA,con0 ; porta P0=0, RS=0 , LCD recebe inst.
movlw 0x0C0 ; w=C0h
movwf PORTB ; cursor vai p/2.linha, 1.coluna do LCD
call time
bsf PORTA,con0
movlw M
movwf PORTB
call time
movlw I
movwf PORTB
call time
movlw 0x43
movwf PORTB
call time
movlw R
movwf PORTB
call time
movlw O
movwf PORTB
call time
movlw 0x43
movwf PORTB
call time
movlw O
movwf PORTB
call time
movlw N
movwf PORTB
call time
movlw T
movwf PORTB
call time
movlw R
movwf PORTB
call time
movlw O
movwf PORTB
call time
movlw L
movwf PORTB
call time
movlw A
movwf PORTB
call time
movlw D
movwf PORTB
call time
movlw O
movwf PORTB
call time
movlw R
movwf PORTB
call time
; goto principal ; ou a linha ==> aqui: .....
aqui: goto aqui
;---------------------------------------------------------------------------------
; Rotinas de tempo
;---------------------------------------------------------------------------------
temp1:
movlw 18 ; 1uS
movwf y ; 1uS
temp2:
nop ; 1uS
decfsz y ; decrementa y de 1,se>0 exec.prox.inst.
goto temp2 ; se=0 salta prox.inst.
decfsz x ; 1uS
goto temp1 ; 1uS
return ; 1uS
+ PIC 16F628A
C3
S1 10uF
(09)RB3
(07)RB1
R3
(08)RB2 390R
(06)RB0
(10)RB4
(11)RB5
(12)RB6
(13)RB7
(17)RA0
(18)RA1
(5)Vss
(15) (16) D1
Clk-in Clk-out LED1
XTAL1
4.000MHZ
C1 C2
33pF 33pF
C U R S O
P I C 1 6 F 6 2 8