kEIl5c语言双向流水灯,【Keil5 C51】AT89C52 做流水灯实验(调用C51的库函数_crol_)

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仿真图

9138ffcabe004062dc2ea80b64782f5f.png

5b751aca33c416892b3e7fab4eea4e43.png

  • 2
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值