标签:http mic mamicode pre delay 函数 char 操作 png
#include<reg52.h>
#include"led.h"
#include"delay.h"
int main()
{
liushuianwei();//按位
delay_xms(1000);
liushuixunhuan();//循环移位
delay_xms(1000);
liushuiyiwei();//移位
delay_xms(1000);
while(1);
return 0;
}
#ifndef __LED_H__
#define __LED_H__
#include"delay.h"
void liushuianwei(void);//按位
void liushuixunhuan(void);//循环
void liushuiyiwei(void);//移位
void liushuianwei()
{
led1 = on;// P1^0 = 0;
delay_xms(200);//延时200毫秒
led1 = off;
led2 = on;
delay_xms(200);//延时200毫秒
led2 = off;
led3 = on;
delay_xms(200);//延时200毫秒
led3 = off;
led4 = on;
delay_xms(200);//延时200毫秒
led4 = off;
led5 = on;
delay_xms(200);//延时200毫秒
led5 = off;
led6 = on;
delay_xms(200);//延时200毫秒
led6 = off;
led7 = on;
delay_xms(200);//延时200毫秒
led7 = off;
led8 = on;
delay_xms(200);//延时200毫秒
led8 = off;
}
void liushuixunhuan(void)
{
char i;
P1 = 0xfe;//1111 1110
for(i = 0;i<8;i++)
{
delay_xms(200);
P1 =_crol_(P1,1); /*将P1循环左移1位*/
}
P1 |= 0xff; //让P1^1 为1
}
void liushuiyiwei(void)
{
char i=0;
P1 = 0xfe;//1111 1110
for(i=0;i<8;i++)
{
delay_xms(200);
P1 <<= 1;//P1 = P1<<1;
P1 = P1 | 0x01;
}
}
#endif
#ifndef __DELAY_H__
#define __DELAY_H__
#include<intrins.h>
#define uint unsigned int //16 0-65535
#define on 0
#define off 1
sbit led1 = P1^0;
sbit led2 = P1^1;
sbit led3 = P1^2;
sbit led4 = P1^3;
sbit led5 = P1^4;
sbit led6 = P1^5;
sbit led7 = P1^6;
sbit led8 = P1^7;
void delay_xms(uint s);
void delay_xms(uint s)
{
uint i,j;
for(i=s;i>0;i--) //i=xms即延时约xms毫秒
for(j=112;j>0;j--);
}
###endif
标签:http mic mamicode pre delay 函数 char 操作 png
原文地址:https://www.cnblogs.com/Poppings/p/14489206.html