#include <reg51.h>
#include <ABSACC.H>
void delay(unsigned int i1);
void init8279(void);
void disp8279(void);
#define C8279 XBYTE[0xE001]
#define D8279 XBYTE[0xE000]
#define CH372_DATA XBYTE[0x8000]
#define CH372_CMD XBYTE[0x8001]
unsigned char i, buffer[8];
void int0() interrupt 0 using 1
{unsigned char ADRESS_L,ADRESS_H,CHANGDU_L,CHANGDU_H,CMD_BUFFER[4],a[7],i,cj1,cj5,cj7,cj6;
//中断程序
RS0=1; //PSW.3,切换至工作寄存器组1
CH372_CMD=0x22 ; //获取中断状态 并取消中断请求
i=CH372_DATA;
IE0=0;
if (i!=0x02) // USB端点2的OUT 批量下传成功
{ if (i!=0x0A) //USB端点1的IN
{ //CH372_UP_INTOK
if (i==0x09) //USB端点1的IN
{ CH372_CMD=0x23; } //中断数据发送成功,;解锁寄存器,清中断等待标志,通知应用程序可以继续发送中断数据
}
else // CH372_UPOK i==0x0A
{ cj1=CHANGDU_L|CHANGDU_H; // USB批量数据发送成功CH372_UPOK:
if(cj1!=0)
{ cj5= CHANGDU_L-0x40;
cj6= CHANGDU_H-0x00;
if(cj6&0x80==0x80)
{ //CH372_UPEND
cj7=CHANGDU_L;
CHANGDU_L=0x00;
}
else //cj6&0x80!=0x80
{
cj7=0x40;
CHANGDU_L=cj5;
CHANGDU_H=cj6;
}
//CH372_UPNEXT
CH372_CMD=0x2b;
CH372_DATA=cj7;
//CH372_INTUP1
do{
cj1=ADRESS_L;
i=cj1;
cj1++;
ADRESS_L=cj1;
CH372_DATA=i;
cj7--;
} while(cj7!=0);
//CH372_INTUNLK
CH372_CMD=0x23; //解锁寄存器 转到CH372_INTRET
}
}
}
//接收成功 ,CH372_DOWNOK i=0x02
else
{
CH372_CMD=0x28; //从当前USB中断的端点缓冲区读取数据块,并释放缓冲区 长度+数据
i =CH372_DATA; //读下载长度
cj7=i;
if(i!=0) //如果i==0x00; LJMP CH372_INTRET
{
if(i==0x07) //不是命令包
{ cj1=CMD_BUFFER[0];} // CH372_INTCMD
do { //CH372_INTCMD0
cj1=i;
cj1++;
cj7--;
} while(cj7!=0) ;
i= CMD_BUFFER[0] ; // 取命令
if(i!=0x0a0) //否则转到 CH372_INTRET
{ //CH372_INTCMD1
if(i==0x0a2) //下传数据块
{
ADRESS_L =CMD_BUFFER[1]; //地址
ADRESS_H =CMD_BUFFER[2];
CHANGDU_L=CMD_BUFFER[3]; //长度
CHANGDU_H=CMD_BUFFER[4]; //转到 CH372_INTRET
}
else //CH372_INTCMD2 i!=0x0a2
{
if(i==0x0a1)
{
ADRESS_L =CMD_BUFFER[1]; //地址
ADRESS_H =CMD_BUFFER[2];
CHANGDU_L=CMD_BUFFER[3]; //长度
CHANGDU_H=CMD_BUFFER[4];
cj5=CHANGDU_L-0x40;
cj6=CHANGDU_H-0x00;
if(cj6&0x80!=0x80) //上传不足 64个长度
{
cj7=0x40;
CHANGDU_L=cj5;
CHANGDU_H=cj6;
}
else // CH372_UPSHORT cj6&0x80==0x80 //CH372_UPSHORT
{
cj7=CHANGDU_L;
CHANGDU_L=0x00;
}
//CH372_UPFIRST
CH372_CMD=0x2b; //向USB端点2的发送缓冲区写入数据块
CH372_DATA =cj7;
do{ //CH372_INTUP0
cj1=CMD_BUFFER[1];
i=cj1;
cj1++;
(CMD_BUFFER[1])=cj1;
CH372_DATA=i;
cj7--;
}while(cj7!=0); //LJMP CH372_INTRET
}
else //CH372_INTCMD3 i!=0x0a1
{
if(i==0x91)
{
CH372_CMD=0x2b; //向USB端点2的发送缓冲区写入数据块
CH372_DATA=0x07; //命令长度
cj7=0x07;
cj1=CMD_BUFFER[0];
do //CH372_TEST
{
i=cj1;
if((cj1&0x01)==0x01)
{a[0]=0x80;}
else{a[0]=0x00;}
if((cj1&0x02)==0x02)
{a[1]=0x40;}
else{a[1]=0x00;}
if((cj1&0x04)==0x04)
{a[2]=0x20;}
else{a[2]=0x00;}
if((cj1&0x08)==0x08)
{a[3]=0x10;}
else{a[3]=0x00;}
if((cj1&0x10)==0x10)
{a[4]=0x08;}
else{a[4]=0x00;}
if((cj1&0x20)==0x20)
{a[5]=0x04;}
else{a[5]=0x00;}
if((cj1&0x40)==0x40)
{a[6]=0x02;}
else{a[6]=0x00;}
if((cj1&0x80)==0x80)
{a[7]=0x01;}
else{a[7]=0x00;}
i=a[0]|a[1]|a[2]|a[3]|a[4]|a[5]|a[6]|a[7];
CH372_DATA=i;
cj1++;
cj7--;
}while(cj7!=0);
CHANGDU_L=0x00;
CHANGDU_H=0x00; //LJMP CH372_INTRET
}
else //CH372_INTCMD4 i!=0x91
{ if(i!=0x56)
{while(1){;}}
cj1=CMD_BUFFER[4];
i=0x87-cj1;