void aknowledge()
{ scl=1;_nop_();_nop_();scl=0;}
void start()
{sda=1; scl=1; _nop_();_nop_();sda=0;scl=0;}
void stop()
{sda=0; scl=1; _nop_();_nop_();sda=1;scl=0;}
unsigned char read_byte()
{unsigned char reead;
unsigned int i;
sda=1;
reead=0;
for(i=0;i<8;i++)
{
reead=reead<<1;
scl=1;
_nop_();
_nop_();
if(sda==1)
reead++;
scl=0;
}
sda=0;
return reead;}
void send_byte(unsigned char value)
{ unsigned int i;
unsigned char send;
send=value;
for(i=0;i<8;i++)
{sda=send/128;
send=send<<1;
scl=1;
_nop_();
_nop_();
scl=0;}
ack=sda;
sda=0;}
void save()
{start();
send_byte(0xA0);
aknowledge();
send_byte(0x00);
aknowledge();
send_byte(arm_hr);aknowledge();
send_byte(arm_min);aknowledge();
send_byte(dis_hr);aknowledge();
send_byte(dis_min);aknowledge();
send_byte(htr_time);aknowledge();
send_byte(ent_time);aknowledge();
send_byte(ext_time);aknowledge();
send_byte(user_key[0]);aknowledge();
send_byte(user_key[1]);aknowledge();
send_byte(user_key[2]);aknowledge();
send_byte(user_key[3]);aknowledge();
send_byte(zone_key[1]);aknowledge();
send_byte(zone_key[2]);aknowledge();
send_byte(zone_key[3]);aknowledge();
send_byte(zone_key[4]);aknowledge();
send_byte(zone_key[5]);aknowledge();
send_byte(zone_key[6]);aknowledge();
send_byte(zone_key[7]);aknowledge();
send_byte(zone_key[8]);aknowledge();
stop();
if(key[0]=='9' && key[1]=='5'&& key[2]=='6' && key[3]=='7')
{send_command_lcd(0x80,"Settting default \0");
send_command_lcd(0xc0," Please wait... \0");
delay();delay();delay();delay();delay();
main_full();
}
settings();
}
void Read()
{start();
send_byte(0xA0);
aknowledge();
send_byte(0x00);
aknowledge();
start();
send_byte(0xA1);
aknowledge();
arm_hr=read_byte();aknowledge();
arm_min=read_byte();aknowledge();
dis_hr=read_byte();aknowledge();
dis_min=read_byte();aknowledge();
htr_time=read_byte();aknowledge();
ent_time=read_byte();aknowledge();
ext_time=read_byte();aknowledge();
user_key[0]=read_byte();aknowledge();
user_key[1]=read_byte();aknowledge();
user_key[2]=read_byte();aknowledge();
user_key[3]=read_byte();aknowledge();
zone_key[1]=read_byte();aknowledge();
zone_key[2]=read_byte();aknowledge();
zone_key[3]=read_byte();aknowledge();
zone_key[4]=read_byte();aknowledge();
zone_key[5]=read_byte();aknowledge();
zone_key[6]=read_byte();aknowledge();
zone_key[7]=read_byte();aknowledge();
zone_key[8]=read_byte();aknowledge();
stop();
}