sbit LCD_RS at RA0_bit;
sbit LCD_EN at RA1_bit;
sbit LCD_D4 at RB4_bit;
sbit LCD_D5 at RB5_bit;
sbit LCD_D6 at RB6_bit;
sbit LCD_D7 at RB7_bit;
sbit LCD_RS_Direction at TRISA0_bit;
sbit LCD_EN_Direction at TRISA1_bit;
sbit LCD_D4_Direction at TRISB4_bit;
sbit LCD_D5_Direction at TRISB5_bit;
sbit LCD_D6_Direction at TRISB6_bit;
sbit LCD_D7_Direction at TRISB7_bit;
sbit SR04_Echo at RA6_bit;
sbit SR04_Tigger at RA7_bit;
sbit SR04_Echo_Direction at TRISA6_bit;
sbit SR04_Tigger_Direction at TRISA7_bit;
unsigned char peso[12] ;
long txt[8];
int contador, variable;
int i = 0 ;
int distancia, talla1;
long dato,dato1;
int talla(){
distancia = HCSR04_Get_Distance(_cm);
IntToStr(distancia,txt);
return txt;
}
void main() {
CMCON=0x07;
NOT_RBPU_bit=1;
TRISB.RB0=1;
lcd_init();
UART1_init(1200);
delay_ms(100);
HCSR04_Init();
Lcd_Cmd(_LCD_CLEAR);
Lcd_Cmd(_LCD_CURSOR_OFF);
contador=0;
variable=0;
do {
if(Button(&PORTB,0, 1, 1))
{
variable=1;
}
if (variable && Button(&PORTB,0, 1,0))
{
variable=0;
contador++;
Lcd_Cmd(_LCD_CLEAR);
Lcd_Cmd(_LCD_CURSOR_OFF);
}
switch(contador){
case 0: DELAY_MS(20);
Lcd_Out(1,3,"Mensaje");
Lcd_Out(2,5,"Bienvenida");
break;
case 1: DELAY_MS(20);
Lcd_Out(1,1,"DISTANCIA");
talla1 = talla();
Lcd_Out(2,4,talla1);
break;
case 2: DELAY_MS(20);
Lcd_Out(1,3,"TOMA DE PESO"); // aqui es donde no se lee el
if (UART1_DATA_Ready()==0){ // dato enviado, por RF
// por teclado lo recibe bien y lo
Uart1_Read_Text(peso, "0", 7); // presenta.
Uart1_Write_Text(peso);
lcd_Out(2,1, peso);
}
break;
case 3: DELAY_MS(20);
Lcd_Out(1,1,"Dist: CM");
Lcd_Out(1,7,talla1);
Lcd_Out(2,1,"PESO: KGS");
Lcd_Out(2,6,peso);
break;
case 4: contador=0;
break;
}
}
while(1);
}