-
pic软件计算奇偶校验,出错
pic软件计算奇偶校验,发送1,2,3,4,5。显示3F,3F,03,3F,05。请大家帮忙看看uint add (uint data) //奇校验 1的个数为奇数 { uint i = 0; int cnt = 0; int temp = 0; for(i = 0;i < 8;i++) { temp = ((data >> i) & 1); cnt += temp; } if(cnt%2 == 0) { return 1; } else { return 0; } } void Usart_Init (void) { RCSTA = 0xD0; //9位接收 TXSTAbits.TX9 = 1; //9位发送 TXSTAbits.TXEN = 1; //使能发送 TXSTAbits.SYNC = 0; //异步 TXSTAbits.BRGH = 1; //高速 BAUDCONbits.BRG16 = 0; //SYNC = 0, BRGH = 1, BRG16 = 0 SP1BRGH = 0; SP1BRGL = 0x19; //25,波特率9600 RCIE = 1; RCIF = 0; // TXIE = 1; } void Usart_SEND (uint TX) { TXSTAbits.TX9D = add(TX); TXREG = TX; while(!TXSTAbits.TRMT); delayus(50); }
1147浏览量 4回复量 关注量