📄 test8.c
字号:
#include "REG5402.h"
int timer1_over;
int serial_temp;
int a1;
int a2;
int serialbyte_receive()
{
unsigned int i,a;
a=0;
for(;RXD!=0;);
PRD1=0xef;
TCR1=0x02eb;
while(timer1_over==0);
timer1_over=0;
if(RXD==0)
{
for(i=0;i<8;i++)
{
PRD1=0x1df;
TCR1=0x02eb;
for(;timer1_over==0;);
timer1_over=0;
a=a>>1;
if(RXD!=0)
a=a|0x8000;
}
PRD1=0x1df;
TCR1=0x02eb;
for(;timer1_over==0;);
timer1_over=0;
if(RXD==0) return 0;
}
else return 0;
a=a>>8;
serial_temp=a;
return 1;
}
void cpu_init()
{
PMST=0x3fa0;
SWWSR=0x7fff;
SWCR=0x0000;
IMR=0; IFR=IFR;
SPSA1=0xe;
SPSD1=0x3020;
}
void timer1_init() /* Sample time */
{
PRD1=0x1df;
TCR1=0x039b;
IMR=IMR|0x0080;
}
main()
{
int i;
serial_temp=0;
asm(" ssbx intm");
cpu_init();
timer1_init();
asm(" rsbx intm");
for(;;)
{
i=serialbyte_receive();
if(serial_temp==0xff)
{
i=serialbyte_receive();
a1=serial_temp;
i=serialbyte_receive();
a2=serial_temp;
READS=(a1<<8)+a2;
}
}
}
interrupt void timer1_int()
{
timer1_over=1;
TCR1=0x039b;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -