unsigned char _crol_ (
unsigned char c, /* character to rotate left */
unsigned char b); /* bit positions to rotate */
Description
The _crol_ routine rotates the bit pattern for the character c left b bits. This routine is implemented as an intrinsic function (从c变量中的第1开始位 一次向左移动b位, 比如b = 1 时这串数字会这样移动:1111110–>11111101)
Return Value
The crol routine returns the rotated value of c.(把移动之后的值返回给c)
Example
#include void test_crol (void) {
char a;
char b;
a = 0xA5;
b = _crol_(a,3); /* b now is 0x2D */
}
流水灯代码
使用AT89C52芯片,晶振为11.0592MHz
#include #include #define uint unsigned int
#define uchar unsigned char
void delay(uint time);
void main()
{
uint led = 0xfe;//11111110
while(1){
P1 = led; //11111110 先让P1口的第一个灯亮
delay(500);//延时0.5s
led = _crol_(led,1);//调用_crol_函数,使led的变量从第一个开始左移 11111110-->11111101
//再返回给led ,此时led = 11111101
}
}
void delay(uint time) //delay = 1 ms 0.001s
{
uint x;
uint y;
uint z;
for(z = time; z > 0; z--){
for(x = 1; x > 0; x--){
for(y = 115; y > 0; y--){}
}
}
}
Proteus仿真图