void SCI0_Init(void) { U8 Date; SCI0BDH=0x00; SCI0BDL=0xA4; //SCI0CR1=0x40; SCI0CR1=0x00; Date=SCI0DRL; Date=SCI0SR1; //SCI0CR2=0xEC; SCI0CR2=0x0C; } //------------------------------------------------------------------ void SCI0_Send_OneByte(S8 Date) { while(1) //等待数据寄存器为空时,发送 if(SCI0SR1_TDRE){ SCI0DRL=Date; break; } while(!SCI0SR1_TC); //等待直到发送完成 }
//------------------------------------------------------------------ void SCI0_Send_N_Byte(U8 n,S8 p[]) { U8 i; for(i=0;i<n;i++)SCI0_Send_OneByte(p); } //------------------------------------------------------------------ U8 SCI0_Re_One(U8 *f) //接收一个字节 返回接收数据和接收成功标识 { U8 Date; *f=0x01; while(1){ if(SCI0SR1_IDLE){ Date=0xFF; break; //如果总线空闲,则没有数据可接收 } else if(SCI0SR1_RDRF){ //等待接收寄存器满,读数据 Date=SCI0DRL; *f=0x00; //接收成功 break; } } return Date; //返回接收到的数据 } //------------------------------------------------------------------ U8 SCI0_Re_N(U8 n,U8 *p) //接收n字节数据,存放在数组p[]中 { U8 i; U8 fail=1; for(i=0;i<n;i++){ p=SCI0_Re_One(&fail); if(fail)break; } return fail; } //------------------------------------------------------------------- 还有问题 仅供参考 |