Está en la página 1de 52

//GLCD_tactil.

c
//Microcontrolador: PIC16F877A
//Oscilador: Externo 4MHz (Modo HS)
//El archivo T6963C.h contiene la definicin de constantes y macros. Este
//archivo se encuentra en la carpeta del proyecto.

#include "T6963C.h"

//Declaracin de variables de conexin del T6963C
char T6963C_dataPort at PORTD; // Puerto de Datos

sbit T6963C_ctrlwr at RB2_bit; // Seal WR write
sbit T6963C_ctrlrd at RB1_bit; // Seal RD read
sbit T6963C_ctrlcd at RB0_bit; // Seal CD command/data
sbit T6963C_ctrlrst at RB4_bit; // Seal RST reset
sbit T6963C_ctrlwr_Direction at TRISB2_bit; // Seal WR write
sbit T6963C_ctrlrd_Direction at TRISB1_bit; // Seal RD read
sbit T6963C_ctrlcd_Direction at TRISB0_bit; // Seal CD command/data
sbit T6963C_ctrlrst_Direction at TRISB4_bit; // Seal RST reset

//Seales no empleadas por la librera, se configuran en la funcin main
sbit T6963C_ctrlce at RB3_bit; // Seal CE
sbit T6963C_ctrlfs at RB6_bit; // Seal FS
sbit T6963C_ctrlmd at RB5_bit; // Seal MD
sbit T6963C_ctrlce_Direction at TRISB3_bit; // Seal CE
sbit T6963C_ctrlfs_Direction at TRISB6_bit; // Seal FS
sbit T6963C_ctrlmd_Direction at TRISB5_bit; // Seal MD
//Final de declaracin de variables de conexin del T6963C

// Touch Panel (TP) module connections
sbit DriveA at RC0_bit;
sbit DriveB at RC1_bit;
sbit DriveA_Direction at TRISC0_bit;
sbit DriveB_Direction at TRISC1_bit;
// End Touch Panel module connections

char write_erase;
char pen_size;
char write_msg[] = "WRITE"; // GLCD menu
messages
char clear_msg[] = "CLEAR";
char erase_msg[] = "ERASE";
unsigned int x_coord, y_coord;

void Initialize() {
DriveA_Direction = 0; // Set DriveA
pin as output
DriveB_Direction = 0; // Set DriveB
pin as output
TRISA = 3;
ADC_Init(); // Initialize
ADC
TP_Init(128, 64, 0, 1); //Initialize TP. Canal 0(AN0) para la posicin
x, canal 1(AN1)
//para la posicin y.
TP_Set_ADC_Threshold(900); // Set touch panel
(TP) ADC threshold
}

void Calibrate() {
T6963C_Dot(0,63,T6963C_WHITE); // Draw bottom
left dot
T6963C_Write_Text("TOUCH BOTTOM LEFT",0,3,T6963C_ROM_MODE_OR);
TP_Calibrate_Bottom_Left(); // Calibration of
bottom left corner
Delay_ms(1000);

T6963C_Dot(0,63,T6963C_BLACK); // Clear
bottom left dot
T6963C_Dot(127,0,T6963C_WHITE); // Draw upper
right dot
T6963C_Write_Text(" ",0,3,T6963C_ROM_MODE_OR);
T6963C_Write_Text("TOUCH UPPER RIGHT",0,4,T6963C_ROM_MODE_OR);
TP_Calibrate_Upper_Right(); // Calibration of upper
right corner
Delay_ms(1000);
}

void main() {
T6963C_ctrlce_Direction = 0;
T6963C_ctrlce = 0; //Habilitar el T6963C.
T6963C_ctrlfs_Direction = 0;
T6963C_ctrlfs = 0; //Fuente 8x8 (FS<1:0>=00).
T6963C_ctrlmd_Direction = 0;
T6963C_ctrlmd = 1; //32 columnas (MD<3:2>=11) (pantalla
virtual)

T6963C_init(128, 64, 8); //Inicializa el T6963C. Caracteres de 8
bits.
T6963C_graphics(1); //Habilita la presentacin de grficos.
T6963C_text(1); //Habilita la presentacin de texto.

Initialize();

T6963C_Write_Text("CALIBRATION",0,3,T6963C_ROM_MODE_OR);
Delay_ms(1000);
T6963C_txtFill(0); // Clear
GLCD
Calibrate();
T6963C_txtFill(0);
T6963C_Write_Text("WRITE ON SCREEN",0,5,T6963C_ROM_MODE_OR) ;
Delay_ms(1000);
T6963C_txtFill(0); // Clear
GLCD
T6963C_Write_Text(clear_msg,0,0,T6963C_ROM_MODE_OR);
T6963C_Write_Text(erase_msg,11,0,T6963C_ROM_MODE_OR);

// Pen Menu:
T6963C_Rectangle(41,0,52,9,T6963C_WHITE);
T6963C_Box(45,3,48,6,T6963C_WHITE);
T6963C_Rectangle(63,0,70,7,T6963C_WHITE);
T6963C_Box(66,3,67,4,T6963C_WHITE);
T6963C_Rectangle(80,0,86,6,T6963C_WHITE);
T6963C_Dot(83,3,T6963C_WHITE);

write_erase = T6963C_WHITE;
pen_size = 1;
while (1) {
if (TP_Press_Detect()) {
// After a PRESS is detected read X-Y and convert it to 128x64
space
if (TP_Get_Coordinates(&x_coord, &y_coord) == 0) {

if ((x_coord < 31) && (y_coord < 8)) {

T6963C_grFill(0);
T6963C_txtFill(0);

// Pen Menu:
T6963C_Rectangle(41,0,52,9,T6963C_WHITE);
T6963C_Box(45,3,48,6,T6963C_WHITE);
T6963C_Rectangle(63,0,70,7,T6963C_WHITE);
T6963C_Box(66,3,67,4,T6963C_WHITE);
T6963C_Rectangle(80,0,86,6,T6963C_WHITE);
T6963C_Dot(83,3,T6963C_WHITE);

T6963C_Write_Text(clear_msg,0,0,T6963C_ROM_MODE_OR);
if (write_erase)
T6963C_Write_Text(erase_msg,11,0,T6963C_ROM_MODE_OR);
else
T6963C_Write_Text(write_msg,11,0,T6963C_ROM_MODE_OR);
}

// If write/erase is pressed
if ((x_coord > 96) && (y_coord < 8)) {
if (write_erase) {
write_erase = T6963C_BLACK;
T6963C_Write_Text(write_msg,11,0,T6963C_ROM_MODE_OR);
Delay_ms(500);
}
else {
write_erase = T6963C_WHITE;
T6963C_Write_Text(erase_msg,11,0,T6963C_ROM_MODE_OR);
Delay_ms(500);
}
}

// If pen size is selected
if ((x_coord >= 41) && (x_coord <= 52) && (y_coord <= 9))
pen_size = 3;

if ((x_coord >= 63) && (x_coord <= 70) && (y_coord <= 7))
pen_size = 2;

if ((x_coord >= 80) && (x_coord <= 86) && (y_coord <= 6))
pen_size = 1;

if (y_coord < 11)
continue;

switch (pen_size) {
case 1 : {
if ( (x_coord >= 0) && (y_coord >= 0) && (x_coord <= 127) &&
(y_coord <= 63) )
T6963C_Dot(x_coord, y_coord, write_erase);
break;
}
case 2 : {
if ( (x_coord >= 0) && (y_coord >= 0) && (x_coord <= 127-1) &&
(y_coord <= 63-1) )
T6963C_Box(x_coord, y_coord, x_coord + 1, y_coord + 1,
write_erase);
break;
}
case 3 : {
if ( (x_coord >= 1) && (y_coord >= 1) && (x_coord <= 127-2) &&
(y_coord <= 63-2) )
T6963C_Box(x_coord-1, y_coord-1, x_coord + 2, y_coord + 2,
write_erase);
break;
}
}
}
}
}
}




//DiscadorDTMF.c
//Microcontrolador: PIC16F628A
//Oscilador interno: 4MHz (TCI=1us)

#define R4 RB7_bit
#define R3 RB6_bit
#define R2 RB5_bit
#define R1 RB4_bit

#define R4D TRISB7_bit
#define R3D TRISB6_bit
#define R2D TRISB5_bit
#define R1D TRISB4_bit


#define C4 RA3_bit
#define C3 RA2_bit
#define C2 RA1_bit
#define C1 RA0_bit

#define C4D TRISA3_bit
#define C3D TRISA2_bit
#define C2D TRISA1_bit
#define C1D TRISA0_bit


void main(){
CMCON=0x07; //Pines RA<3:0> como E/S digital.
TRISA=0xFF; //Puerto A como entrada.
TRISB=0xFF; //Puerto B como entrada.

Delay_ms (2000); //Espera 2 segundos antes de hacer la llamada.


//0
C2=0; R4=0; //Escribir niveles bajos en los latch de salida.
C2D=0; R4D=0; //Enviar los niveles bajos a los pines de salida.
Delay_ms(80); //Generar los tonos durante 80 ms.
C2D=1; R4D=1; //Restablecer los pines a su estado de alta Z.
Delay_ms(200); //Esperar 200ms antes de enviar el siguiente
//dgito.

//9
C3=0; R3=0;
C3D=0; R3D=0;
Delay_ms(80);
C3D=1; R3D=1;
Delay_ms(200);

//8
C2=0; R3=0;
C2D=0; R3D=0;
Delay_ms(80);
C2D=1; R3D=1;
Delay_ms(200);

//7
C1=0; R3=0;
C1D=0; R3D=0;
Delay_ms(80);
C1D=1; R3D=1;
Delay_ms(200);

//4
C1=0; R2=0;
C1D=0; R2D=0;
Delay_ms(80);
C1D=1; R2D=1;
Delay_ms(200);

//3
C3=0; R1=0;
C3D=0; R1D=0;
Delay_ms(80);
C3D=1; R1D=1;
Delay_ms(200);

//8
C2=0; R3=0;
C2D=0; R3D=0;
Delay_ms(80);
C2D=1; R3D=1;
Delay_ms(200);

//8
C2=0; R3=0;
C2D=0; R3D=0;
Delay_ms(80);
C2D=1; R3D=1;
Delay_ms(200);

//7
C1=0; R3=0;
C1D=0; R3D=0;
Delay_ms(80);
C1D=1; R3D=1;
Delay_ms(200);

//7
C1=0; R3=0;
C1D=0; R3D=0;
Delay_ms(80);
C1D=1; R3D=1;
Delay_ms(200);
}


Termmetro digital

