
#pragma used+
sfrb PINA=0;
sfrb DDRA=1;
sfrb PORTA=2;
sfrb PINB=3;
sfrb DDRB=4;
sfrb PORTB=5;
sfrb PINC=6;
sfrb DDRC=7;
sfrb PORTC=8;
sfrb PIND=9;
sfrb DDRD=0xa;
sfrb PORTD=0xb;
sfrb PINE=0xc;
sfrb DDRE=0xd;
sfrb PORTE=0xe;
sfrb PINF=0xf;
sfrb DDRF=0x10;
sfrb PORTF=0x11;
sfrb PING=0x12;
sfrb DDRG=0x13;
sfrb PORTG=0x14;
sfrb TIFR0=0x15;
sfrb TIFR1=0x16;
sfrb TIFR2=0x17;
sfrb TIFR3=0x18;
sfrb TIFR4=0x19;
sfrb TIFR5=0x1a;
sfrb PCIFR=0x1b;
sfrb EIFR=0x1c;
sfrb EIMSK=0x1d;
sfrb GPIOR0=0x1e;
sfrb EECR=0x1f;
sfrb EEDR=0x20;
sfrb EEARL=0x21;
sfrb EEARH=0x22;
sfrw EEAR=0X21;   
sfrb GTCCR=0x23;
sfrb TCCR0A=0x24;
sfrb TCCR0B=0x25;
sfrb TCNT0=0x26;
sfrb OCR0A=0x27;
sfrb OCR0B=0x28;
sfrb GPIOR1=0x2a;
sfrb GPIOR2=0x2b;
sfrb SPCR=0x2c;
sfrb SPSR=0x2d;
sfrb SPDR=0x2e;
sfrb ACSR=0x30;
sfrb OCDR=0x31;
sfrb SMCR=0x33;
sfrb MCUSR=0x34;
sfrb MCUCR=0x35;
sfrb SPMCSR=0x37;
sfrb RAMPZ=0x3b;
sfrb EIND=0x3c;
sfrb SPL=0x3d;
sfrb SPH=0x3e;
sfrb SREG=0x3f;
#pragma used-

#asm
	#ifndef __SLEEP_DEFINED__
	#define __SLEEP_DEFINED__
	.EQU __se_bit=0x01
	.EQU __sm_mask=0x0E
	.EQU __sm_powerdown=0x04
	.EQU __sm_powersave=0x06
	.EQU __sm_standby=0x0C
	.EQU __sm_ext_standby=0x0E
	.EQU __sm_adc_noise_red=0x02
	.SET power_ctrl_reg=smcr
	#endif
#endasm

char data[4]={0};

typedef char *va_list;

#pragma used+

char getchar(void);
void putchar(char c);
void puts(char *str);
void putsf(char flash *str);
int printf(char flash *fmtstr,...);
int sprintf(char *str, char flash *fmtstr,...);
int vprintf(char flash * fmtstr, va_list argptr);
int vsprintf(char *str, char flash * fmtstr, va_list argptr);

char *gets(char *str,unsigned int len);
int snprintf(char *str, unsigned int size, char flash *fmtstr,...);
int vsnprintf(char *str, unsigned int size, char flash * fmtstr, va_list argptr);

int scanf(char flash *fmtstr,...);
int sscanf(char *str, char flash *fmtstr,...);

#pragma used-

#pragma library stdio.lib

#pragma used+

void delay_us(unsigned int n);
void delay_ms(unsigned int n);

#pragma used-

void EEPROM_write(char WordAdress,char data)
{
(*(unsigned char *) 0xbc) = (1<<7)|(1<<5)|(1<<2);

while (!((*(unsigned char *) 0xbc) & (1<<7)));    

(*(unsigned char *) 0xbb) = 0xd0;

(*(unsigned char *) 0xbc) = (1<<7) |(1<<2);
while (!((*(unsigned char *) 0xbc) & (1<<7)));

(*(unsigned char *) 0xbb) = WordAdress;
(*(unsigned char *) 0xbc) = (1<<7) |(1<<2);

while (!((*(unsigned char *) 0xbc) & (1<<7)));

(*(unsigned char *) 0xbb) = data;
(*(unsigned char *) 0xbc) = (1<<7) |(1<<2); 

while (!((*(unsigned char *) 0xbc) & (1<<7)));

(*(unsigned char *) 0xbc) = (1<<7)|(1<<2)|(1<<4);

}
char EEPROM_read(char high)
{
char data=0;
(*(unsigned char *) 0xbc) = (1<<7)|(1<<5)|(1<<2);

while (!((*(unsigned char *) 0xbc) & (1<<7)));

(*(unsigned char *) 0xbb) = 0xd0;
(*(unsigned char *) 0xbc) = (1<<7) |(1<<2);

while (!((*(unsigned char *) 0xbc) & (1<<7)));

(*(unsigned char *) 0xbb) = high;
(*(unsigned char *) 0xbc) = (1<<7) |(1<<2);

while (!((*(unsigned char *) 0xbc) & (1<<7)));

(*(unsigned char *) 0xbc) = (1<<7)|(1<<5)|(1<<2);

while (!((*(unsigned char *) 0xbc) & (1<<7)));

(*(unsigned char *) 0xbb) = 0xd1;
(*(unsigned char *) 0xbc) = (1<<7) |(1<<2);

while (!((*(unsigned char *) 0xbc) & (1<<7)));

(*(unsigned char *) 0xbc) = (1<<7) |(1<<2);
while (!((*(unsigned char *) 0xbc) & (1<<7)));

data=(*(unsigned char *) 0xbb);
(*(unsigned char *) 0xbc) = (1<<7)|(1<<2)|(1<<4);

return data;     
}

void main(void)
{

#pragma optsize-
(*(unsigned char *) 0x61)=0x80;
(*(unsigned char *) 0x61)=0x00;
#pragma optsize+

(*(unsigned char *) 0xc0)=0x00;
(*(unsigned char *) 0xc1)=0x08;
(*(unsigned char *) 0xc2)=0x06;
(*(unsigned char *) 0xc5)=0x00;
(*(unsigned char *) 0xc4)=0x67;

(*(unsigned char *) 0xb8) = (16000000 -(16*100000 ))/(4*2*100000 ) ;
(*(unsigned char *) 0xb9)=0;
(*(unsigned char *) 0xbc)=0X04;
EEPROM_write(00,0); 
EEPROM_write(01,0x03);  
EEPROM_write(02,6);   
EEPROM_write(07,0x03);    

while (1)
{ 
static unsigned char data,data1,data2=0;
static unsigned char h,m,s=0;

data=EEPROM_read(0);
data1=(data&0x0f);  
data2=(data&0x70);  
data2=(data2>>4)*10; 

s=(data2+data1);

data=EEPROM_read(1);
data1=(data&0x0f);  
data2=(data&0x70);  
data2=(data2>>4)*10;
m=(data2+data1);    

data=EEPROM_read(2);
data1=(data&0x0f);  
data2=(data&0x30);  
data2=(data2>>4)*10;
h=(data2+data1);  

printf("hour: %d minute: %d second: %d\r\n",h,m,s);  

}
}
