Skip to content

Instantly share code, notes, and snippets.

@LaloHao
Created November 21, 2015 01:24
Show Gist options
  • Save LaloHao/8ff94e3ac98cd9a6b0b6 to your computer and use it in GitHub Desktop.
Save LaloHao/8ff94e3ac98cd9a6b0b6 to your computer and use it in GitHub Desktop.
#define VERDE PORTE.RE0
#define AMARILLO PORTE.RE1
#define ROJO PORTE.RE2
#define T_total 60
#define T_medio T_total/2
#define T_critico 3
#define SEGUNDO 50 //1000ms=SEGUNDO
sbit LCD_RS at RD1_bit;
sbit LCD_EN at RD0_bit;
sbit LCD_D4 at RD4_bit;
sbit LCD_D5 at RD5_bit;
sbit LCD_D6 at RD6_bit;
sbit LCD_D7 at RD7_bit;
sbit LCD_RS_Direction at TRISD1_bit;
sbit LCD_EN_Direction at TRISD0_bit;
sbit LCD_D4_Direction at TRISD4_bit;
sbit LCD_D5_Direction at TRISD5_bit;
sbit LCD_D6_Direction at TRISD6_bit;
sbit LCD_D7_Direction at TRISD7_bit;
int contador = T_total;
char contador_en_lcd[2];
int no = 1;
void main()
{
ANSEL = 0; // Configure AN pins as digital I/O
ANSELH = 0;
TRISE=0;
PORTE=0;
C1ON_bit = 0; // Disable comparators
C2ON_bit = 0;
TRISA=0x01;
PORTA=0x00;
UART1_Init(9600);
Delay_ms(100);
Lcd_Init();
Lcd_Cmd(_LCD_CLEAR);
Lcd_Cmd(_LCD_CURSOR_OFF);
Lcd_Out(2, 1, "Inicializando...");
Delay_ms(1000);
Lcd_Cmd(_LCD_CLEAR);
do
{
Lcd_Out(1, 1, "Pulse el boton");
Lcd_Out(2, 1, "para comenzar.");
//contador = T_total;
while(no){
if(UART1_Data_Ready() == 1) {
UART1_Read_Text(contador_en_lcd, " ", 10);
contador = atoi(contador_en_lcd);
if(contador > 0) {
no = 0;
}
}
}
while(!Button(&PORTA, 0, 1, 1)){}
// if (Button(&PORTA, 0, 1, 1)){
Lcd_Out(1, 1, "Tiempo restante:");
while(contador > 0){
IntToStr(contador, contador_en_lcd);
Lcd_Out(2, 1, " ");
Lcd_Out(2, 1, contador_en_lcd);
UART1_Write_Text(contador_en_lcd);
UART1_Write(13);
UART1_Write(10);
if(contador > T_medio){
VERDE = 1;
AMARILLO = 0;
ROJO = 0;
} else if(contador > T_critico){
VERDE = 0;
AMARILLO = 1;
ROJO = 0;
} else {
VERDE = 0;
AMARILLO = 0;
ROJO = 1;
}
Delay_ms(SEGUNDO);
contador--;
}
no = 1;
// }
} while (1);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment