#include"pic.h"
#define uchar unsigned char
#define uint unsigned int
#define Some_nop(); NOP(); NOP(); NOP(); NOP(); NOP(); NOP();
extern set_inte();
uchar time_chang_flag;
uchar time_over_flag;
uchar set_clock1_flag;
void Key_init(void)
{
TRISB |= 0x1f;
OPTION &= 0x3f;
RBIE = 1;
}
void delay(void)
{
uint i;
for(i=6553;--i;)
continue;
}
void restart()
{
RD1 = 0;
time_over_flag = 0;
set_clock1_flag = 0;
time_buff = 2;
}
//********************************************************
main()
{
uchar i,j;
uchar time_buff;
TRISD = 0;
PORTD = 0;
GIE = 1;
Key_init();
set_clock1_flag = 0;
time_over_flag = 0;
time_chang_flag = 0;
time_buff = 2;
while(1)
{
if(time_chang_flag==1)
{
RD2=1;
time_chang_flag = 0;
time_buff = 0;
}
if(time_buff < 1)
{
if(set_clock1_flag==0)
{
RD1 = 1;
RD3=0;
set_clock1_flag = 1;
INTE = 1;
set_inte();
}
}
if(time_over_flag==1)
{
time_over_flag = 0;
RD3=1;
set_clock1_flag = 0;
restart();
}
}
}
void interrupt interrupt_job()
{
if(RBIF)
{
RBIF = 0;
delay();
PORTB = PORTB;
if(RB4==0)
{
if(time_chang_flag==0)
{
time_chang_flag = 1;
}
}
RBIF = 0;
}
if(INTF)
{
INTE = 0;//disable int wait clear 8563 alarm
INTF = 0;
time_over_flag = 1;
}
}