📄 main.txt
字号:
asm("icr .set 0ffech ");
asm("pmst .set 0ffe4h ");
asm("sdtr .set 0fff0h ");
asm("adtr .set 0fff4h");
asm("aspcr .set 0fff5h");
asm("iosr .set 0fff6h");
asm("brd .set 0fff7h");
asm("ifr .set 0006h");
asm("imr .set 0004h");
asm("wsgr .set 0fffch ");
volatile unsigned int *imr = (volatile unsigned int * )0x0004;
volatile unsigned int *greg = (volatile unsigned int * )0x0005;
volatile unsigned int *ifr = (volatile unsigned int * )0x0006;
ioport unsigned port0ffe4; /*PMST*/
#define pmst port0ffe4
ioport unsigned port0fff7; /*BRD*/ /*identify capslock mode*/
#define brd port0fff7
ioport unsigned port0fff6; /*iosr*/
#define iosr port0fff6
ioport unsigned port0fff5; /*aspcr*/
#define aspcr port0fff5
ioport unsigned port0ffe8; /*clk*/
#define clk port0ffe8
ioport unsigned port0ffec; /*icr*/
#define icr port0ffec
ioport unsigned port0fffc; /*wsgr*/
#define wsgr port0fffc;
ioport unsigned port0fff4; /*adtr*/
#define adtr port0fff4;
/**************************************************************/
unsigned int sendbuff[3]={0}; /*串口发送缓冲区*/
unsigned int recebuff[6]={0};
unsigned int recdata[3]={0};
unsigned int sendready[3]={0};
unsigned int senddata=0;
unsigned int rdpoint=0;
unsigned int sdpoint=0;
unsigned int sendnum=0;
unsigned int sendenable=4;
unsigned int ready=0;
unsigned int recing=0;
unsigned int recnum=0;
static unsigned int receach[4][4]={{0,0}};
static unsigned int receach4[4][4]={{0,0}};
static unsigned int receach3[3][4]={{0,0}};
void proA();
void proB();
void hexascii(unsigned int *a,unsigned int b[4] );
void asciihex(unsigned int b[4],unsigned int *a );
/**************************************************************/
void asciihex(unsigned int b[4],unsigned int *a )
{char i,ch;
*a=0;
for (i=0;i<4;i++)
{ ch=b[i];
if( ((ch>='0')&& (ch<='9')) || ((ch>='A')&&(ch<='F')) )
{
switch(ch){
case 0x30: ch=0; break;
case 0x31: ch=1; break;
case 0x32: ch=2; break;
case 0x33: ch=3; break;
case 0x34: ch=4; break;
case 0x35: ch=5; break;
case 0x36: ch=6; break;
case 0x37: ch=7; break;
case 0x38: ch=8; break;
case 0x39: ch=9; break;
case 0x41: ch=10; break;
case 0x42: ch=11; break;
case 0x43: ch=12; break;
case 0x44: ch=13; break;
case 0x45: ch=14; break;
case 0x46: ch=15; break;
} ;
*a=*a+(ch<<(3-i)*4);
}
else *a=0;
}
}
void hexascii(unsigned int *a,unsigned int b[4] )
{
unsigned char ch;
unsigned int i;
for (i=0;i<4;i++)
{ ch= *a>>((3-i)*4);
ch=ch & 0x0f;
switch(ch){
case 0: ch=0x30; break;
case 1: ch=0x31; break;
case 2: ch=0x32; break;
case 3: ch=0x33; break;
case 4: ch=0x34; break;
case 5: ch=0x35; break;
case 6: ch=0x36; break;
case 7: ch=0x37; break;
case 8: ch=0x38; break;
case 9: ch=0x39; break;
case 10: ch=0x41; break;
case 11: ch=0x42; break;
case 12: ch=0x43; break;
case 13: ch=0x44; break;
case 14: ch=0x45; break;
case 15: ch=0x46; break;
} ;
b[i]=ch;
}
}
void sciinitial()
{
aspcr = 0xe08f; /* rece interrupt send only = 0xe10fh*/
iosr = 0x0ff0;
brd = 0x0082;
}
void proB()
{ int i;
asciihex(recedata[3],senddata);
senddata=senddata+4369; /*senddata=0x2345/*
hexascii(senddata,sendready[3]);
aspcr=0x0e18f;
for(i=0,sendnum=0;i<4;i++,sendnum++)
{sendbuff[sendnum]=sendready[i];
sendnum=0;
adtr=sendbuff[sendnum];/*adtr*/
sendnum++;
sendenable--;
}
}
/*************************************************************************/
main()
{ int i;
asm(" setc intm "); /*清除所有中断*/
asm(" clrc cnf"); /*B0分配到数据空间*/
asm(" LDP #0H");
pmst=0x04; /*PON=1.DON=0*/
clk=0x00; /*CLKOUT1 enable*/
icr=0x00; /*REST value*/
asm(" splk #0e40h,64h");
asm(" nop");
asm(" out 64h,wsgr"); /*等待状态产生器控制寄存器*/
*greg = 0x0000; /*all memory in local memory*/
*ifr = 0xffff;
sciinitial();
asm(" clrc INTM");
*imr = 0x0026; /*open TXRXINT TINT INT2/3 interrupt*/
asm(" splk #(_sendbuff),63h");
while(1)
{}
}
/***************************************************************************/
void interrupt receive()
{ static int judgeDR;
int i;
judgeDR=(iosr&0x0100);
if (judgeDR==0x0000)
{ aspcr=0x0e18f;
if(sendbuff[0]!=0)
{
adtr=sendbuff[sendnum];/*adtr*/
sendnum++;
sendenable--;
}
else
{
aspcr=0x0e08f ;
*ifrr=0x0020 ;
}
}
else
{ if (recing==1)
{
recbuff[recnum]=adtr;/*adtr*/
recbuff[recnum]=recbuff[recnum]&0x00ff;
recdata[rdpoint]=recbuff[recnum];
rdpoint++;
if(recbuff[recnum]=='&')
{recing=0;
goto end;}
else
{recnum++;
goto end;}
}
else
{
if(ready==1)
{
recbuff[recnum]=adtr;/*adtr*/
recbuff[recnum]=recbuff[recnum]&0x00ff;
if(recbuff[recnum]=='A')
{goto end;}
else if(recbuff[recnum]=='B')
{proB();}
}
else
{
recbuff[recnum]=adtr;
recbuff[recnum]=recbuff[recnum]&0x00ff;
if(recbuff[recnum]=='#')
{ready=1;
recnum=0;
goto end;}
else if(recbuff[recnum]=='$')
{
recing=1;
recnum=0;
goto end;
}
}
end:
*ifrr=0x0020 ;
return;
}
/**********************************************************************/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -