说明文件 : cror库函数,实现右移,同理,crol为左移
#include <intrins.h>unsigned char _cror_ ( //循环要两个变量unsigned char c, /* 循环左移*/unsigned char b); /* 循环几位(位数)*/
#include <intrins.h>void test_cror (void) {char a;char b;a = 0xA5; //A5为1010 0101b = _crol_(a,1); /* b now is 0xD2 ,D2为1101 0010,即右移,将末尾提到最左*/}
循环不断左移(右移),则能以总线相继点亮不同的灯,形成流水灯
代码
#include "reg52.h"#include "intrins.h"typedef unsigned char u16 ;typedef unsigned int u8 ;u16 temp;void delay(u8 z){u8 x,y;for(x=z; x>0; x--){for(y=70; y>0; y--);//用keil软件调试出500ms}}void main(){temp=0xfe; //第一个led,1111 1110P2=temp; //整条总线附上while(1){temp=_crol_(temp,1);//把temp循环左移1位delay(800); //延时亮一会P2=temp; //点亮下一个灯,无限循环}}
定时器流水灯
#include "reg52.h"#include "intrins.h"typedef unsigned int u8;typedef unsigned char u16;u16 temp;void time(){TMOD=0x01;TH0=0XD4; //gao8TL0=0XCD; //di 8EA=1;ET0=1;TR0=1;}void main(){temp=0xfe;time();while(1);}void enter0() interrupt 1 //进入定时器中断函数{static u8 i;TH0=0XD4; //gao8TL0=0XCD; //di 8i++;if(i==10){P2=temp;i=0;temp=_cror_(temp,1);}}
