【Keil5 C51】调用C51的库函数_crol_做流水灯实验

北城余情 提交于 2020-02-08 20:22:46

_crol_ 函数的介绍

Cx51 User’s Guide

Summary

#include <intrins.h>

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变量中的b开始位 一次向左移动, 比如b = 1 时这串数字会这样移动:1111110–>11111101)

Return Value

The crol routine returns the rotated value of c.(把移动之后的值返回给c)

Example

#include <intrins.h>

void test_crol (void) {
  char a;
  char b;

  a = 0xA5;
  b = _crol_(a,3); /* b now is 0x2D */
}

流水灯代码

使用AT89C52芯片,晶振为11.0592MHz

#include <reg52.h>
#include <intrins.h>

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

在这里插入图片描述
在这里插入图片描述

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!