Lab 1

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 1

Inicio

// LCD module connections


sbit LCD_RS at RD5_bit;
sbit LCD_EN at RD4_bit;
sbit LCD_D4 at RD3_bit;
sbit LCD_D5 at RD2_bit;
sbit LCD_D6 at RD1_bit;
sbit LCD_D7 at RD0_bit;

sbit LCD_RS_Direction at TRISD5_bit;


sbit LCD_EN_Direction at TRISD4_bit;
sbit LCD_D4_Direction at TRISD3_bit;
sbit LCD_D5_Direction at TRISD2_bit;
sbit LCD_D6_Direction at TRISD1_bit;
sbit LCD_D7_Direction at TRISD0_bit;
// End LCD module connections

Variables
globales
int adc=0;
float adc1=0;
char txt1;
char txt[15];
char tecla;
int aux=0;

Inicio del Programa


Principal
void main()
Declaracion
Entradas y Salidas
de Puertos
ADCON1=13;
TRISB=0b00001111;
PORTB=0b11110000;
TRISC.F0=0;
TRISC.F1=0;

Lcd_Cmd(_LCD_CLEAR);
Lcd_Cmd(_LCD_CURSOR_OFF);

Inicilalizacion
del PWMy LCD
ADC_Init();
PWM1_Init(5000);
PWM1_Start();
Lcd_Init();

adc = ADC_Read(0);
delay_ms(50);
adc=adc*0.0977517106;
inttostr(adc,txt);
lcd_out(1,8,txt);
lcd_out(1,14,"[%]");

adc = ADC_Read(0);
delay_ms(50);
adc=adc*0.0977517106;
inttostr(adc,txt);
lcd_out(1,8,txt);
lcd_out(1,14,"[%]");

Creacion del
teclado
Matricial Filas-
Columnas
PORTB.f4=0;

if(PORTB.F0==0) tecla='1';
if(PORTB.F1==0) tecla='2';
if(PORTB.F2==0) tecla='3';
if(PORTB.F3==0) tecla='A';

PORTB.f4=1;
PORTB.f5=0;
Text
if(PORTB.F0==0) tecla='4';
if(PORTB.F1==0) tecla='5';
if(PORTB.F2==0) tecla='6';
if(PORTB.F3==0) tecla='B';

PORTB.f5=1;
PORTB.f6=0;

if(PORTB.F0==0) tecla='7';
if(PORTB.F1==0) tecla='8';
if(PORTB.F2==0) tecla='9';
if(PORTB.F3==0) tecla='C';

PORTB.f6=1;
PORTB.f7=0;

if(PORTB.F0==0) tecla='*';
if(PORTB.F1==0) tecla='0';
if(PORTB.F2==0) tecla='#';
if(PORTB.F3==0) tecla='D';

PORTB.f7=1;
Lcd_Chr(2, 16, tecla);

No
tecla=='A'

Si

lcd_out(2,1,"Start");
aux=1;

PWM1_Set_Duty(adc*2.55);

No
tecla=='B'

Si

lcd_out(2,1,"Stop ");
PWM1_Set_Duty(0);
aux=0;

No
tecla=='C'

Si

lcd_out(2,7,"IZQ ");
PORTC.F0=1;
PORTC.F1=0;

No
tecla=='D'

Si

lcd_out(2,7,"DER ");
PORTC.F0=0;
PORTC.F1=1;

No
aux==1

Si

PWM1_Set_Duty(adc*2.55);

No
aux==0

Si

PWM1_Set_Duty(0);

Bucle =1

Fin

You might also like