Beruflich Dokumente
Kultur Dokumente
;---------------------------------------------------------
;Autor: LONELY113
; http://lonely113.blogspot.com
;---------------------------------------------------------
include "p16f84a.inc"
list P=16f84a
subwf TIME,0
goto FIRST
subwf TIME,0
goto SECOND
subwf TIME,0
goto THIRD
subwf TIME,0
goto FOURTH
goto FINISH
goto FINISH
goto FINISH
goto FINISH
goto FINISH
;Subrutinas
movwf COUNT3
goto LOOP
movlw 0xFA
movwf COUNT1
decfsz COUNT2,1
goto LOOP
movlw 0xFA
movwf COUNT1
movlw 0xC8
movwf COUNT2
decfsz COUNT3,1
goto LOOP
incf TIME,1
subwf TIME,0
btfsc STATUS,2
clrf TIME
return
;Autor: LONELY113
; http://lonely113.blogspot.com
;Salidas: PUERTOB
;---------------------------------------------------------
include "p16f84a.inc"
list P=16f84a
clrf PORTA
clrf PORTB
bcf STATUS,0
movwf TIMES
call DELAY
decfsz TIMES
goto LEFT
movlw 0x07
movwf TIMES
call DELAY
decfsz TIMES
goto RIGHT
;Subrutinas
movwf COUNT2
movlw 0x20
movwf COUNT3
movlw 0xFF
movwf COUNT1
movwf COUNT2
decfsz COUNT3,1
goto LOOP
processor 16f877
include<p16f877.inc>
v0 equ h'24'
v1 equ h'25'
v2 equ h'26'
v3 equ h'27'
org 0h
goto INICIO
org 05h
INICIO:
clrf PORTA ;Limpia el puerto A
bsf STATUS,RP0
movlw h'0'
movwf ADCON1
movlw 3fh
CICLO:
movlw h'0'
movwf v0
movlw h'1'
movwf v1
movfw PORTA
btfsc STATUS,Z
goto MSB
movlw h'2'
movwf v2
movfw PORTA
btfsc STATUS,Z
goto LSB
movlw h'3'
movwf v3
movfw PORTA
btfsc STATUS,Z
goto DERIZQ
clrf PORTB
goto CICLO
movwf PORTB
call retardo
movlw h'FF'
movwf PORTB
call retardo
goto CICLO
movlw h'F0'
movwf PORTB
call retardo
goto CICLO
movlw h'0F'
movwf PORTB
call retardo
goto CICLO
movwf PORTB
call retardo
DER2:
rrf PORTB,1
call retardo
btfss PORTB,0
goto DER2
movlw h'01'
movwf PORTB
call retardo
IZQ2:
rlf PORTB,1
call retardo
btfss PORTB,7
goto IZQ2
goto CICLO
retardo
movwf valor1
movwf valor2
goto uno
decfsz valor2
goto dos
decfsz valor1
goto tres
return
end
Programa Contador de 00-99 con pic 16f877
processor 16f877
include<P16f877.inc>
;Variable contador
contador equ h'24'
org 0h
goto INICIO
org 05h
INICIO:
clrf PORTB
bsf STATUS,RP0
movlw h'0'
START:
clrf PORTD
LOOP:
movwf PORTB
call RETARDO
movlw UNO
movwf PORTB
call RETARDO
movlw DOS
movwf PORTB
call RETARDO
movlw TRES
movwf PORTB
call RETARDO
movlw CUATRO
movwf PORTB
call RETARDO
movlw CINCO
movwf PORTB
call RETARDO
movlw SEIS
movwf PORTB
call RETARDO
movlw SIETE
movwf PORTB
call RETARDO
movlw OCHO
movwf PORTB
call RETARDO
movlw NUEVE
movwf PORTB
call RETARDO
;Verifica si contador=10
movlw h'A'
xorwf contador,w
;el conteo
UNIDADES
movlw h'1'
xorwf contador,w
goto PRINT1
movlw h'2'
xorwf contador,w
goto PRINT2
movlw h'3'
xorwf contador,w
goto PRINT3
movlw h'4'
xorwf contador,w
goto PRINT4
movlw h'5'
xorwf contador,w
goto PRINT5
movlw h'6'
xorwf contador,w
movlw h'7'
xorwf contador,w
goto PRINT7
movlw h'8'
xorwf contador,w
goto PRINT8
movlw h'9'
xorwf contador,w
goto PRINT9
PRINT1:
movlw UNO
movwf PORTD
goto LOOP
PRINT2:
movlw DOS
movwf PORTD
goto LOOP
PRINT3:
movlw TRES
movwf PORTD
goto LOOP
PRINT4:
movlw CUATRO
movwf PORTD
goto LOOP
PRINT5:
movlw CINCO
movwf PORTD
goto LOOP
PRINT6:
movlw SEIS
movwf PORTD
goto LOOP
PRINT7:
movlw SIETE
movwf PORTD
goto LOOP
PRINT8:
movlw OCHO
movwf PORTD
goto LOOP
PRINT9:
movlw NUEVE
movwf PORTD
goto LOOP
RETARDO
movwf valor1
movwf valor2
movwf valor3
goto uno
decfsz valor2
goto dos
decfsz valor1
goto tres
return
end
3 Programa para el control de un Teclado matricial 4x4
;---------------------------------------------------------
;Autor: LONELY113
; http://lonely113.blogspot.com
;
;Programa para control de teclado matricial 4x4
;Adicionalmente muestra la tecla pulsada en un display
;Para teclado: Salida: RB0-RB3
; Entradas: RB4-RB7
;Para Display: Salidas: RB1-RB7 (7 segmentos)
; RA0 (Habilitacion catodo comun)
;---------------------------------------------------------
include "p16f84a.inc"
LIST P=16f84a
;Subroutines
CONV: addwf PCL,1 ;Convierte hexadecimal a 7 segmentos
retlw 0x00 ;" "
retlw 0x0C ;1 tecla 1
retlw 0xB6 ;2 tecla 2
retlw 0x9E ;3 tecla 3
retlw 0xE2 ;F tecla 4
retlw 0xCC ;4 tecla 5
retlw 0xDA ;5 tecla 6
retlw 0xFA ;6 tecla 7
retlw 0xF2 ;E tecla 8
retlw 0x0E ;7 tecla 9
retlw 0xFE ;8 tecla 10
retlw 0xDE ;9 tecla 11
retlw 0xBC ;D tecla 12
retlw 0xEE ;A tecla 13
retlw 0x7E ;0 tecla 14
retlw 0xF8 ;B tecla 15
retlw 0x72 ;C tecla 16
;----------------------------------------------------------
;Autor: LONELY113
; http://lonely113.blogspot.com
;
;Programa para control de LCD con controlador Hitachi 44780
;2x16 lineas
;Configuracion de pines:
;RA0: RS (Pin 4)
;RA1: R/W (Pin 5)
;RA2: E (Pin 6)
;RB0-RB7: D0-D7 (Pines 7-14)
;----------------------------------------------------------
include "p16f84a.inc"
LIST P=16f84a
include<P16f877.inc>
;Declaración de VARIABLES
;Contador de caractéres
INICIO:
; polarización en entradas
;Inicio
START:
clrf caracter
INICIA_LCD:
movwf PORTD
movwf PORTD
movwf PORTD
return
ENVIA:
return
COMANDO:
bsf PORTC, 1 ; Pone la señal ENABLE en 1
return
LINEA2:
movwf PORTD
goto NEW_SCAN
; Rutina de retardo
DELAY:
movlw 0xFF
movwf cont2
loop1:
movlw 0xFF
movwf cont1
loop2:
decfsz cont1,1
goto loop2
decfsz cont2,1
goto loop1
return
NEW_SCAN:
movwf PORTB
CHK_COL:
NEXT_COL:
; recorrida
TECLA_ON:
Espera1
Espera3
Espera4
;numTecla en W
CONV_TECLA
addwf PCL,1
end
PROGRAMA PARA CONTROLAR LCD CON PIC PROCESSOR 16F877
include <P16F877.INC>
;Configuración de puertos
INICIO:
START_LCD:
goto START_LCD
;Mensaje a enviar
M1:
movlw 'e'
movwf PORTB
call ENVIA
movlw 'l'
movwf PORTB
call ENVIA
movlw 'l'
movwf PORTB
call ENVIA
movlw 'o'
movwf PORTB
call ENVIA
movwf PORTB
call ENVIA
movlw 'W'
movwf PORTB
call ENVIA
movlw 'o'
movwf PORTB
call ENVIA
movlw 'r'
movwf PORTB
call ENVIA
movlw 'l'
movwf PORTB
call ENVIA
movlw 'd'
movwf PORTB
call ENVIA
movlw '!'
movwf PORTB
call ENVIA
return
M2:
movlw 'm'
movwf PORTB
call ENVIA
movwf PORTB
call ENVIA
movlw 'O'
movwf PORTB
call ENVIA
movlw 'p'
movwf PORTB
call ENVIA
movlw 'e'
movwf PORTB
call ENVIA
movlw 'n'
movwf PORTB
call ENVIA
movlw 'B'
movwf PORTB
call ENVIA
movlw 'o'
movwf PORTB
call ENVIA
movlw 'x'
movwf PORTB
call ENVIA
movlw 'e'
movwf PORTB
call ENVIA
movlw 'r'
movwf PORTB
call ENVIA
return
INICIA_LCD:
movwf PORTB
movwf PORTB
movwf PORTB
return
COMANDO:
call DELAY
call DELAY
return
ENVIA:
return
LINEA2:
bcf PORTD, 0 ; RS=0 MODO INSTRUCCION
movwf PORTB
return
; Subrutina de retardo
DELAY:
movlw 0xFF
movwf val2
ciclo:
movlw 0xFF
movwf val1
ciclo2:
decfsz val1,1
goto ciclo2
decfsz val2,1
goto ciclo
return
END
Programa con sensor de temperatura LM 35 y LCD
include<p16f877.inc>
; en valor BCD
org 0h
goto INICIO
org 05h
INICIO:
bsf STATUS,RP0
movlw 00h
movlw 3fh
movlw h'0'
START
;Inicia LCD
START_LCD:
movwf PORTD
movwf PORTD
movwf PORTD
return
ENVIA:
return
COMANDO:
call DELAY2
call DELAY2
return
ERASE_LCD
movwf PORTD
call COMANDO ; Se da de alta el comando
return
START_ADC
PRINT_TEMP
movlw 'T'
movwf PORTD
call ENVIA
movlw '='
movwf PORTD
call ENVIA
call READ_TEMP ;Llamada a rutina que obtine el
movwf PORTD
call ENVIA
movwf PORTD
call ENVIA
movwf PORTD
call ENVIA
movwf PORTD
call ENVIA
movwf PORTD
call ENVIA
movlw 'C'
movwf PORTD
call ENVIA
READ_TEMP:
clrf Centenas
clrf Decenas
clrf Unidades
movf ADRESH,W
;sucesivas.
CENTENAS1
DECENAS1
UNIDADES1
movwf Unidades
;clrf Resto
OBTEN_ASCII
movlw h'30'
iorwf Unidades,f
iorwf Decenas,f
iorwf Centenas,f
return
DELAY1:
movlw h'30'
movwf val
goto Loop
return
;Subrutina de retardo para ENABLE_LCD
DELAY2:
movlw 0xFF
movwf val1
Loop1:
movlw 0xFF
movwf val2
Loop2:
decfsz val2,1
goto Loop2
decfsz val1,1
goto Loop1
return
end
hola a todos soy nuevo en el foro, pero me parese grandioso todo esto, nota
un nivel alto a nivel de usuario, espero poder aportar algun cosita que sepa y
tengan dudas como tambien poder solisitar su ayuda en mas de una vez.
bueno estoy aqui por que e echo un pequeño codigo en CCS C para el pic
16f877a donde manejo un teclado matrisial 4x4, pero el punto es que me
quedo muy robusto y no se como hacer que quede mas presentable y que no
tenga que consumir tanto tiempo en leer lineas, si me pudieran ayudar a
mejorarlo seria de gran ayuda. por otra parte no puedo ocupar el puerto A por
que lo tengo configurado para otras cosas, el B lo tengo para el manejo de una
LCD 20x4 y parte del puerto C estoy ocupando los 2 CCP por ende me esta
quedando solo el puerto D libre y el C en parte, bueno les dejo el para ver si
me pueden echar una manito. antemano gracias.
#include <16F877a.h>
#device adc=10
#FUSES NOWDT, HS, NOPUT, NOPROTECT, BROWNOUT, NOLVP, NOCPD, NOWRT
#use delay (clock=20000000) //Fosc=20Mhz
#define use_portb_lcd TRUE //definir salida del puerto B para la lcd
#include<lcd.c> //libreria manejo lcd
#use standard_io(D)
int i,j,x;
char Teclas[4][4]={{'1','2','3','A'}
{'4','5','6','B'}
{'7','8','9','C'}
{'D','0','E','F'}};
void main(){
lcd_init(); //inicializa lcd
while(TRUE){
i++;
switch( i )
{
case 1:
output_high(PIN_D4);
output_high(PIN_D5);
output_high(PIN_D6);
output_low(PIN_D7);
break;
case 2:
output_high(PIN_D4);
output_high(PIN_D5);
output_low(PIN_D6);
output_high(PIN_D7);
break;
case 3:
output_high(PIN_D4);
output_low(PIN_D5);
output_high(PIN_D6);
output_high(PIN_D7);
break;
case 4:
output_low(PIN_D4);
output_high(PIN_D5);
output_high(PIN_D6);
output_high(PIN_D7);
break;
case 5:
break;
default:
}
if(i==5){i=0;}
if(!input(PIN_D0)){j=0;x=i;}
if(!input(PIN_D1)){j=1;x=i;}
if(!input(PIN_D2)){j=2;x=i;}
if(!input(PIN_D3)){j=3;x=i;}
printf(lcd_putc,"tecla:%c",Teclas[j][x]); //...presentacion
lcd_gotoxy(1,1);
}}
No creo que sea necesario usar un mismo puerto para los 2. Yo cambiaría el
LCD al puerto D, y aprovecharía la interrupción por cambio de estado en RB4-
RB7 para detectar la pulsación de alguna tecla.
#use fast_io(b)
char Teclas[17]={'1','2','3','A',
'4','5','6','B',
'7','8','9','C',
'D','0','E','F',' '};
char Tecla;
void main(){
set_tris_b(0xF0);
output_b(0x00);
enable_interrupts(INT_RB);
enable_interrupts(GLOBAL);
#int_RB
void RB_isr(void)
{
Tecla=TestTeclado(); //Testea la Tecla Pulsada.-
printf("Tecla=%c",Tecla);
output_b(0x00); // Se puede usar interrupción por RB4-RB7, y con esto
queda
// en espera de una proxima interrupcion.-
}
int TestTeclado(void){
int i,j,Filas;
Filas=0x0E; //xxxx1110.
output_b(Filas);
i=0;
for(j=0;j<4;j++){
if(input(PIN_B4)==0){break;}
i++;
if(input(PIN_B5)==0){break;}
i++;
if(input(PIN_B6)==0){break;}
i++;
if(input(PIN_B7)==0){break;}
i++;
//rotate_left(&Filas,1);
shift_left(&Filas,1,1);
output_b(Filas); //Trasladamos el 0 a siguiente Pin.
}
return(Teclas[i]);