12DG128中断接收,急啊!!各位前辈多多帮忙啊
- UID
- 345466
- 性别
- 男
|
12DG128中断接收,急啊!!各位前辈多多帮忙啊
这是系统时钟和SCI0初始化:
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) {
uchar data;
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]);
}
data=SCI0SR1; //OR中断
data=SCI0DRL;
}
请各位前辈多多指导啊
做了一天了,中断接收都出不来,急啊
interrupt 20 void SCI0_interrupt(void)
{
while(SCI0SR1_RDRF)
{
rdata[0]=SCI0SR1;
rdata[0]=SCI0DRL;
}
}
如果用这个,无论由PC机发什么数据,12DG128返回3个一样的十六进制数:0xe1,0x01,0xe1
这是为什么啊 |
|
|
|
|
|
- UID
- 104380
- 性别
- 男
|
|
|
|
|
|