You are on page 1of 4

/*

* ESPIRULINA.c
*
* Created: 3/12/2018 15:06:04
* Author : JeanPaul
*/
#define F_CPU 16000000
#include <avr/io.h>
#include <util/delay.h>
#include <stdlib.h>
#include <avr/interrupt.h>
#include "lcd.h"

void configuracion_timer1();

uint8_t horas=0,minutos=0,segundos=0;
uint8_t h=1,m=1;
uint8_t contador=0;

char h_1[16];
char m_1[16];
char s_1[16];

char h_2[16];
char m_2[16];

int main(void)
{

DDRB=0X00; //pulsadores de temporizador


DDRA=0XFF; //salida de la bomba
DDRC=0x00;//encendido y pagado manual de la bomba

configuracion_timer1();
lcd_init(LCD_DISP_ON);
PORTA=0x00;

while (1)
{

if (contador==102)
{

contador=1;
segundos+=1;
itoa(segundos,s_1,10);
lcd_gotoxy(6,1);
lcd_puts(s_1);
if (segundos==60)
{
lcd_clrscr();
segundos=0;
minutos+=1;
itoa(minutos,m_1,10);
lcd_gotoxy(3,1);
lcd_puts(m_1);

if (minutos==60)
{
lcd_clrscr();
minutos=0;
horas+=1;
itoa(horas,h_1,10);
lcd_gotoxy(0,1);
lcd_puts(h_1);

if (horas==24)
{
lcd_clrscr();
horas=0;
itoa(horas,h_1,10);
lcd_gotoxy(0,1);
lcd_puts(h_1);

}
}
}
}
else
{
itoa(segundos,s_1,10);
lcd_gotoxy(6,1);
lcd_puts(s_1);

lcd_gotoxy(2,1);
lcd_puts(":");

itoa(minutos,m_1,10);
lcd_gotoxy(3,1);
lcd_puts(m_1);

lcd_gotoxy(5,1);
lcd_puts(":");

itoa(horas,h_1,10);
lcd_gotoxy(0,1);
lcd_puts(h_1);
//******************************
itoa(m,m_2,10);
lcd_gotoxy(13,1);
lcd_puts(m_2);

lcd_gotoxy(12,1);
lcd_puts(":");

itoa(h,h_2,10);
lcd_gotoxy(10,1);
lcd_puts(h_2);

if (PINB&(1<<PC0))
{
while (PINB&(1<<PC0))
{
_delay_ms(100);
}
minutos+=1;
itoa(minutos,m_1,10);
lcd_gotoxy(3,1);
lcd_puts(m_1);

}
if (PINB&(1<<PC1))
{
while (PINB&(1<<PC1))
{
_delay_ms(100);
}
horas+=1;
itoa(horas,h_1,10);
lcd_gotoxy(6,1);
lcd_puts(h_1);
}
//********************************************
if (PINB&(1<<PB2))
{
while (PINB&(1<<PB2))
{
_delay_ms(100);
}
m+=1;
itoa(m,m_2,10);
lcd_gotoxy(13,1);
lcd_puts(m_2);

}
if (PINB&(1<<PB3))
{
while (PINB&(1<<PB3))
{
_delay_ms(100);
}
h+=1;
itoa(h,h_2,10);
lcd_gotoxy(10,1);
lcd_puts(h_2);
}
//********************************************

if(PINC==0X00)
{
if ((horas==h && minutos==m))
{
PORTA=0xff ;
}
if((horas==h && (minutos>(m+5)))||(minutos<m||horas<h) )
{
PORTA=0x00;
}
}
else
{
PORTA=0XFF;
}

//*********************************************

}
}

void configuracion_timer1()
{
cli();
TCCR0=(1<<CS02)|(0<<CS01)|(1<<CS00);
TIMSK=(1<<TOIE0);
TCNT0=100;
sei();

ISR(TIMER0_OVF_vect)
{

contador+=1;

TCNT0=100;
}

You might also like