Sei sulla pagina 1di 25

TAREA 3.

5 TECLADO 7-SEG
#include <18f452.h> /* libreria de pic a utilizar */
#fuses HS,NOWDT,NOPROTECT,NOLVP
#use delay(clock=40000000) /* reloj */
void main() /* comienzo */
{

set_tris_b(0xF0);
for(;;)
{

//Fila 1 (7,8,9,A)
output_high(PIN_B0); /* alto */
output_low(PIN_B1); /* bajo */
output_low(PIN_B2); /* bajo */
output_low(PIN_B3); /* bajo */

while(output_high(PIN_B0)&&input(PIN_B4))
{
output_d(0x10); /* salida en el dispaly 1*/

}
while(output_high(PIN_B0)&&input(PIN_B5))
{

output_d(0x20);/* salida en el dispaly 2*/

}
while(output_high(PIN_B0)&&input(PIN_B6))
{
output_d(0x30);/* salida en el dispaly 3*/

}
while(output_high(PIN_B0)&&input(PIN_B7))
{
output_d(0xA0);/* salida en el dispaly A*/

//Fila 2 (4,5,6,B)
output_low(PIN_B0);
output_high(PIN_B1);
output_low(PIN_B2);
output_low(PIN_B3);

while(output_high(PIN_B1)&&input(PIN_B4))
{

output_d(0x40);

}
while(output_high(PIN_B1)&&input(PIN_B5))
{
output_d(0x50);

}
while(output_high(PIN_B1)&&input(PIN_B6))
{
output_d(0x60);

}
while(output_high(PIN_B1)&&input(PIN_B7))
{
output_d(0xB0);

//Fila 3 (1,2,3,C)
output_low(PIN_B0);
output_low(PIN_B1);

output_high(PIN_B2);
output_low(PIN_B3);

while(output_high(PIN_B2)&&input(PIN_B4))
{
output_d(0x70);

}
while(output_high(PIN_B2)&&input(PIN_B5))
{
output_d(0x80);

}
while(output_high(PIN_B2)&&input(PIN_B6))
{
output_d(0x90);

}
while(output_high(PIN_B2)&&input(PIN_B7))
{
output_d(0xC0);

//Fila 3 (E,0,F,D)
output_low(PIN_B0);
output_low(PIN_B1);
output_low(PIN_B2);
output_high(PIN_B3);

while(output_high(PIN_B3)&&input(PIN_B4))
{
output_d(0xE0);

}
while(output_high(PIN_B3)&&input(PIN_B5))
{
output_d(0x00);

}
while(output_high(PIN_B3)&&input(PIN_B6))
{
output_d(0xF0);

}
while(output_high(PIN_B3)&&input(PIN_B7))
{
output_d(0xD0);

TAREA 3.6 DESPLIEGUE-1234


#include <16f887.h> // Cabecera de uso del microcontrolador

#fuses NOWDT,HS,NOMCLR

#use delay(clock=20000000)
#use fast_io(b) // Declaracion rapida de entradas y salidas
#use fast_io(d)

void main(void)
{
while(1)
{
set_tris_b(0); // Se establece el resgistro trisb, 0=salidas, 1=entradas
set_tris_d(0);
output_d(0b00000001); //Habilita el primer digito
output_b(0b11111001);
delay_us(1000);
output_d(0b00000010);
output_b(0b10100100);
delay_us(1000);

output_d(0b00000100);
output_b(0b10110000);
delay_us(1000);
output_d(0b00001000);
output_b(0b10011001);
delay_us(1000);

TAREA 3.8 MOTOR A PASOS


#include <16f887.h>

#fuses NOWDT, NOMCLR


#fuses XT,INTRC_IO

#define numpasos 4 // se define la constante "numpasos"

#use delay (clock = 4000000)


#use fast_io(B)
#use fast_io(D)

char paso[]={3,6,20,17}; // arreglo con 4 elementos


char pospaso=0;
int bandera=0;
int1 go=0;

void avancemotor()
{

pospaso++;
if(pospaso == numpasos)
pospaso = 0;
}

void regreso()
{
if(pospaso == 0)
pospaso=numpasos-1;
else
{
pospaso--;
}
}

#int_ext
cambio()
{
go++;
if(go==1)bandera=1;
else
{
bandera=2;
go=0;
}

clear_interrupt(int_ext);
}

void main (void)


{
set_tris_b(0b00000001);
output_B(0);
set_tris_d(0b00000000);
output_D(0b00001000);

enable_interrupts(int_ext);
ext_int_edge(H_to_L);
enable_interrupts(GLOBAL);

while(1)
{
while(bandera==1)
{
output_d(paso[pospaso]);
delay_ms(100);
avancemotor();
}
while(bandera==2)
{

regreso();
output_d(paso[pospaso]);
delay_ms(100);

TAREA 3.9 PWM


#include <16F887.h>
#device ADC=8

//INCLUIR LIBRERIA DEL (PIC18F2550)

//DEFINIMOS LA CANTIDAD DE BITS UTILIZADOS POR EL ADC

#fuses NOWDT, NOPROTECT,HS,NOMCLR // DECLARACION DE FUSIBLES INTERNOS A UTILIZAR


#use delay(clock=20M)

int8 pot = 0;
int8 x = 0;

void main(void)
{
//*************** CONFIGURACIN DEL PWM **************
//setup_ccp1(CCP_PWM);

// Configure CCP1 as a PWM

//setup_timer_2(T2_DIV_BY_16, 255, 1); // The cycle time will be (1/clock)*4*t2div*(period+1)


period=PR2
setup_ccp2(CCP_PWM);

// Configure CCP2 as a PWM

setup_timer_2(T2_DIV_BY_16, 255, 1); // The cycle time will be (1/clock)*4*t2div*(period+1)


period=PR2

//Los calculos anteriores nos arrojan una frecuencia de 1.22 Khz para el control de motor y el LED
//Como queremos usar todo el rango en un lapso de 10 segundos de aumento y 10 segundos en
decremento.

//Tenemos que el rango maximo ed PWM = 255 = 100% por lo que si queremos usarlo por 10 seg
//debemos dar pasos de = 255/10 = 25.5, y tener delays de 1000ms

while (TRUE)
{

//set_pwm1_duty(100); //Escribimos el valor de "pot" en el registro del PWM1


set_pwm2_duty(70);//Escribimos el valor de "pot" en el registro del PWM2
delay_ms(3000);
set_pwm2_duty(120);//Escribimos el valor de "pot" en el registro del PWM2
delay_ms(3000);
set_pwm2_duty(180);
delay_ms(1000);
set_pwm2_duty(250);//Escribimos el valor de "pot" en el registro del PWM2
delay_ms(5000);
set_pwm2_duty(180);
delay_ms(3000);
set_pwm2_duty(120);
delay_ms(3000);
set_pwm2_duty(70);
delay_ms(1000);

TAREA3.10 TECLADO 7-SEG CON INTERRUPCIONES


#include <18f452.h>
#fuses HS, NOWDT,NOPROTECT,NOLVP
#use delay(clock=10000000)

#byte port_b = 0xF81


#byte port_d = 0xF83
#byte tris_b = 0xF93
#byte tris_d = 0xF95

#int_RB
void RB_isr()
{
switch(port_b)
{
case 0x1F:
port_b = 0x01;
break;

case 0x2F:
port_b = 0x02;
break;

case 0x4F:
port_b = 0x04;
break;

case 0x8F:
port_b = 0x08;
break;

default:
break;

}
}

void main()
{
tris_b = 0xF0;
tris_d = 0x00;

//port_b_pullups(TRUE);

enable_interrupts(int_RB);
enable_interrupts(global);

port_b = 0xFF;

while(True)
{
// Primer fila
if((output_high(PIN_B0))&&(output_low(PIN_B1))&&(output_low(PIN_B2))&&(output_low(PIN_B3)))

{
while(input(PIN_B4))
{
port_d=0x07;
}
//port_b=0xFF;
while(input(PIN_B5))
{
port_d=0x08;
}
//port_b=0xFF;
while(input(PIN_B6))
{
port_d=0x09;
}
//port_b=0xFF;
while(input(PIN_B7))
{
port_d=0x0A;
}
//port_b=0xFF;
}
port_b=0xFF;

//Segunada fila
if((output_low(PIN_B0))&&(output_high(PIN_B1))&&(output_low(PIN_B2))&&(output_low(PIN_B3)))
{
while(input(PIN_B4))
{
port_d=0x04;
}
//port_b=0xFF;
while(input(PIN_B5))
{
port_d=0x05;
}
//port_b=0xFF;
while(input(PIN_B6))
{
port_d=0x06;
}
//port_b=0xFF;

while(input(PIN_B7))
{
port_d=0x0B;
}
//port_b=0xFF;
}

port_b=0xFF;

//Tercer fila
if((output_low(PIN_B0))&&(output_low(PIN_B1))&&(output_high(PIN_B2))&&(output_low(PIN_B3)))
{
while(input(PIN_B4))
{
port_d=0x01;
}
//port_b=0xFF;
while(input(PIN_B5))
{
port_d=0x02;
}
//port_b=0xFF;
while(input(PIN_B6))
{
port_d=0x03;
}
//port_b=0xFF;

while(input(PIN_B7))
{
port_d=0x0C;
}

//port_b=0xFF;
}
port_b=0xFF;

//Cuarta fila
if((output_low(PIN_B0))&&(output_low(PIN_B1))&&(output_low(PIN_B2))&&(output_high(PIN_B3)))
{
while(input(PIN_B4))
{
port_d=0x0E;
}
//port_b=0xFF;
while(input(PIN_B5))
{
port_d=0x00;
}
//port_b=0xFF;
while(input(PIN_B6))
{
port_d=0x0F;
}
//port_b=0xFF;

while(input(PIN_B7))
{

port_d=0x0D;
}
//port_b=0xFF;
}
port_b=0xFF;

TAREA 3.11 ECO DEL TECLADO AL MONITOR


#include <16F887.h>
#fuses HS,NOWDT,PUT,NOPROTECT,PUT,NOBROWNOUT,NOLVP
#use delay(clock=20000000)
#use rs232(baud=115200,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8)

/* LIBRERIAS */

/* MAIN */
void main(void)
{
char a;
while(TRUE)
{
a=getc();
putc(a);
TAREA 3.12 CONVERSION ANALOGICO DIGITAL
#include <18f452.h>
#fuses HS, NOPROTECT, NOWDT, NOLVP

#use delay(clock=1000000)
#use rs232(baud=9600,xmit=PIN_C6,rcv=PIN_C7)
#byte port_b = 0xF81
#byte tris_b = 0xF93

unsigned int16 tension=0;


unsigned int8 valor;

#int_AD
void ADC()
{
valor=tension/31;
switch(valor)
{
case 0:
port_b = 0b00000000;
break;

case 1:
port_b = 0b10000000;
break;

case 2:
port_b = 0b11000000;
break;

case 3:
port_b = 0b11100000;
break;

case 4:
port_b = 0b11110000;
break;

case 5:
port_b = 0b11111000;
break;

case 6:
port_b = 0b11111100;
break;

case 7:
port_b = 0b11111110;
break;

case 8:
port_b = 0b11111111;
break;

default:
break;

void main()
{
setup_adc_ports(AN0);
setup_adc(adc_clock_internal);
tris_b = 0x00;
set_adc_channel(0);

enable_interrupts(int_AD);
enable_interrupts(global);

while(true)
{
tension=read_adc();
delay_ms(1);
//valor=tension/31;
//printf("tension: %Ld \r",tension);

TAREA 3.13 PWM MULTIPLE


#include <18f452.h>

#fuses HS, NOPROTECT, NOLVP, NOWDT


#use delay(clock=20000000)

int i;

void main()
{
i=0;

// for(;;)
// {
for(i=0;i<=60;i++)
{
output_low(PIN_B0);
delay_us(19500);
output_high(PIN_B0);
delay_us(500);
}

for(i=0;i<=60;i++)

{
output_low(PIN_B1);
delay_us(19000);
output_high(PIN_B1);
delay_us(1000);
}

for(i=0;i<=60;i++)
{
output_low(PIN_B2);
delay_us(18500);
output_high(PIN_B2);
delay_us(1500);
}

for(i=0;i<=60;i++)
{
output_low(PIN_B3);
delay_us(18000);
output_high(PIN_B3);
delay_us(2000);
}

for(i=0;i<=60;i++)
{

output_low(PIN_B4);
delay_us(17500);
output_high(PIN_B4);
delay_us(2500);
}

for(i=0;i<=60;i++)
{
output_low(PIN_B5);
delay_us(17000);
output_high(PIN_B5);
delay_us(3000);
}

for(i=0;i<=60;i++)
{
output_low(PIN_B6);
delay_us(16500);
output_high(PIN_B6);
delay_us(3500);
}

for(i=0;i<=60;i++)
{
output_low(PIN_B7);

delay_us(16000);
output_high(PIN_B7);
delay_us(4000);

Potrebbero piacerti anche