void adjust_time(void)
{
uchar i,ucTemp;
sendbuf[0]=0xff; /*帧起始字节*/
sendbuf[1]=0x10; /*命令*/
sendbuf[2]=0x05; /*数据长度*/
sendbuf[9]=0x0d; /*帧结束字节*/
sendbuf[3]=0;//GetMonth(); /*月*/
sendbuf[4]=0;//GetDay(); /*日*/
sendbuf[5]=0;//GetHour(); /*时*/
sendbuf[6]=0;//GetMinute(); /*分*/
sendbuf[7]=0;//GetSecond(); /*秒*/
for(ucTemp=sendbuf[1],i=2;i <8;i++) /*计算校验和*/
ucTemp+=sendbuf[i];
sendbuf[8]=(~ucTemp)+1;
sendlen=10;
SendStart();
}
void sio1() interrupt 7 using 2 /*串口1中断--DR & PC*/
{
xdata uchar ucXor,i;
if (_testbit_(TI))
{ //发送数据
if (sendfull==0 && sendpoint <sendlen)
{
SBUF1 = sendbuf[sendpoint++];
}
else
sendfull==1;
}
}
void ini_mcu(void)
{
PMR = 0x40; //4 clocks/machine cycles , switch disable , ALE enable ,
internal 1K SRAM disable , oscilator enable
DPS = 0x00; //DPTR is selected
CKCON = 0xc1; //clock of Timer0,1,2 is divided by 12 ,others default
WDCON = 0x00; //disable wathcdog reset
EIE = 0x00; //disable watchdog interrupt and extern2-5 interrupt
EIP = 0x00; //all extended interrupt priority disable
T2MOD = 0xf0; //EXTN2,3,4,5 flag auto clear,T2 down counter disable
T2CON = 0x00; //Timer1 act as baudrater
SCON1 = 0X50;
TMOD = 0x20; //start Timer0 ,1ms interrupt
TH1 = 0xFA;
TL1 = 0xFA;
TR1 = 1;
ES1 = 1; //enable serial port interrupt
ET1 = 0;
EA = 1; //first enable all interrupt
}
void main(void)
{ini_mcu();
adjust_time();
}