unsigned char ch;
unsigned int adc_rd;
char *text,*text1;
long tlong;
int i,j;
void main() {
INTCON = 0;
Lcd_Config(&PORTB, 4, 5, 6, 3, 2, 1, 0);
LCD_Cmd(LCD_CURSOR_OFF);
LCD_Cmd(LCD_CLEAR);
for(i=0;i<5;i++){
LCD_Cmd(LCD_CLEAR);
text = "INGENIERIA";
LCD_Out(1,i,text);
Delay_ms(100);
}
text1 = "ELECTRONICA";
LCD_Out(2,3,text1);
ADCON1 = 0x82;
TRISA = 0xFF;
Delay_ms(1000);
LCD_Cmd(LCD_CLEAR);

text = "Temperatura:";
for(j=16;j>0;j--){
LCD_Cmd(LCD_CLEAR);
LCD_Out(1,j,text);
Delay_ms(100);
}

while (1) {
adc_rd = ADC_read(2);

tlong = (long)adc_rd * 5000;
tlong = tlong / 1023 - 40;
ch = tlong / 1000;

if(ch==0)
LCD_Chr(2,6,' ');
else
LCD_Chr(2,6,48+ch);

ch = (tlong / 100) % 10;

LCD_Chr_CP(48+ch);
ch = (tlong / 10) % 10;
LCD_Chr_CP(48+ch);
LCD_Chr_CP('.');

ch = tlong % 10;
LCD_Chr_CP(48+ch);
LCD_Chr_CP('C');
Delay_ms(10000);
}
}




Temporizador programable

//*****DECLARACION DE LAS FUNCIONES
void BIN_7SEG(int f_data1bin,int f_data2bin);//Usado en la conversion de datos a
//valor de 7segmentos. Ingresas dos registros por ejemplo el de los segundos y
//minutos y entrega los datos en los registros (displa_1 ... display_4)

int BCD_7SEG(int f_digit);//Usado en la conversion de los datos a 7 segmentos
//Convierte valor BCD a 7 segmentos, cada registro es convertido a BCD y guardado
//en dos registros.

void DISPLAY(int f_data,int f_port);//Usado cuando se hace el barrido en cada
//interrupcion. Permite activar el bit del puerto que habilita el display asi
//mismo saca el dato por el puerto del display de 7segmentos (display_1...display_4)


//*****DECLARACION DE LAS VARIABLES

//*****DECLARACION DE VARIABLES USADAS PARA MOSTRAR VALOR EN DISPLAYS
unsigned count_1 =0; //Contador 1. Usado para mostrar los datos en displays
unsigned display_data=0; //Usado en "DISPLAY". Contiene valor a mostrar
unsigned display_port=0; //Usado en "DISPLAY". Indica que display mostrar

//*****DECLARACION DE VARIABLES USADAS PARA CONTABILIZAR SEGUNDOS Y MINUTOS
unsigned count_1sec=0; //Ayuda a temporizar 250 veces 4ms para obtener 1 segundo
unsigned seconds_bin=0;//Cuenta los segundos en binario, de 0 a 59 segundos
unsigned minutes_bin=0;//Cuenta los minutos en binario, de 0 a 59 minutos


//*****DECLARACION DE VARIABLES USADAS PARA LA CONVERSION DE DATOS A VALORES DE
//7 SEGMENTOS. POR EJEMPLO EL REGISTRO SEGUNDOS ES CONVERTIDO PRIMERO A DOS
//REGISTROS EN BCD Y LUEGO PASADO A DOS REGISTROS CODIFICADO PARA 7 SEGMENTOS.
unsigned valor1_bcd=0;//Contiene el valor en BCD de f_data1bin
unsigned data1_7seg=0;//Contiene el primer digito en 7segmentos de Valor1_bcd
unsigned data2_7seg=0;//Contiene el segundo digito en 7segmentos de Valor2_bcd

unsigned valor2_bcd=0;//Contiene el valor en BCD de f_data2bin
unsigned data3_7seg=0;//Contiene el primer digito en 7segmentos de Valor2_bcd
unsigned data4_7seg=0;//Contiene el segundo digito en 7segmentos de Valor2_bcd

unsigned display_1=0; //Valor a mostrar en primer display (lado derecho)
unsigned display_2=0; //Valor a mostrar en segundo display
unsigned display_3=0; //Valor a mostrar en tercer display
unsigned display_4=0; //Valor a mostrar en cuarto display(lado izquierdo)


//--------------- RUTINA DE ATENCION A INTERRUPCIONES --------------------------

void interrupt() {

//------------- RUTINA DE ATENCION A INTERRUPCIONES POR TMRO -------------------
if (INTCON.TMR0IF==1){//Verificar si la interrupcion es por TMR0

//PRESENTACION DE VALOR EN LOS DISPLAYS EN CADA INTERRUPCION
count_1++; //Contador usado para mostrar los datos en los displays. Cada incre-
//mento se hace en 4ms.
if (count_1==150) count_1=30; //Solo se muestran 4 displays y el punto

switch (count_1){ // Permite seleccionar display que activara y valor que
//mostrara el display seleccionado.

case 30: // Activaremos primer display y mostramos valor de "display_1"

display_port=0b00000001;
display_data=display_1;
DISPLAY(display_data,display_port);//Llamada a funcion
break;

case 60: // Activamos segundo display y mostramos valor de "display_2"
display_port=0b00000010;
display_data=display_2;
DISPLAY(display_data,display_port);//Llamada a funcion
break;

case 90: // Activamos tercer display y mostramos valor de "display_3"
display_port=0b00000100;
display_data=display_3;
DISPLAY(display_data,display_port);//Llamada a funcion
break;

case 120: // Activamos cuarto display y mostramos valor de "display_4"
display_port=0b00001000;
display_data=display_4;//Llamada a funcion
DISPLAY(display_data,display_port);
break;
}


//REINICIO DE INTERRUPCION POR TMRO
TMR0=6; //Cargamos TMRO con el valor inicial
INTCON=0b10100000; // TMROIF=0(Bit_2), Reset Overflow Flag
// TMROIE=1(Bit_5), Enable TMRO interrupt
//GIE=1(Bit_7), Enable all interrupts
}
}

//-------------------------RUTINA PRINCIPAL-------------------------------------

void main(){

OPTION_REG = 0b10000100; //PS=100 (Bit_0,1,2) Prescaler select 1:32
//PSA=0 (Bit_3) Prescaler asigned to TMRO module
//TOCS=0 (Bit_5) Internal Clock (CLKO)
ADCON1=0X06; //Configurar IOs como digitales
TRISA=0X00; //Puerto_C como salida. Habilitacion de los displays
TRISD=0X00;
TRISB=0X00; //Puerto_D como salida. Bus de datos para los displays
PORTA=PORTB=PORTD=0X00; //Inicializar con los puertos apagados

TMR0=6; // Temporizador T0 cuenta de 6 a 255
INTCON=0b10100000; // Habilitar interrupcin por TMR0
// TMROIE=1 (Bit_5), Enable TMRO interrupt
// GIE=1 (Bit_7), Enable Global interrupts

while(1) {
minutes_bin=3;
seconds_bin=5;
BIN_7SEG(minutes_bin,seconds_bin);
}
}






//++++++++++++++++++++DESARROLLO DE LAS
FUNCIONES+++++++++++++++++++++++++++++++


//*****DESARROLLO DE FUNCION PARA CONVERTIR LOS DATOS BINARIOS A 4 VALORES GUAR
//DADOS EN DISPLAY_1 AL 4. F_DATA1BIN CONTIENE EL PRIMER VALOR BINARIO QUE SE
//CONVERTIRA EN BCD Y LUEGO A 7SEGMENTOS. F_DATA2BIN ES EL SEGUNDO VALOR BINARIO
//f_data1bin es convertido y luego guardado en displays 1 y 2
//f_data2bin sobre los displays 3 y 4

void BIN_7SEG(int f_data2bin,int f_data1bin){
valor1_bcd=Dec2Bcd(f_data1bin);//Funcion para convertir binario a BCD
data1_7seg=valor1_bcd & 0b00001111;//Separar el primer digito BCD
data2_7seg=(valor1_bcd & 0b11110000)>>4;//Separar el segundo digito BCD
display_1=BCD_7SEG(data1_7seg);
display_2=BCD_7SEG(data2_7seg);

valor2_bcd=Dec2Bcd(f_data2bin);//Funcion para convertir binario a BCD
data3_7seg=valor2_bcd & 0b00001111;//Separar el primer digito BCD
data4_7seg=(valor2_bcd & 0b11110000)>>4;//Separar el segundo digito BCD
display_3=(BCD_7SEG(data3_7seg)|0b10000000);//Colocamos el punto decimal
display_4=BCD_7SEG(data4_7seg);//Funcion convierte el valor BCD a 7 Seg
}


//*****DESARROLLO DE FUNCION PARA MOSTRAR LOS DATOS EN LOS DISPLAYS
void DISPLAY(int f_data,int f_port){
PORTD=f_data; //Actualiza el valor a mostrar en display
PORTA=f_port; //Activa el display donde mostraremos el dato
return;
}

//*****DESARROLLO DE FUNCION PARA PASAR BCD A 7 SEGMENTOS
int BCD_7SEG(int f_digit){

switch (f_digit){
case 0: return 0x3F; //0x3F es el cdigo 7-segmentos del 0.
case 1: return 0x06; //0x06 es el cdigo 7-segmentos del 1.
case 2: return 0x5B;
case 3: return 0x4F;
case 4: return 0x66;
case 5: return 0x6D;
case 6: return 0x7D;
case 7: return 0x07;
case 8: return 0x7F;
case 9: return 0x6F;
}
}

5-Alarma para conectar al movil
DESCRIPCION
que se acciona al abrir un interruptor magnetico
;por lo tanto se activa cuando la entrada es 1
;esta version solo suena al abrir la puerta.
;tiempo de llamada 1 minuto
;tiempo de reposo 5 minutos,en el caso de que la puerta continue abierta
;
;****************************** ZONA DE DATOS
****************************

__CONFIG _MCLRE_OFF & _CP_ON & _WDT_ON & _INTRC_OSC_NOCLKOUT &
_PWRTE_ON

;MCLRE OFF - configura GP3 como entrada en lugar de como reset
;CP ON - CODIGO DE PROTECCION ACTIVADO
;WDT ON - PERRO GUARDIAN ACTIVADO
;INTRC_OSC_NOCLKOUT - UTILIZACION DE OSCILADOR INTERIOR
;PWRTE_ON - SE ACTIVA EL RESET AL ALIMENTAR AL MICRO
;BODEN_OFF - No actua el reset por bajada de tension


