Professional Documents
Culture Documents
// ab : cd : ef
#define ON 1
#define OFF 0
#define start PINA.0
#define stop PINA.1
#define next PINA.2
#define uj PINA.3
#define um PINA.4
#define ud PINA.5
#define dj PINA.6
#define dm PINA.7
#define dd PINB.0
void pembuka();
void time();
void time1();
void jam()
//=============================================================================
{
a = 0;
b = 0;
c = 0;
d = 0;
e = 0;
f = 0;
//=============================================================================
help = hours;
// ab : __ : __
while (help > 9)
{
help -= 10;
a++;
};
b = help;
//=============================================================================
help = minuts;
// __ : cd : __
while (help > 9)
{
help -= 10;
c++;
};
d = help;
//=============================================================================
help = seconds;
// __ : __ : ef
while (help > 9)
{
help -= 10;
e++;
};
f = help;
// ab : cd : ef
// Alrm gh : ij
lcd_gotoxy(0,0);
lcd_putsf("RELAY 1:");
sprintf(buff,"%d",a);
lcd_puts(buff);
sprintf(buff,"%d",b);
lcd_puts(buff);
lcd_putsf(":");
sprintf(buff,"%d",c);
lcd_puts(buff);
sprintf(buff,"%d",d);
lcd_puts(buff);
lcd_putsf(":");
sprintf(buff,"%d",e);
lcd_puts(buff);
sprintf(buff,"%d",f);
lcd_puts(buff);
};
void time()
{
a = 0;
b = 0;
c = 0;
d = 0;
e = 0;
f = 0;
//=============================================================================
help = hours;
// ab : __ : __
while (help > 9)
{
help -= 10;
a++;
};
b = help;
//=============================================================================
help = minuts;
// __ : cd : __
while (help > 9)
{
help -= 10;
c++;
};
d = help;
//=============================================================================
help = seconds;
// __ : __ : ef
while (help > 9)
{
help -= 10;
e++;
};
f = help;
lcd_gotoxy(3,0);
lcd_putsf("SET RELAY 1");
lcd_gotoxy(4,1);
sprintf(buff,"%d",a);
lcd_puts(buff);
sprintf(buff,"%d",b);
lcd_puts(buff);
lcd_putsf(":");
sprintf(buff,"%d",c);
lcd_puts(buff);
sprintf(buff,"%d",d);
lcd_puts(buff);
lcd_putsf(":");
sprintf(buff,"%d",e);
lcd_puts(buff);
sprintf(buff,"%d",f);
lcd_puts(buff);
if (uj == 0)
{
hours++;
if (hours > 23) hours = 0;
};
if (dj == 0)
{
hours--;
if (hours > 23) hours = 23;
};
if (um == 0)
{
minuts++;
if (minuts > 59) minuts = 0;
};
if (dm == 0)
{
minuts--;
if (minuts > 59) minuts = 59;
};
if (ud == 0)
{
seconds++;
if (seconds > 59) seconds = 0;
};
if (dd == 0)
{
seconds--;
if (seconds > 59) seconds = 59;
};
delay_ms(50);
}
void time1()
{
a = 0;
b = 0;
c = 0;
d = 0;
e = 0;
f = 0;
//=============================================================================
help = hours;
// ab : __ : __
while (help > 9)
{
help -= 10;
a++;
};
b = help;
//=============================================================================
help = minuts;
// __ : cd : __
while (help > 9)
{
help -= 10;
c++;
};
d = help;
//=============================================================================
help = seconds;
// __ : __ : ef
while (help > 9)
{
help -= 10;
e++;
};
f = help;
lcd_gotoxy(3,0);
lcd_putsf("SET RELAY 1");
lcd_gotoxy(4,1);
sprintf(buff,"%d",a);
lcd_puts(buff);
sprintf(buff,"%d",b);
lcd_puts(buff);
lcd_putsf(":");
sprintf(buff,"%d",c);
lcd_puts(buff);
sprintf(buff,"%d",d);
lcd_puts(buff);
lcd_putsf(":");
sprintf(buff,"%d",e);
lcd_puts(buff);
sprintf(buff,"%d",f);
lcd_puts(buff);
if (uj == 0)
{
hours++;
if (hours > 23) hours = 0;
};
if (dj == 0)
{
hours--;
if (hours > 23) hours = 23;
};
if (um == 0)
{
minuts++;
if (minuts > 59) minuts = 0;
};
if (dm == 0)
{
minuts--;
if (minuts > 59) minuts = 59;
};
if (ud == 0)
{
seconds++;
if (seconds > 59) seconds = 0;
};
if (dd == 0)
{
seconds--;
if (seconds > 59) seconds = 59;
};
delay_ms(50);
}
// Timer 1 overflow interrupt service routine
interrupt [TIM1_OVF] void timer1_ovf_isr(void)
{
// Reinitialize Timer 1 value
TCNT1H=0xD23A >> 8;
TCNT1L=0xD23A & 0xff;
// Place your code here
seconds--;
if (seconds > 59)
{
seconds = 59;
minuts--;
if (minuts > 59)
{
minuts = 59;
hours--;
if (hours > 23)
{
hours = 23;
};
};
};
jam();
}
void main()
{
// Declare your local variables here
// Input/Output Ports initialization
// Port A initialization
// Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In
// State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=T
PORTA=0xFF;
DDRA=0x00;
// Port B initialization
// Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In
// State7=P State6=P State5=P State4=P State3=P State2=P State1=P State0=P
PORTB=0xFF;
DDRB=0x00;
// Port C initialization
// Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In
// State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=T
PORTC=0x00;
DDRC=0x00;
// Port D initialization
// Func7=In Func6=In Func5=In Func4=In Func3=Out Func2=Out Func1=In Func0=In
// State7=T State6=T State5=T State4=T State3=0 State2=0 State1=T State0=T
PORTD=0x00;
DDRD=0x0C;
// Timer/Counter 0 initialization
// ADC initialization
// ADC disabled
ADCSRA=0x00;
// SPI initialization
// SPI disabled
SPCR=0x00;
// TWI initialization
// TWI disabled
TWCR=0x00;
// Alphanumeric LCD initialization
// Connections are specified in the
// Project|Configure|C Compiler|Libraries|Alphanumeric LCD menu:
// RS - PORTC Bit 0
// RD - PORTC Bit 1
// EN - PORTC Bit 2
// D4 - PORTC Bit 4
// D5 - PORTC Bit 5
// D6 - PORTC Bit 6
// D7 - PORTC Bit 7
// Characters/line: 16
lcd_init(16);
pembuka();
lcd_clear();
timing:
while (start==1)
{
time();
}
// Global enable interrupts
lcd_clear();
#asm("sei")
while (1)
{
// Place your code here
if (stop == 0)
{
#asm("cli")
lcd_clear();
SIGNAL = OFF;
goto timing;
};
if (hours == 0)
{
if (minuts == 0)
{
if (seconds == 0)
{
#asm("cli")
SIGNAL = ON;
}
}
}
};
}