void initialsystermclock(void)
{
PLLCTL=0x00;
CLKSEL=0x00;
SYNR=3;
REFDV=0; //PLLCLK=2*OSCCLK*(SYNR+1)/(REFDV+1)
}
void initSCI0(void) {
uchar clear;
SCI0BDL=104; //MCLK=8MHz,波特率为4800
SCI0BDH=0x00; //SCIbaudrate=SCI module clock/(16*SCIBR[12:0])
SCI0CR1=0x00; //bit5,数据格式控制,1起始位,8数据位,1停止位,不打开奇偶校验//,奇校验
SCI0CR2=0x2c; //接收寄存器满或溢出中断允许,RIE=1时,允许中断。允许接收发送数据
clear=SCI0SR1;
}
interrupt 20 void SCI0_receive_isr(void) {
DisableInterrupts;
if(SCI0SR1&0x20) { //接收中断
rdata[0]=SCI0SR1;
rdata[0]=SCI0DRL;
switch(rdata[0]) {
case 0x01:pwm45set(1350);goahead();pwm6set(150); break; //左拐
case 0x02:pwm45set(1650);goahead();pwm6set(150); break; //右拐
case 0x03:pwm45set(1300);goahead();pwm6set(130); break; //前进
case 0x04:pwm45set(1700);goback(); pwm6set(130); break; //后退
case 0x05:pwm45set(1500);pwm6set(0);break; //停止
default:break;
}
SCI0_send(rdata[0]);
}
EnableInterrupts;
}
这样用中断接收有什么错误吗
为什么返回的数据不对呢 |