LIST P=16F629 ;Procesador utilizado.
INCLUDE <P12F629.INC>

#define llamar GPIO,5 ;activo optoacoplador de llamar
#define colgar GPIO,4 ;activo optoacoplador de colgar
#define puerta GPIO,2 ;entrada de deteccion de la puerta

#define tres GPIO,3 ;activo optoacoplador de llamar
#define uno GPIO,1 ;activo optoacoplador de colgar
#define cero GPIO,0
;***************************** MAPA DE MEMORIA
****************************

PDel0 equ 0x20 ;utilizado para los retardos
PDel1 equ 0x21 ;utilizado para los retardos
tiempo_ON equ 0x22 ;utilizado para los retardos
tiempo_OFF equ 0x23 ;utilizado para los retardos


;************************************************************************
******
;********************************** INICIO
**********************************
;************************************************************************
******

reset org 0x00 ;El programa comienza en la direccin 0.
goto inicio ;pasa a la posicion de inicio para evitar la
int.
org 0x04 ;aqui se atienden las interupciones

DT " Alarma gsm ver.01 solo apertura
"
DT "llamada 1 min repeticion 5 min "

inicio bsf STATUS,5 ;Banco 1.

call 0x3ff ; CALIBRACION DEL
movwf OSCCAL ; OSCILADOR INTERNO

;movlw b'111110' ;0=salida, 1=entrada
;movwf TRISIO ;lo tranfiere al puerto
bcf colgar ; configuro el pin como salida
bcf llamar ; configuro el pin como salida
bsf puerta ; configuro el pin como entrada

;abilitar resistencias internas
movlw b'00001111'
movwf OPTION_REG
movlw b'00111111' ;selecciono los pines donde quiero las
resistencias
movwf WPU

bcf STATUS,5 ;Banco 0.

;instrucciones para poder utilizar GP0 y GP1 como entradas
movlw b'00000111' ; desactiva el comparador
movwf CMCON ; selecciona GPIO en vez de comparador

clrf GPIO ;todas las salidas puestas a 0


;************************************************************************
******
;******************************* PRINCIPAL
***********************************
;************************************************************************
******
principal clrwdt

btfss puerta ;si es 1 se salta la instruccion, puerta
abierta
goto principal

goto retardo_puerta ;verifica si es una interferencia

sigue call LLAMAR

call Retardo_1m ;tiempo que dura la llamada

call COLGAR

call Retardo_5m ;tiempo que tarda en realizar otra
llamada

goto principal


;************************************************************************
******
;******************************* LLAMAR
***********************************
;************************************************************************
******

LLAMAR clrwdt

bsf colgar ;actuo sobre el pulsador de colgar
call demora_250ms
bcf colgar ;suelto el pulsador de colgar
call demora_250ms

bsf llamar ;actuo sobre el pulsador de llamar
call demora_250ms
bcf llamar ;suelto el pulsador de llamar
call demora_250ms

bsf llamar ;actuo sobre el pulsador de llamar
call demora_250ms
bcf llamar ;suelto el pulsador de llamar
call demora_250ms

return

;************************************************************************
******
;******************************* COLGAR
***********************************
;************************************************************************
******

COLGAR clrwdt

bsf colgar ;actuo sobre el pulsador de colgar
call demora_250ms
bcf colgar ;suelto el pulsador de colgar
call demora_250ms

return

;************************************************************************
******
;**** RETARDOS hasta 24 Horas - cuidado no sobrepasar la PILA
*******
;************************************************************************
******
Retardo_24h call Retardo_1h
Retardo_23h call Retardo_1h
Retardo_22h call Retardo_1h
Retardo_21h call Retardo_1h
Retardo_20h call Retardo_1h
Retardo_19h call Retardo_1h
Retardo_18h call Retardo_1h
Retardo_17h call Retardo_1h
Retardo_16h call Retardo_1h
Retardo_15h call Retardo_1h
Retardo_14h call Retardo_1h
Retardo_13h call Retardo_1h
Retardo_12h call Retardo_1h
Retardo_11h call Retardo_1h
Retardo_10h call Retardo_1h
Retardo_9h call Retardo_1h
Retardo_8h call Retardo_1h
Retardo_7h call Retardo_1h
Retardo_6h call Retardo_1h
Retardo_5h call Retardo_1h
Retardo_4h call Retardo_1h
Retardo_3h call Retardo_1h
Retardo_2h call Retardo_1h

;************************************************************************
******
;**** RETARDOS hasta 1 Hora - cuidado no sobrepasar la PILA
*******
;************************************************************************
******

Retardo_1h call Retardo_1m
call Retardo_1m
call Retardo_1m
call Retardo_1m
call Retardo_1m
Retardo_55m call Retardo_1m
call Retardo_1m
call Retardo_1m
call Retardo_1m
call Retardo_1m
Retardo_50m call Retardo_1m
call Retardo_1m
call Retardo_1m
call Retardo_1m
call Retardo_1m
Retardo_45m call Retardo_1m
call Retardo_1m
call Retardo_1m
call Retardo_1m
call Retardo_1m
Retardo_40m call Retardo_1m
call Retardo_1m
call Retardo_1m
call Retardo_1m
call Retardo_1m
Retardo_35m call Retardo_1m
call Retardo_1m
call Retardo_1m
call Retardo_1m
call Retardo_1m
Retardo_30m call Retardo_1m
call Retardo_1m
call Retardo_1m
call Retardo_1m
call Retardo_1m
Retardo_25m call Retardo_1m
call Retardo_1m
call Retardo_1m
call Retardo_1m
call Retardo_1m
Retardo_20m call Retardo_1m
call Retardo_1m
call Retardo_1m
call Retardo_1m
call Retardo_1m
Retardo_15m call Retardo_1m
call Retardo_1m
call Retardo_1m
call Retardo_1m
call Retardo_1m
Retardo_10m call Retardo_1m
call Retardo_1m
call Retardo_1m
call Retardo_1m
call Retardo_1m
Retardo_5m call Retardo_1m
call Retardo_1m
call Retardo_1m
Retardo_2m call Retardo_1m

;************************************************************************
******
;*************************** RETARDO hasta 10seg
*******************
;************************************************************************
******

Retardo_1m call Retardo_1s
call Retardo_1s
call Retardo_1s
call Retardo_1s
call Retardo_1s
Retardo_55s call Retardo_1s
call Retardo_1s
call Retardo_1s
call Retardo_1s
call Retardo_1s
Retardo_50s call Retardo_1s
call Retardo_1s
call Retardo_1s
call Retardo_1s
call Retardo_1s
Retardo_45s call Retardo_1s
call Retardo_1s
call Retardo_1s
call Retardo_1s
call Retardo_1s
Retardo_40s call Retardo_1s
call Retardo_1s
call Retardo_1s
call Retardo_1s
call Retardo_1s
Retardo_35s call Retardo_1s
call Retardo_1s
call Retardo_1s
call Retardo_1s
call Retardo_1s
Retardo_30s call Retardo_1s
call Retardo_1s
call Retardo_1s
call Retardo_1s
call Retardo_1s
Retardo_25s call Retardo_1s
call Retardo_1s
call Retardo_1s
call Retardo_1s
call Retardo_1s
Retardo_20s call Retardo_1s
call Retardo_1s
call Retardo_1s
call Retardo_1s
call Retardo_1s
Retardo_15s call Retardo_1s
call Retardo_1s
call Retardo_1s
call Retardo_1s
call Retardo_1s
Retardo_10s call Retardo_1s
call Retardo_1s
call Retardo_1s
call Retardo_1s
call Retardo_1s
Retardo_5s call Retardo_1s
call Retardo_1s
call Retardo_1s
call Retardo_1s

;************************************************************************
******
;*************************** RETARDO 1seg
***************************
;************************************************************************
******
Retardo_1s call demora_250ms
call demora_250ms
call demora_250ms


;************************************************************************
******
;***************** demora 250ms
********************
;************************************************************************
******

demora_250ms
DEMORA movlw .195 ; 1 set numero de repeticion (B)
movwf PDel0 ; 1 |
PLoop1 movlw .213 ; 1 set numero de repeticion (A)
movwf PDel1 ; 1 |
PLoop2 clrwdt ; 1 clear watchdog
PDelL1 goto PDelL2 ; 2 ciclos delay
PDelL2
decfsz PDel1, 1 ; 1 + (1) es el tiempo 0 ? (A)
goto PLoop2 ; 2 no, loop
decfsz PDel0, 1 ; 1 + (1) es el tiempo 0 ? (B)
goto PLoop1 ; 2 no, loop
clrwdt ; 1 ciclo delay
return ; 2+2 Fin.

;************************************************************************
******
;******************* RETARDO comprobando la puerta
*******************
;************************************************************************
******


retardo_puerta nop ;verificando continuamente la puerta

DEMORA1 movlw .20 ;
movwf PDel0 ;
PLoop11 movlw .207 ;
movwf PDel1 ;
PLoop21 clrwdt ;

btfss puerta ;si es 1 se salta la
instruccion
goto principal ;vuelve si es una
interferencia

decfsz PDel1,1 ;
goto PLoop21 ;
decfsz PDel0,1 ;
goto PLoop11 ;
PDelL11 goto PDelL21 ;
PDelL21 clrwdt ;

goto sigue

;------------------------------------------------------------------------
----
org 0x3FF ; OSSCAL ----------------
----
retlw 0x20 ; VALOR DE CALIBRACION ----------------
----
;------------------------------------------------------------------------
----
END

6-Control de un servo motor y ver su posicion
DESCRIPCION
;Generamos una seal comprendida entre un tiempo de .55ms y 2,34mseg,
pudiendo
;regular este tiempo en 256 intervalos de 7useg.
;con los 7us consegimos un tiempo maximo de 1792usg para alcanzar los
2,34ms
;El programa arranca con el servo en la posicion central

;************************ BITS DE CONFIGURACION
*************************
;CP_OFF - Codigo de proteccion programa desactivado
;CPD_OFF - Codigo de proteccion eeprom desactivado
;WDT_OFF - Perro guardian desconectado
;BODEN_OFF - No actua el reset por bajada de tension
;PWRTE_OFF - Reset de inicio desconectado
;MCLRE_OFF - Reset externo desconectado, sino pierdo una
entrada A5
;XT_OSC - oscilador exterior
;INTOSC_OSC_NOCLKOUT - funcionamiento con reloj interno
;LVP_OFF - programacion de bajo voltage desconectado,
; para activar el pin 4 de RB

__CONFIG _LVP_OFF & _MCLRE_OFF & _BODEN_OFF & _CP_OFF & _PWRTE_ON &
_WDT_OFF & _INTOSC_OSC_NOCLKOUT

