增加循环移位函数

This commit is contained in:
fengbh 2024-07-15 02:40:40 +08:00
parent 6d3124d648
commit 914d2dac24
2 changed files with 34 additions and 0 deletions

View File

@ -17,5 +17,7 @@ extern char __xdata receice_password[RESET_PASSWORD_LENGTH];
void delay_10us(u16 ten_us);
void delay_ms(u16 ms);
u8 auto_reset(u8 rec_data);
u8 rotate_left(u8 value, u8 shift);
u8 rotate_right(u8 value, u8 shift);
#endif

View File

@ -50,4 +50,36 @@ u8 auto_reset(u8 rec_data)
ISP_CONTR = 0x60; //软件复位并切换到系统ISP监控程序区开始执行程序
return 0;
}
/*******************************************************************************
* : rotate_left
* :
* : valueshift
* :
*******************************************************************************/
u8 rotate_left(u8 value, u8 shift) {
// 保存最高位
u8 high_bit = value & 0x80;
// 执行左移操作
value <<= shift;
// 将最高位循环到最低位
value |= high_bit >> (8 - shift);
return value;
}
/*******************************************************************************
* : rotate_right
* :
* : valueshift
* :
*******************************************************************************/
u8 rotate_right(u8 value, u8 shift) {
// 保存最低位
u8 low_bit = value & 0x01;
// 执行右移操作
value >>= shift;
// 将最低位循环到最高位
value |= low_bit << (8 - shift);
return value;
}