#include
/* for the intended 8051 derivative */
#include
#define BYTE unsigned char
#define WORD unsigned int
#define LONG unsigned long
#define dword unsigned long
#define DWORD unsigned long
#define byte unsigned char
#define word unsigned int
#define XBYTE ((unsigned char volatile xdata *) 0)
#define XWORD ((unsigned int volatile xdata *) 0)
#define NES 0x6000
data union{
LONG l;
BYTE b[4];
}lShift;
data BYTE bCnt;
/****************/
/* main program */
/****************/
void main (void) { /* execution starts here after stack init */
#define KEY_BREAK 0x1f800
#define BCNT_VALUE 0
//BYTE code abBitHi[] ={0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80};
//BYTE code KeyTable[][2]={}
data BYTE bKey=0xff, bC, bKeyTmp;
//data WORD wKb;
//data long lBrk;
data union{
LONG l;
BYTE b[4];
}lTmp;
bit fParity, fP;
TCON=0x01; //bit0: 1/0 falling edge/low level triggered external interrupts
IP=0x01; //bit0:Externl interrupt 0 Priority control bit
IE=0x81; //bit0:Enable External interrupt 0 control bit
//bit7:All control bit
XBYTE[NES]=0x00;
///if (bCnt>=BCNT_VALUE) {
while(1){
T0=~T0;
bCnt=BCNT_VALUE;
lTmp.l=lShift.l;
if ((((lTmp.b[1] & 0x1f)==0x1f) && ((lTmp.b[2] & 0xfc)==0x80)) ||
((lTmp.b[0]==0xfc) && (lTmp.b[1]<=0x10)))
{
//fBrk=1;
bKey &= 0x7f;
}
else if (((lTmp.b[0] & 0xa0)==0x80) && //stop bit=1, data bit7=0
((lTmp.b[1] & 0x20)==0x00) ){ //start bit==0 bit0 , data bit7==0
if (lTmp.b[0] & 0x40) fP=1; //parity bit bit9
else fP=0;
lTmp.l<<=2;
bKeyTmp=lTmp.b[0];
fParity=1;
for (bC=0; bC<=7; bC++){
if ((lTmp.b[0] & 0x80)!=0) fParity=~fParity;
lTmp.b[0]<<=1;
}
if (fP==fParity) {
//fOk=1;
//bKey=KeyTable[bKeyTmp];
bKey=bKeyTmp | 0x80;
}
}
P1=bKey;
XBYTE[NES]=bKey;
}
////else bCnt++; //while (1)
} //void main (void)
/**/void vInt0() interrupt 0 using 2
{
bit fT0;
fT0=INT1;
lShift.l>>=1;
if (fT0==0x01) lShift.b[0] |= 0x80;
///bCnt=0;
}
/* link
hello.obj
XDATA(0) IDATA(80H) RAMSIZE(256) SYMBOLS
*/
沒有留言:
張貼留言