LIST P=16F628A ;Procesador utilizado.
INCLUDE <P16F628A.INC>
ERRORLEVEL 0, -302 ;suppress bank selection messages

;****************************** ZONA DE DATOS
****************************
#define Banco0 bcf STATUS,RP0
#define Banco1 bsf STATUS,RP0

#define Salida PORTA,0

#define Pulsador_IZQ PORTA,3
#define Pulsador_DER PORTA,4
#define Selec PORTA,5
#define Pulsador_Vel PORTA,2

#define Led_0 PORTB,0
#define Led_1 PORTB,1
#define Led_2 PORTB,2
#define Led_3 PORTB,3
#define Led_4 PORTB,4
#define Led_5 PORTB,5
#define Led_6 PORTB,6
#define Led_7 PORTB,7

#define Pulsador_0 PORTB,0 ;ojo repito el puerto
#define Pulsador_1 PORTB,1
#define Pulsador_2 PORTB,2
#define Pulsador_3 PORTB,3
#define Pulsador_4 PORTB,4
#define Pulsador_5 PORTB,5
#define Pulsador_6 PORTB,6
#define Pulsador_7 PORTB,7

;****************************** MAPA DE MEMORIA
****************************
CBLOCK 0x20 ;Inicio de 16f628, pero 0C para el 16f84
contador
contador_
velocidad
PDel0
PDel1
PDel2

ENDC

;************************************************************************
******
;************************* INICIO
****************************
;************************************************************************
******
Inicio org 0
goto Configuracion

;Datos que se veran al cargar el HEX en el micro, pero no afectan al
programa
DT " control de un servomotor"
DT " 16f628A"
Configuracion

Banco1 ;Acceso al Banco 1.
bsf Pulsador_DER ;entradas
bsf Pulsador_IZQ
bsf Selec
bsf Pulsador_Vel

bcf Salida
bcf Led_0 ;salidas
bcf Led_1
bcf Led_2
bcf Led_3
bcf Led_4
bcf Led_5
bcf Led_6
bcf Led_7

bcf OPTION_REG,NOT_RBPU ;Activa las resistencias Pull-Up del
Puerto B
Banco0 ;Acceso al Banco 0.

movlw 0x07 ;desconecta los comparadores analogicos
del
movwf CMCON ;pic 16f628

clrf contador
clrf contador_
clrf velocidad
movlw .128 ;valor para la posicion neutra
movwf contador

goto principal


Entradas
Banco1 ;Acceso al Banco 1.
bsf Pulsador_0 ;entradas
bsf Pulsador_1
bsf Pulsador_2
bsf Pulsador_3
bsf Pulsador_4
bsf Pulsador_5
bsf Pulsador_6
bsf Pulsador_7
Banco0 ;Acceso al Banco 0.
return

Salidas
Banco1 ;Acceso al Banco 1.
bcf Led_0 ;salidas
bcf Led_1
bcf Led_2
bcf Led_3
bcf Led_4
bcf Led_5
bcf Led_6
bcf Led_7
Banco0 ;Acceso al Banco 0.
return

Led_OFF
bsf Led_0 ;led apagados
bsf Led_1
bsf Led_2
bsf Led_3
bsf Led_4
bsf Led_5
bsf Led_6
bsf Led_7
return

Led_ON
bcf Led_0 ;led encendidos
bcf Led_1
bcf Led_2
bcf Led_3
bcf Led_4
bcf Led_5
bcf Led_6
bcf Led_7
return

;************************************************************************
******
;************************* PRINCIPAL
****************************
;************************************************************************
******
principal
bcf Salida ;a nivel bajo

goto bucle_1

call Led_ON ;efectos luminosos NO UTILIZADOS (goto
detante)
call Retardo_500ms
call Led_OFF
call Retardo_500ms
call Led_ON
call Retardo_500ms
call Led_OFF
call Retardo_500ms
call Led_ON
call Retardo_500ms
call Led_OFF
call Retardo_500ms

bucle_1
btfss Selec
call microswitch
btfsc Selec
call pulsadores

movlw 0x0A ;10 veces x 20ms =200ms
movwf velocidad ;veces que manda la seal antes de actualizarla

;************************* SEAL DE SALIDA
bucle_2
bsf Salida ;pongo en alto la salida
call Retardo_300micros ;tiempo minimo de 550 us
call Retardo_200micros
call Retardo_50micros

call TEMPO ;incremento el tiempo seleccionado
bcf Salida ;pongo la salida en bajo
call Retardo_10ms ;tiempo para completar un ciclo conpleto
call Retardo_5ms ;tiempo para completar un ciclo conpleto

btfss Pulsador_Vel ;si esta pulsado contara mas rapido
goto bucle_1

decfsz velocidad,F ;decrementa el contador
goto bucle_2 ;vuelve a mandar el mismo pulso
goto bucle_1 ;vuelvo a repetir esta secuencia



;************************************************************************
******
;************************* PULSADORES
****************************
;************************************************************************
******
pulsadores
call Salidas ;configuro el puerto para encender los led
call Led_OFF ;apago todos los led

movf contador,W ;el valor del contador lo paso a los led
xorlw 0xFF ;invierto todos los bit
movwf PORTB



btfss Pulsador_DER ;salta si vale 1
goto Sumar
btfss Pulsador_IZQ
goto Restar
RETURN

Sumar
incf contador,F ; rutina de incremento
movf contador,W ; incremento las unidades
btfss STATUS,Z ;Mira si vale cero
RETURN
movlw 0xFF
movwf contador ;vuelvo a dejarlo en 256
RETURN
Restar
movf contador,F ;se carga sobre si mismo
btfsc STATUS,Z ;Mira si vale cero
return ;regresa si vale cero
decfsz contador,F ;decrementa el contador
nop ;importante, para que no me salte el
return.
RETURN

;************************************************************************
******
;************************* MICROSWITCH
****************************
;************************************************************************
******
microswitch
call Entradas ;configuro el puerto para leer los microswitch
movf PORTB,W
xorlw 0xFF
movwf contador

return

;************************************************************************
******
;************************* MEDIR TIEMPO
****************************
;************************************************************************
******
;cada unidad del contador_ equivale a un tiempo de 4us
TEMPO
movf contador,W
movwf contador_

movf contador_,F ;se carga sobre si mismo
btfsc STATUS,Z ;Mira si vale cero
return ;regresa si vale cero

Tiempo
nop ; 4us
nop ; 5us
nop ; 6us
nop ; 7us
; nop ; 8us no utilizado


decfsz contador_,F ;decrementa el contador 1us
goto Tiempo ;regresa si llego a cero 3us

return


;************************************************************************
******
;************************* RETARDOS
****************************
;************************************************************************
******

; ZONA DE DATOS
***************************************************************
CBLOCK
R_ContA ;Contadores para los retardos.
R_ContB
R_ContC
ENDC
;************************************************************************
******
; RETARDOS de 0.5 hasta 60 segundos
;************************************************************************
******
Retardo_1minuto
Retardo_60s
call Retardo_10s
Retardo_50s
call Retardo_25s
Retardo_25s
movlw d'250'
goto Retardo_1Decima
Retardo_20s
movlw d'200'
goto Retardo_1Decima
Retardo_10s
movlw d'100'
goto Retardo_1Decima
Retardo_5s
movlw d'50'
goto Retardo_1Decima
Retardo_2s
movlw d'20'
goto Retardo_1Decima
Retardo_1s
movlw d'10'
goto Retardo_1Decima
Retardo_500ms
movlw d'5'

Retardo_1Decima
movwf R_ContC
R1Decima_BucleExterno2
movlw d'100'
movwf R_ContB
R1Decima_BucleExterno
movlw d'249'
movwf R_ContA
R1Decima_BucleInterno
clrwdt
decfsz R_ContA,F
goto R1Decima_BucleInterno
decfsz R_ContB,F
goto R1Decima_BucleExterno
decfsz R_ContC,F
goto R1Decima_BucleExterno2
return

;************************************************************************
******
; RETARDOS de 1 ms hasta 200 ms.
;************************************************************************
******
Retardo_200ms
movlw d'200'
goto Retardos_ms
Retardo_100ms
movlw d'100'
goto Retardos_ms
Retardo_50ms
movlw d'50'
goto Retardos_ms
Retardo_20ms
movlw d'20'
goto Retardos_ms
Retardo_10ms
movlw d'10'
goto Retardos_ms
Retardo_5ms
movlw d'5'
goto Retardos_ms
Retardo_3ms
movlw d'2'
goto Retardos_ms
Retardo_2ms
movlw d'2'
goto Retardos_ms
Retardo_1ms
movlw d'1'

Retardos_ms
movwf R_ContB
R1ms_BucleExterno
movlw d'249'
movwf R_ContA
R1ms_BucleInterno
clrwdt
decfsz R_ContA,F
goto R1ms_BucleInterno
decfsz R_ContB,F
goto R1ms_BucleExterno
return

;************************************************************************
******
; RETARDOS de 20 hasta 500 microsegundos
;************************************************************************
******
Retardo_500micros
clrwdt
movlw d'164'
goto RetardoMicros
Retardo_300micros
clrwdt
movlw d'95'
goto RetardoMicros
Retardo_200micros
clrwdt
movlw d'64'
goto RetardoMicros
Retardo_100micros
movlw d'31'
goto RetardoMicros
Retardo_50micros
clrwdt
movlw d'14'
goto RetardoMicros
Retardo_20micros
movlw d'5'

RetardoMicros
movwf R_ContA
Rmicros_Bucle
decfsz R_ContA,F
goto Rmicros_Bucle
return

;************************************************************************
******
; RETARDOS de 4 hasta 10 microsegundos
;************************************************************************
******
Retardo_10micros
nop
nop
nop
nop
nop
Retardo_5micros
clrwdt
Retardo_4micros
return


end

7- pulsadores para concursos de TV
16f628A

; DESCRIPCION
;Dispone de 8 pulsadores con 8 salidas, de modo que solo el pulsador que
;primero se actue conseguira actuar su salida correspondiente.
;Los pulsadores que se actuen a continuacion no actuaran de ninguna forma
;************************ BITS DE CONFIGURACION
*************************
;CP_OFF - Codigo de proteccion programa desactivado
;CPD_OFF - Codigo de proteccion eeprom desactivado
;WDT_OFF - Perro guardian desconectado
;BODEN_OFF - No actua el reset por bajada de tension
;PWRTE_OFF - Reset de inicio desconectado
;MCLRE_OFF - Reset externo desconectado, sino pierdo una
entrada A5
;XT_OSC - oscilador exterior
;INTOSC_OSC_NOCLKOUT - funcionamiento con reloj interno
;LVP_OFF - programacion de bajo voltage desconectado,
; para activar el pin 4 de RB

__CONFIG _LVP_OFF & _MCLRE_OFF & _BODEN_OFF & _CP_OFF & _PWRTE_ON &
_WDT_ON & _INTOSC_OSC_NOCLKOUT


LIST P=16F628A ;Procesador utilizado.
INCLUDE <P16F628A.INC>
ERRORLEVEL 0, -302 ;suppress bank selection messages

;****************************** ZONA DE DATOS
****************************
#define Banco0 bcf STATUS,RP0
#define Banco1 bsf STATUS,RP0

#define Led_1 PORTA,6
#define Led_2 PORTA,7
#define Led_3 PORTA,0
#define Led_4 PORTA,1
#define Led_5 PORTA,2
#define Led_6 PORTA,3
#define Led_7 PORTB,0
#define Led_8 PORTB,1

#define Pulsador_1 PORTA,5
#define Pulsador_2 PORTB,7
#define Pulsador_3 PORTB,6
#define Pulsador_4 PORTB,5
#define Pulsador_5 PORTB,4
#define Pulsador_6 PORTB,3
#define Pulsador_7 PORTB,2
#define Pulsador_8 PORTA,4
;****************************** MAPA DE MEMORIA
****************************
CBLOCK 0x20 ;Inicio de 16f628, pero 0C para el 16f84
PDel0
PDel1
PDel2
ENDC

;************************************************************************
******
;************************* INICIO
****************************
;************************************************************************
******
Inicio org 0
goto Configuracion

;Datos que se veran al cargar el HEX en el micro, pero no afectan al
programa
DT " Pulsadores para concursos televisivos"
DT " 16f628A"
Configuracion
Banco1 ;Acceso al Banco 1.
bsf Pulsador_1 ;entradas
bsf Pulsador_2
bsf Pulsador_3
bsf Pulsador_4
bsf Pulsador_5
bsf Pulsador_6
bsf Pulsador_7
bsf Pulsador_8

bcf Led_1 ;salidas
bcf Led_2
bcf Led_3
bcf Led_4
bcf Led_5
bcf Led_6
bcf Led_7
bcf Led_8

bcf OPTION_REG,NOT_RBPU ;Activa las resistencias Pull-Up del
Puerto B
Banco0 ;Acceso al Banco 0.

movlw 0x07 ;desconecta los comparadores analogicos
del
movwf CMCON ;pic 16f628

call Apago ;apaga todos los led

;************************************************************************
******
;********************* PULSADORES
******************
;************************************************************************
******
Ver_Pulsadores clrwdt
btfss Pulsador_1 ;salta si no esta presionado
goto Prende_1 ;actua sobre el led

btfss Pulsador_2 ;salta si no esta presionado
goto Prende_2 ;actua sobre el led

btfss Pulsador_3 ;salta si no esta presionado
goto Prende_3 ;actua sobre el led

btfss Pulsador_4 ;salta si no esta presionado
goto Prende_4 ;actua sobre el led

btfss Pulsador_5 ;salta si no esta presionado
goto Prende_5 ;actua sobre el led

btfss Pulsador_6 ;salta si no esta presionado
goto Prende_6 ;actua sobre el led

btfss Pulsador_7 ;salta si no esta presionado
goto Prende_7 ;actua sobre el led

btfss Pulsador_8 ;salta si no esta presionado
goto Prende_8 ;actua sobre el led

goto Ver_Pulsadores

;************************************************************************
******
;********************* ENCENDER y APAGAR LED
*********************
;************************************************************************
******

Prende_1
bsf Led_1
goto Final
Prende_2
bsf Led_2
goto Final
Prende_3
bsf Led_3
goto Final
Prende_4
bsf Led_4
goto Final
Prende_5
bsf Led_5
goto Final
Prende_6
bsf Led_6
goto Final
Prende_7
bsf Led_7
goto Final
Prende_8
bsf Led_8
goto Final

Final
call DEMORA_10seg
call Apago
goto Ver_Pulsadores

Apago ;todas las salidas desconectadas
bcf Led_1
bcf Led_2
bcf Led_3
bcf Led_4
bcf Led_5
bcf Led_6
bcf Led_7
bcf Led_8
RETURN

;************************************************************************
******
;************************* RETARDOS
****************************
;************************************************************************
******
; Descripcion: Delay 10000000 ciclos

DEMORA_10seg
movlw .43 ; 1 set numero de repeticion (C)
movwf PDel0 ; 1 |
PLoop0 movlw .226 ; 1 set numero de repeticion (B)
movwf PDel1 ; 1 |
PLoop1 movlw .205 ; 1 set numero de repeticion (A)
movwf PDel2 ; 1 |
PLoop2 clrwdt ; 1 clear watchdog
clrwdt ; 1 ciclo delay
decfsz PDel2, 1 ; 1 + (1) es el tiempo 0 ? (A)
goto PLoop2 ; 2 no, loop
decfsz PDel1, 1 ; 1 + (1) es el tiempo 0 ? (B)
goto PLoop1 ; 2 no, loop
decfsz PDel0, 1 ; 1 + (1) es el tiempo 0 ? (C)
goto PLoop0 ; 2 no, loop
clrwdt ; 1 ciclo delay
return ; 2+2 Fin.

end

8-Proteccion para cerradura electrica
DESCRIPCION
;A los 5 segundos de tener alimentacion activare el rele y pondre el led
en
;modo intermitente
;****************************** CONFIGURACION
****************************
;CP_OFF - Codigo de proteccion programa desactivado
;CPD_OFF - Codigo de proteccion eeprom desactivado
;WDT_OFF - Perro guardian desconectado
;BODEN_OFF - No actua el reset por bajada de tension
;PWRTE_OFF - Reset de inicio desconectado
;MCLRE_OFF - Reset externo desconectado, sino pierdo una
entrada A5
;XT_OSC - oscilador exterior
;INTOSC_OSC_NOCLKOUT - funcionamiento con reloj interno
;LVP_OFF - programacion de bajo voltage desconectado,
; para activar el pin 4 de RB

__CONFIG _MCLRE_OFF & _CP_OFF & _WDT_ON & _INTRC_OSC_NOCLKOUT &
_PWRTE_ON

LIST P=16F629 ;Procesador utilizado.
INCLUDE <P12F629.INC>

;***************************** MAPA DE MEMORIA
****************************

CBLOCK 0x20 ;Inicio de la memoria de datos
PDel0 ;utilizado para los retardos
PDel1 ;utilizado para los retardos
tiempo_ON ;utilizado para los retardos
tiempo_OFF ;utilizado para los retardos
ENDC

;****************************** ZONA DE DATOS
****************************

#define Led GPIO,5 ;puerto utilizado pala la conexion del led
#define Rele GPIO,4 ;puerto utilizado pala la conexion del Rele


#define Banco0 bcf STATUS,RP0
#define Banco1 bsf STATUS,RP0

;************************************************************************
******
;********************************** INICIO
**********************************
;************************************************************************
******

reset org 0x00 ;El programa comienza en la direccin 0.
goto inicio ;pasa a la posicion de inicio para evitar la
int.
org 0x04 ;aqui se atienden las interupciones

inicio Banco1
call 0x3ff ; CALIBRACION DEL
movwf OSCCAL ; OSCILADOR INTERNO
bcf Led
bcf Rele
Banco0

;instrucciones para poder utilizar GP0 y GP1 como entradas
movlw b'00000111' ; desactiva el comparador
movwf CMCON ; selecciona GPIO en vez de comparador

bcf Rele
bcf Led


;************************************************************************
******
;******************************* PRINCIPAL
***********************************
;************************************************************************
******
call retardo_5seg
bsf Rele ;activa el rele que desconecta la cerradura
bucle bsf Led ;enciende el led que indica que se activo la
proteccion
call DEMORA ;250ms
bcf Led ;apaga el led
call DEMORA ;250ms
goto bucle


;************************************************************************
******
;***************** RETARDOS
********************
;************************************************************************
******
retardo_5seg
call DEMORA ;5seg
call DEMORA ;4,75seg
call DEMORA ;4,5seg
call DEMORA ;4,25seg
call DEMORA ;4seg
call DEMORA ;3,75seg
call DEMORA ;3,5seg
call DEMORA ;3,25seg
call DEMORA ;3seg
call DEMORA ;2,75seg
call DEMORA ;2,5seg
call DEMORA ;2,25seg
call DEMORA ;2seg
call DEMORA ;1,75seg
call DEMORA ;1,5seg
call DEMORA ;1,25seg
call DEMORA ;1seg
call DEMORA ;0,75seg
call DEMORA ;0,5seg

;-------------------------------------------------------------
; Generado con PDEL ver SP
; Descripcion: Delay 249996 ciclos 250ms
;-------------------------------------------------------------
DEMORA movlw .195 ; 1 set numero de repeticion (B)
movwf PDel0 ; 1 |
PLoop1 movlw .213 ; 1 set numero de repeticion (A)
movwf PDel1 ; 1 |
PLoop2 clrwdt ; 1 clear watchdog
PDelL1 goto PDelL2 ; 2 ciclos delay
PDelL2
decfsz PDel1, 1 ; 1 + (1) es el tiempo 0 ? (A)
goto PLoop2 ; 2 no, loop
decfsz PDel0, 1 ; 1 + (1) es el tiempo 0 ? (B)
goto PLoop1 ; 2 no, loop
clrwdt ; 1 ciclo delay
return ; 2+2 Fin.

;------------------------------------------------------------------------
----
org 0x3FF ; OSSCAL ----------------
----
retlw 0x20 ; VALOR DE CALIBRACION ----------------
----
;------------------------------------------------------------------------
----
END

9-Control de motor PWM con 1 display y eeprom

DESCRIPCION
;ERROR,ERROR,ERROR,ERROR no me graba la eeprom el valor 0 ni el 10,
devido a
;que el motor (PORTA,3) no cambia de estado)
;no deveria de influir PORTA3, ya que esta desconectado ese comparador

;************************ BITS DE CONFIGURACION
*************************
;CP_OFF - Codigo de proteccion programa desactivado
;CPD_OFF - Codigo de proteccion eeprom desactivado
;WDT_OFF - Perro guardian desconectado
;BODEN_OFF - No actua el reset por bajada de tension
;PWRTE_OFF - Reset de inicio desconectado
;MCLRE_OFF - Reset externo desconectado, sino pierdo una
entrada A5
;XT_OSC - oscilador exterior
;INTOSC_OSC_NOCLKOUT - funcionamiento con reloj interno
;LVP_OFF - programacion de bajo voltage desconectado,
; para activar el pin 4 de RB

__CONFIG _LVP_OFF & _MCLRE_OFF & _BODEN_ON & _CP_OFF & _PWRTE_ON &
_WDT_ON & _INTOSC_OSC_NOCLKOUT

LIST P=16F628A ;Procesador utilizado.
INCLUDE <P16F628A.INC>
ERRORLEVEL 0, -302 ;suppress bank selection messages


;****************************** MAPA DE MEMORIA
****************************
CBLOCK 0x20
Digito
Contador
PDel0
PDel1
PDel2
R_ContA ; Contadores para los retardos.
R_ContB
R_ContC

Data_EE
Addr_EE
ENDC


;****************************** ZONA DE DATOS
****************************
#define Banco0 bcf STATUS,RP0
#define Banco1 bsf STATUS,RP0

#define MOTOR PORTA,3 ; Rele

#define PulsadorSube PORTB,2
#define PulsadorBaja PORTB,3

#define DigitoA PORTA,0
#define DigitoB PORTA,7
#define DigitoC PORTA,6
#define DigitoD PORTB,7
#define DigitoE PORTB,6
#define DigitoF PORTB,5
#define DigitoG PORTB,4


ORG 0x2100 ; Corresponde a la direccin 0 de la zona
EEPROM
DT .5




;************************************************************************
******
;************************* INICIO
****************************
;************************************************************************
******
Inicio org .0
goto CONFIGURACION
org .4
goto INTERRUPCION
;Datos que se veran al cargar el HEX en el micro, pero no afectan al
programa
DT " control PWM"
DT " con un display de 7 segmentos"
DT " y grabacion en eeprom al desaparecer la tension"

INTERRUPCION ; AQUI PROCEDERE A GRABAR LOS DATOS EN LA EPROM,

call apagar ;desconecto todas las salidas para aumentar el
tiempo
;de descarga de los condensadores

; bsf DigitoG ;esta rutina me muestra si graba bien
; nop ;espero a que se termine de ir la energia o en
todo caso
; goto $-1 ;provocare un reset por no refrescar al perro
guardian



MOVFW Data_EE ;valor leido en la eeprom
SUBWF Digito, W ; Compara con el actual
BTFSC STATUS,Z ; Mira si son iguales
goto reset_ ; Y no necesita grabar la eprom
call GrabaEprom

reset_ bsf DigitoA ;activo todos los displays para que termine de
bsf DigitoB ;descargarse los condensadores
bsf DigitoC
bsf DigitoD
bsf DigitoE
bsf DigitoF
bsf DigitoG

nop ;espero a que se termine de ir la energia o en
todo caso
goto $-1 ;provocare un reset por no refrescar al perro
guardian



CONFIGURACION
call DEMORA ;1 seg para que se carguen los condensadores

Banco1 ;Acceso al Banco 1.
bsf PulsadorSube ;Lo configura como entrada
bsf PulsadorBaja ;Lo configura como entrada
bcf DigitoA ;salida
bcf DigitoB ;salida
bcf DigitoC ;salida
bcf DigitoD ;salida
bcf DigitoE ;salida
bcf DigitoF ;salida
bcf DigitoG ;salida
bcf MOTOR ;salida

bsf TRISA,1 ;entrada RA1 del comparador
bsf TRISA,2 ;entrada RA2 del comparador

bcf OPTION_REG,NOT_RBPU ;Activa las resistencias Pull-Up del
Puerto B
Banco0 ;Acceso al Banco 0.

clrf PORTA
clrf PORTB


movlw 0x05 ;solo funciona un comparador
movwf CMCON ;-RA1 , +RA2 , salida C2

movf CMCON,F ;carga sobre si mismo para saber que valor
tiene

goto $+1
nop
goto $+1
nop
goto $+1
nop

bcf PIR1,CMIF ;limpiar bandera para las interrupciones

Banco1 ;banco 1
bsf PIE1,CMIE ;activa las interrupciones con el
comparador
Banco0 ;banco 0
bsf INTCON,PEIE ;activa las interrupciones del comparador
bsf INTCON,GIE ;activa interrupciones globales
call LeeEprom

;TENGO QUE VERIFICAR QUE LOS DATOS ESTAN CPMPRWENDIDOS ENTRE 0 y 10
movf Digito,W ;
sublw .10 ; realizo la resta 10-Digito
btfsc STATUS,C ;si Digito es mayor que 10, entonces
C=0

goto Cambiar

valor movlw 0x05 ;como estaba fiera de los parametros
le
movwf Digito ;pongo de valor 5
goto Cambiar

;************************************************************************
******
;************************* PULSADORES
****************************
;************************************************************************
******
Pulsadores

decfsz Contador ;con un valor de 30 tardara 300ms en
comprobar
return ;los pulsadores

btfss PulsadorSube
goto sumar

btfss PulsadorBaja
goto restar

movlw .1 ;le pongo 1 para que no espere
movwf Contador ;1 para que los pulsadores los lea cada
10ms

return

;************************************************************************
******
;************************* MOTOR
****************************
;************************************************************************
******
;voy a utilizar una frecuencia de 100 Hz la cual tiene una duracion de
10ms
VEL_100 ;10 ms en ON y 0 ms en OFF
bsf MOTOR
call Retardo_10ms
call Pulsadores
goto VEL_100

VEL_90 ;9 ms en ON y 1 ms en OFF
bsf MOTOR
call Retardo_9ms
bcf MOTOR
call Retardo_1ms
call Pulsadores
goto VEL_90

VEL_80 ;8 ms en ON y 2 ms en OFF
bsf MOTOR
call Retardo_8ms
bcf MOTOR
call Retardo_2ms
call Pulsadores
goto VEL_80

VEL_70 ;7 ms en ON y 3 ms en OFF
bsf MOTOR
call Retardo_7ms
bcf MOTOR
call Retardo_3ms
call Pulsadores
goto VEL_70

VEL_60 ;6 ms en ON y 4 ms en OFF
bsf MOTOR
call Retardo_6ms
bcf MOTOR
call Retardo_4ms
call Pulsadores
goto VEL_60

VEL_50 ;5 ms en ON y 5 ms en OFF
bsf MOTOR
call Retardo_5ms
bcf MOTOR
call Retardo_5ms
call Pulsadores
goto VEL_50

VEL_40 ;4 ms en ON y 6 ms en OFF
bsf MOTOR
call Retardo_4ms
bcf MOTOR
call Retardo_6ms
call Pulsadores
goto VEL_40

VEL_30 ;3 ms en ON y 7 ms en OFF
bsf MOTOR
call Retardo_3ms
bcf MOTOR
call Retardo_7ms
call Pulsadores
goto VEL_30

VEL_20 ;2 ms en ON y 8 ms en OFF
bsf MOTOR
call Retardo_2ms
bcf MOTOR
call Retardo_8ms
call Pulsadores
goto VEL_20

VEL_10 ;1 ms en ON y 9 ms en OFF
bsf MOTOR
call Retardo_1ms
bcf MOTOR
call Retardo_9ms
call Pulsadores
goto VEL_10

VEL_0 ;10 ms en OFF
bcf MOTOR
call Retardo_10ms
call Pulsadores
goto VEL_0


;************************************************************************
******
;******************************** SUMAR
*************************************
;************************************************************************
******

sumar
incf Digito,F ; rutina de incremento
movf Digito,W ;

sublw 0x0B ; realizo la resta 11-Digito
btfss STATUS,Z ; si W=11, entonces Z=1

goto Cambiar ; Cambio el numero mostrado

movlw 0x0A ; cargo W con 10, para transferirlo
movwf Digito ;

goto Cambiar ; Cambio el numero mostrado

;************************************************************************
******
;********************************** RESTAR
**********************************
;************************************************************************
******
restar
decf Digito,F ; rutina de decremento
movf Digito,W ; decremento las unidades

sublw 0xff
btfss STATUS,Z ; si W es negativo entonces Z=1

goto Cambiar ; Cambio el numero mostrado

clrf Digito ; Impido que sea inferior a 0

goto Cambiar ; Cambio el numero mostrado

;************************************************************************
******
;********************************** CAMBIAR
*********************************
;************************************************************************
******
Cambiar
movlw .30 ;como cada 10ms decremento el contador, le
pongo
movwf Contador ;30 para que los pulsadores los lea cada
300ms

call apagar

VerTabla movf Digito,W ;lee el valor del Digito
addwf PCL,F

tabla goto cero
goto uno
goto dos
goto tres
goto cuatro
goto cinco
goto seis
goto siete
goto ocho
goto nueve
goto diez

apagar bcf DigitoA
bcf DigitoB
bcf DigitoC
bcf DigitoD
bcf DigitoE
bcf DigitoF
bcf DigitoG
bcf MOTOR
RETURN

cero bsf DigitoA
bsf DigitoB
bsf DigitoC
bsf DigitoD
bsf DigitoE
bsf DigitoF
goto VEL_0

uno bsf DigitoB
bsf DigitoC

goto VEL_10

dos bsf DigitoA
bsf DigitoB
bsf DigitoD
bsf DigitoE
bsf DigitoG
goto VEL_20

tres bsf DigitoA
bsf DigitoB
bsf DigitoC
bsf DigitoD
bsf DigitoG
goto VEL_30

cuatro bsf DigitoB
bsf DigitoC
bsf DigitoF
bsf DigitoG
goto VEL_40

cinco bsf DigitoA
bsf DigitoC
bsf DigitoD
bsf DigitoF
bsf DigitoG
goto VEL_50

seis bsf DigitoA
bsf DigitoC
bsf DigitoD
bsf DigitoE
bsf DigitoF
bsf DigitoG
goto VEL_60

siete bsf DigitoA
bsf DigitoB
bsf DigitoC
goto VEL_70

ocho bsf DigitoA
bsf DigitoB
bsf DigitoC
bsf DigitoD
bsf DigitoE
bsf DigitoF
bsf DigitoG
goto VEL_80

nueve bsf DigitoA
bsf DigitoB
bsf DigitoC
bsf DigitoF
bsf DigitoG
goto VEL_90

diez bsf DigitoE
bsf DigitoF
bsf DigitoB
bsf DigitoC
goto VEL_100


;************************************************************************
******
;********************************** EPROM
**********************************
;************************************************************************
******
GrabaEprom
MOVLW 0x00 ; Direccion de la eprom a grabar
MOVWF Addr_EE
MOVFW Digito ; dato a enviar
MOVWF Data_EE
CALL GRABAR_EEPROM

return

LeeEprom
MOVLW 0x00 ; Direccion que deseo leer
MOVWF Addr_EE
CALL LEER_EEPROM
MOVFW Data_EE ;el dato obtenido de la
eeprom
MOVWF Digito ;lo pasa a este registro
return

;------------------------------------------------------------------------
-------------------
; Graba en la memoria EEPROM, verificando la grabacin exitosa. En caso
de error en la
; grabacin, vuelve a intentarlo.
;
; In: Addr_EE (Reg) -> Direccin de la EEPROM donde grabar
; In: Data_EE (Reg) -> Dato a grabar
;
; Nota: - El banco de salida es el 0.
; - Modificar segn se utilicen Interrupciones o no.
;
GRABAR_EEPROM
BANKSEL Addr_EE
MOVF Addr_EE,W ; Mueve el valor del
"Addr_EE" a "W"
Banco1
MOVWF EEADR ; Mueve el valor de "W" al
registro "EEADR"
BANKSEL Data_EE
MOVF Data_EE,W ; Mueve el valor del
"Data_EE" a "W"
Banco1
MOVWF EEDATA ; Mueve el valor de "W" al
registro "EEDATA"
BSF EECON1,WREN ; Habilita el BIT de
escritura en la EEPROM (WREN)
;------------------------------------------------------------------------
-------------------;
BCF INTCON, GIE ; Desabilita las
interrupciones
MOVLW 0x55 ; Secuencia obligatoria
MOVWF EECON2 ; para activar la grabacin
MOVLW 0xAA ; de la memoria
MOVWF EECON2 ; EEPROM
BSF EECON1,WR ; Inicia el ciclo de
escritura Bit WR
;------------------------------------------------------------------------
-------------------;
; BSF INTCON, GIE ; Habilita las
interrupciones
Banco0
GRABAR_EEPROM_ESPERAR clrwdt
BTFSS PIR1,EEIF ; Lee ek EEIF y salta una
instruccin si el valor es 1
GOTO GRABAR_EEPROM_ESPERAR ; Espera de
grabacin de la EEPROM
BCF PIR1,EEIF ; Limpia el flag
EEIF
Banco1
BCF EECON1,WREN ; Deshabilita el Bit
de escritura de la EEPROM (WREN)
BANKSEL Data_EE
GRABAR_EEPROM_VERIFICACION
MOVFW Data_EE ; Coloca el valor
leido en W
Banco1
BSF EECON1, RD ; Leer la EEPROM
SUBWF EEDATA, W ; Compara el valor
leido con el grabado
BTFSS STATUS,Z ; Si son iguales,
salta una instruccin
GOTO GRABAR_EEPROM ; Si no son iguales,
comienza de nuevo la rutina
Banco0
RETURN
; Fin Rutina: GRABAR_EEPROM ---------------------------------------------
-------------------


;------------------------------------------------------------------------
-------------------
; Lee la memoria EEPROM
; In: Addr_EE (Reg) -> Direccin de la EEPROM donde leer
; Out: Data_EE (Reg) -> Dato leido
;
LEER_EEPROM
BANKSEL Addr_EE ;lo situa automaticamente en el
banco correspondiente
MOVFW Addr_EE ; Carga la direccin en W
Banco1
MOVWF EEADR ; Coloca la direccin en
EEADR
BSF EECON1, RD ; Leer la EEPROM
MOVF EEDATA, W ; Coloca en W el contenido
de la EEPROM
BANKSEL Data_EE
MOVWF Data_EE ; Coloca en Data_EE el
contenido de W
Banco0
RETURN

;************************************************************************
******
;************************* RETARDOS
****************************
;************************************************************************
******
; RETARDOS de 1 ms hasta 10 ms.

Retardo_10ms
movlw d'10'
goto Retardos_ms
Retardo_9ms
movlw d'9'
goto Retardos_ms
Retardo_8ms
movlw d'8'
goto Retardos_ms
Retardo_7ms
movlw d'7'
goto Retardos_ms
Retardo_6ms
movlw d'6'
goto Retardos_ms
Retardo_5ms
movlw d'5'
goto Retardos_ms
Retardo_4ms
movlw d'4'
goto Retardos_ms
Retardo_3ms
movlw d'3'
goto Retardos_ms
Retardo_2ms
movlw d'2'
goto Retardos_ms
Retardo_1ms
movlw d'1'

Retardos_ms
movwf R_ContB
R1ms_BucleExterno
movlw d'249'
movwf R_ContA
R1ms_BucleInterno
clrwdt
decfsz R_ContA,F
goto R1ms_BucleInterno
decfsz R_ContB,F
goto R1ms_BucleExterno
return


; Descripcion: Delay 200000 ciclos
;-------------------------------------------------------------
DEMORA movlw .156 ; 1 set numero de repeticion (B)
movwf PDel0 ; 1 |
PLoop1 movlw .213 ; 1 set numero de repeticion (A)
movwf PDel1 ; 1 |
PLoop2 clrwdt ; 1 clear watchdog
PDelL1 goto PDelL2 ; 2 ciclos delay
PDelL2
decfsz PDel1, 1 ; 1 + (1) es el tiempo 0 ? (A)
goto PLoop2 ; 2 no, loop
decfsz PDel0, 1 ; 1 + (1) es el tiempo 0 ? (B)
goto PLoop1 ; 2 no, loop
PDelL3 goto PDelL4 ; 2 ciclos delay
PDelL4 clrwdt ; 1 ciclo delay
return ; 2+2 Fin.

end

10-DETECTOR DE INTERFERENCIAS

BITS DE CONFIGURACION *************************
;CP_OFF - Codigo de proteccion programa desactivado
;CPD_OFF - Codigo de proteccion eeprom desactivado
;WDT_OFF - Perro guardian desconectado
;BODEN_OFF - No actua el reset por bajada de tension
;PWRTE_OFF - Reset de inicio desconectado
;MCLRE_OFF - Reset externo desconectado, sino pierdo una
entrada A5
;XT_OSC - oscilador exterior
;INTOSC_OSC_NOCLKOUT - funcionamiento con reloj interno
;LVP_OFF - programacion de bajo voltage desconectado,
; para activar el pin 4 de RB

__CONFIG _LVP_OFF & _MCLRE_OFF & _BODEN_OFF & _CP_OFF & _PWRTE_ON &
_WDT_ON & _INTRC_OSC_NOCLKOUT


LIST P=16F628A ;Procesador utilizado.
INCLUDE <P16F628A.INC>
ERRORLEVEL 0, -302 ;suppress bank selection messages

;****************************** ZONA DE DATOS
****************************
#define Banco0 bcf STATUS,RP0
#define Banco1 bsf STATUS,RP0

#define Led_1 PORTB,0
#define Led_2 PORTB,1
#define Led_3 PORTB,2
#define Led_4 PORTB,3
#define Led_5 PORTB,4
#define Led_6 PORTB,5
#define Led_7 PORTB,6
#define Led_8 PORTB,7 ;tambien incorpora buzer

#define Pulsador_1 PORTA,2
#define Pulsador_2 PORTA,3
#define Pulsador_3 PORTA,4
#define Pulsador_4 PORTA,5
#define Pulsador_5 PORTA,6
#define Pulsador_6 PORTA,7
#define Pulsador_7 PORTA,0
#define Pulsador_8 PORTA,1
;****************************** MAPA DE MEMORIA
****************************
CBLOCK 0x20 ;Inicio de 16f628, pero 0C para el 16f84
PDel0
PDel1
PDel2
ENDC

;************************************************************************
******
;************************* INICIO
****************************
;************************************************************************
******
Inicio org 0
goto Configuracion

;Datos que se veran al cargar el HEX en el micro, pero no afectan al
programa
DT " Detector de interferencias "
DT " 16f628A "
DT " 16f628 "
clrf PORTB
Configuracion
Banco1 ;Acceso al Banco 1.
movlw 0xFF
movf PORTA ;entradas

clrf PORTB ;salidas

Banco0 ;Acceso al Banco 0.

movlw 0x07 ;desconecta los comparadores analogicos
del
movwf CMCON ;pic 16f628

clrf PORTB

;************************************************************************
******
;********************* PRESENTACION
******************
;************************************************************************
******
bsf Led_8
call DEMORA_1s

bsf Led_7
call DEMORA_1s
bcf Led_7

bsf Led_6
call DEMORA_1s
bcf Led_6

bsf Led_5
call DEMORA_1s
bcf Led_5

bsf Led_4
call DEMORA_1s
bcf Led_4

bsf Led_3
call DEMORA_1s
bcf Led_3

bsf Led_2
call DEMORA_1s
bcf Led_2

bsf Led_1
call DEMORA_1s
bcf Led_1

bcf Led_8 ;termina apagando el zumbador


;************************************************************************
******
;********************* PULSADORES
******************
;************************************************************************
******
;los 4 primeros actuaran por "0", mientras que los 4 ultimos actuan por
"1"
Pulsadores clrwdt
btfss Pulsador_1 ;salta si no esta presionado
call Prende_1 ;actua sobre el led

btfss Pulsador_2 ;salta si no esta presionado
call Prende_2 ;actua sobre el led

btfss Pulsador_3 ;salta si no esta presionado
call Prende_3 ;actua sobre el led

btfss Pulsador_4 ;salta si no esta presionado
call Prende_4 ;actua sobre el led

btfsc Pulsador_5 ;salta si no esta presionado
call Prende_5 ;actua sobre el led

btfsc Pulsador_6 ;salta si no esta presionado
call Prende_6 ;actua sobre el led

btfsc Pulsador_7 ;salta si no esta presionado
call Prende_7 ;actua sobre el led

btfsc Pulsador_8 ;salta si no esta presionado
call Prende_8 ;actua sobre el led

goto Pulsadores

;************************************************************************
******
;********************* ENCENDER y APAGAR LED
*********************
;************************************************************************
******

Prende_1
bsf Led_1
goto Final
Prende_2
bsf Led_2
goto Final
Prende_3
bsf Led_3
goto Final
Prende_4
bsf Led_4
goto Final
Prende_5
bsf Led_5
goto Final
Prende_6
bsf Led_6
goto Final
Prende_7
bsf Led_7
goto Final
Prende_8
Final
bsf Led_8 ;tambien lo enciende para activar el zumbador
call DEMORA_4s
clrf PORTB ;apaga todos los led
return ;sigue esplorando los pulsadores


;************************************************************************
******
;************************* RETARDOS
****************************
;************************************************************************
******

DEMORA_4s call DEMORA_1s
DEMORA_3s call DEMORA_1s
DEMORA_2s call DEMORA_1s
DEMORA_1s
movlw .14 ; 1 set numero de repeticion (C)
movwf PDel0 ; 1 |
PLoop0 movlw .72 ; 1 set numero de repeticion (B)
movwf PDel1 ; 1 |
PLoop1 movlw .247 ; 1 set numero de repeticion (A)
movwf PDel2 ; 1 |
PLoop2 clrwdt ; 1 clear watchdog
decfsz PDel2, 1 ; 1 + (1) es el tiempo 0 ? (A)
goto PLoop2 ; 2 no, loop
decfsz PDel1, 1 ; 1 + (1) es el tiempo 0 ? (B)
goto PLoop1 ; 2 no, loop
decfsz PDel0, 1 ; 1 + (1) es el tiempo 0 ? (C)
goto PLoop0 ; 2 no, loop
PDelL1 goto PDelL2 ; 2 ciclos delay
PDelL2 clrwdt ; 1 ciclo delay
return ; 2+2 Fin.


end
11-Decodificador universal

BITS DE CONFIGURACION *************************

;CP_OFF - Codigo de proteccion programa desactivado
;CPD_OFF - Codigo de proteccion eeprom desactivado
;WDT_OFF - Perro guardian desconectado
;BODEN_OFF - No actua el reset por bajada de tension
;PWRTE_OFF - Reset de inicio desconectado
;MCLRE_OFF - Reset externo desconectado, sino pierdo una
entrada A5
;XT_OSC - oscilador exterior
;INTOSC_OSC_NOCLKOUT - funcionamiento con reloj interno
;LVP_OFF - programacion de bajo voltage desconectado,
; para activar el pin 4 de RB




;****************************** ZONA DE DATOS
****************************

__CONFIG _LVP_OFF & _MCLRE_OFF & _BODEN_OFF & _DATA_CP_OFF & _CP_OFF &
_PWRTE_ON & _WDT_ON & _INTRC_OSC_NOCLKOUT

LIST P=PIC16F628A ;Procesador utilizado.
INCLUDE <P16F628A.INC>

;***************************** MAPA DE MEMORIA
****************************

;****************************** ZONA DE DATOS
****************************
org 2100 ;aqui empieza la eeprom

;DECIMAL SALIDAS:'76543210' ENTRADAS: '76543210' HEXADECIMAL:
N0 RETLW b'00000000' ;'00000000' 00
N1 RETLW b'00000001' ;'00000001' 01
N2 RETLW b'00000010' ;'00000010' 02
N3 RETLW b'00000011' ;'00000011' 03
N4 RETLW b'00000100' ;'00000100' 04
N5 RETLW b'00000101' ;'00000101' 05
N6 RETLW b'00000110' ;'00000110' 06
N7 RETLW b'00000111' ;'00000111' 07
N8 RETLW b'00001000' ;'00001000' 08
N9 RETLW b'00001001' ;'00001001' 09
N10 RETLW b'00001010' ;'00001010' 0A
N11 RETLW b'00001011' ;'00001011' 0B
N12 RETLW b'00001100' ;'00001100' 0C
N13 RETLW b'00001101' ;'00001101' 0D
N14 RETLW b'00001101' ;'00001101' 0E
N15 RETLW b'00001111' ;'00001111' 0F
N16 RETLW b'11111111' ;'00010000' 10
N17 RETLW b'11111111' ;'00010001' 11
N18 RETLW b'11111111' ;'00010010' 12
N19 RETLW b'11111111' ;'00010011' 13
N20 RETLW b'11111111' ;'00010100' 14
N21 RETLW b'11111111' ;'00010101' 15
N22 RETLW b'11111111' ;'00010110'
N23 RETLW b'11111111' ;'00010111'
N24 RETLW b'11111111' ;'00011000'
N25 RETLW b'11111111' ;'00011001'
N26 RETLW b'11111111' ;'00011010'
N27 RETLW b'11111111' ;'00011011'
N28 RETLW b'11111111' ;'00011100'
N29 RETLW b'11111111' ;'00011101'
N30 RETLW b'11111111' ;'00011110'
N31 RETLW b'11111111' ;'00011111'
N32 RETLW b'11111111' ;'00100000'
N33 RETLW b'11111111' ;'00100001'
N34 RETLW b'11111111' ;'00100010'
N35 RETLW b'11111111' ;'00100011'
N36 RETLW b'11111111' ;'00100100'
N37 RETLW b'11111111' ;'00100101'
N38 RETLW b'11111111' ;'00100110'
N39 RETLW b'11111111' ;'00100111'
N40 RETLW b'11111111' ;'00101000'
N41 RETLW b'11111111' ;'00101001'
N42 RETLW b'11111111' ;'00101010'
N43 RETLW b'11111111' ;'00101011'
N44 RETLW b'11111111' ;'00101100'
N45 RETLW b'11111111' ;'00101101'
N46 RETLW b'11111111' ;'00101110'
N47 RETLW b'11111111' ;'00101111'
N48 RETLW b'11111111' ;'00110000'
N49 RETLW b'11111111' ;'00110001'
N50 RETLW b'11111111' ;'00110010'
N51 RETLW b'11111111' ;'00110011'
N52 RETLW b'11111111' ;'00110100'
N53 RETLW b'11111111' ;'00110101'
N54 RETLW b'11111111' ;'00110110'
N55 RETLW b'11111111' ;'00110111'
N56 RETLW b'11111111' ;'00111000'
N57 RETLW b'11111111' ;'00111001'
N58 RETLW b'11111111' ;'00111010'
N59 RETLW b'11111111' ;'00111011'
N60 RETLW b'11111111' ;'00111100'
N61 RETLW b'11111111' ;'00111101'
N62 RETLW b'11111111' ;'00111110'
N63 RETLW b'11111111' ;'00111111'
N64 RETLW b'11111111' ;'01000000'
N65 RETLW b'11111111' ;'01000001'
N66 RETLW b'11111111' ;'01000010'
N67 RETLW b'11111111' ;'00000011'
N68 RETLW b'11111111' ;'01000100'
N69 RETLW b'11111111' ;'01000101'
N70 RETLW b'11111111' ;'01000110'
N71 RETLW b'11111111' ;'01000111'
N72 RETLW b'11111111' ;'01001000'
N73 RETLW b'11111111' ;'01001001'
N74 RETLW b'11111111' ;'01001010'
N75 RETLW b'11111111' ;'01001011'
N76 RETLW b'11111111' ;'01001100'
N77 RETLW b'11111111' ;'01001101'
N78 RETLW b'11111111' ;'01001110'
N79 RETLW b'11111111' ;'01001111'
N80 RETLW b'11111111' ;'01010000'
N81 RETLW b'11111111' ;'01010001'
N82 RETLW b'11111111' ;'01010010'
N83 RETLW b'11111111' ;'01010011'
N84 RETLW b'11111111' ;'01010100'
N85 RETLW b'11111111' ;'01010101'
N86 RETLW b'11111111' ;'01010110'
N87 RETLW b'11111111' ;'01010111'
N88 RETLW b'11111111' ;'01011000'
N89 RETLW b'11111111' ;'01011001'
N90 RETLW b'11111111' ;'01011010'
N91 RETLW b'11111111' ;'01011011'
N92 RETLW b'11111111' ;'01011100'
N93 RETLW b'11111111' ;'01011101'
N94 RETLW b'11111111' ;'01011110'
N95 RETLW b'11111111' ;'01011111'
N96 RETLW b'11111111' ;'01100000'
N97 RETLW b'11111111' ;'01100001'
N98 RETLW b'11111111' ;'01100010'
N99 RETLW b'11111111' ;'01100011'
N100 RETLW b'11111111' ;'01100100'
N101 RETLW b'11111111' ;'01100101'
N102 RETLW b'11111111' ;'01100110'
N103 RETLW b'11111111' ;'01100111'
N104 RETLW b'11111111' ;'01101000'
N105 RETLW b'11111111' ;'01101001'
N106 RETLW b'11111111' ;'01101010'
N107 RETLW b'11111111' ;'01101011'
N108 RETLW b'11111111' ;'01101100'
N109 RETLW b'11111111' ;'01101101'
N110 RETLW b'11111111' ;'01101110'
N111 RETLW b'11111111' ;'01101111'
N112 RETLW b'11111111' ;'01110000'
N113 RETLW b'11111111' ;'01110001'
N114 RETLW b'11111111' ;'01110010'
N115 RETLW b'11111111' ;'01110011'
N116 RETLW b'11111111' ;'01110100'
N117 RETLW b'11111111' ;'01110101'
N118 RETLW b'11111111' ;'01110110'
N119 RETLW b'11111111' ;'01110111'
N120 RETLW b'11111111' ;'01111000'
N121 RETLW b'11111111' ;'01111001'
N122 RETLW b'11111111' ;'01111010'
N123 RETLW b'11111111' ;'01111011'
N124 RETLW b'11111111' ;'01111100'
N125 RETLW b'11111111' ;'01111101'
N126 RETLW b'11111111' ;'01111110'
N127 RETLW b'11111111' ;'01111111'

;------------------------------------------------------------------------
-----
; Macros
Banco0 MACRO ;Selecciona el data RAM bank 0
BCF STATUS,RP0
BCF STATUS,RP1
ENDM

Banco1 MACRO ;Selecciona el data RAM bank 1
BSF STATUS,RP0
BCF STATUS,RP1
ENDM
;...................................................................

Reset_ org 0x00 ;El programa comienza en la direccin 0.
goto CONFIGURACION ;pasa a la posicion de inicio para evitar la
int.


DT "Decodificador " ;Datos que se veran al cargar el HEX

;************************************************************************
******
;************************* CONFIGURACION
****************************
;************************************************************************
******
CONFIGURACION

clrf PORTB
Banco1
movlw b'11111111'
movwf PORTA ;entradas
clrf PORTB ;salidas
Banco0

clrf PORTB

movlw 0x07 ;deshabilita comparadores analogicos
movwf CMCON



;************************************************************************
******
;************************* INICIO
****************************
;************************************************************************
******

INICIO

btfsc PORTA,7 ;si es "0" lee el dato de la entrada
goto INICIO ;sino espera

movf PORTA,W ; Lee la entrada
andlw b'01111111' ; coge solo 7 Bits

LEER_EEPROM
Banco1
MOVWF EEADR ; Coloca la direccin en
EEADR
BSF EECON1, RD ; Leer la EEPROM
MOVF EEDATA, W ; Coloca en W el contenido de la
EEPROM
Banco0

movwf PORTB ;el dato de la eeprom lo pasa al puerto B

goto INICIO



END

12-Mando de juego

También podría gustarte