23.3第一周

第一周

一、发光二极管的点亮,控制

1、led发光原理

二极管,PN结。

  1. led点亮:开发板原理图

注:二极管采用共阳极,需要对阴极即P1口输入低电平点亮

#include<reg52.h>
#include<intrins.h>
#define uint unsigned int
#define uchar unsigned char

void Delayms(uint time)//延迟函数
{
	uint i,j;
	for(i=0;i<time;i++)
	{
		for(j=0;j<110;j++);
	}
}

void main()
{
	uchar aa=0xFE;
	P1=aa;
	while(1)
	{
		P1=aa;
		aa=_irol_(aa,1);//循环左移
		Delayms(500);
	}
}

二、数码管

1、数码管原理图

2、数码管受两个锁存器管理

分别为位锁存器和段锁存器,分别控制哪一个数码管亮和数码管的那一段亮

2.1锁存器的原理:

通过输入高电平(1)(P2^6或P2^7)来打开,输入低电平关闭并保存上一次数据。

3、数码管移位循环输出0-9

#include<reg52.h>
#include<intrins.h>
#define uchar unsigned char
#define uint unsigned int
sbit dula=P2^6;
sbit wela=P2^7;

void DelayMS(uint x)
{
 	uchar i;
	while(x--)
	{
	 	for(i=120;i>0;i--);
	}
}
uchar code table[]={
	0x3f,0x06,0x5b,
	0x4f,0x66,0x6d,
	0x7d,0x07,0x7f,0x6f
};
void main()
{
	uint i=0;
	uchar aa = 0xfe;
	while(1)
	{
		wela = 1;	
		P0 = aa;
		wela = 0;
		
	  	P0=0xff;
		
        dula = 1;
		P0 = table[(i++)%10];
		dula = 0;
        
        P0 = 0xff;
        
		aa = _crol_(aa,1);
		if(aa==0xBF)//1011 1111
			aa = 0xFE;//1111 1110
		DelayMS(1000);
	}
}

4、6个数码管分别显示1-6

#include<reg51.h>
#define uint unsigned int
#define uchar unsigned char
sbit dula = P2^6;
sbit wela = P2^7;

void Delayms(uint time)
{
	uint i,j;
	for(i=0;i<time;i++)
	{
		for(j=0;j<110;j++);
	}
}


void main()
{//1
	while(1)
	{
	wela = 1;
	P0 = 0xfe;//1111 1110
	wela = 0;
	P0=0xff;
		
	dula = 1;
	P0 = 0x06;
	dula = 0;
	Delayms(1);
	P0=0xff;
//2
	wela = 1;
	P0 = 0xfd;//1111 1101
	wela = 0;
	P0=0xff;
	dula = 1;
	P0 = 0x5b;
	dula = 0;
	Delayms(1);
	P0=0xff;
//3
	wela = 1;
	P0 = 0xfb;//1111 1011
	wela = 0;
	P0=0xff;
	dula = 1;
	P0 = 0x4f;
	dula = 0;
	Delayms(1);
	P0=0xff;
//4
	wela = 1;
	P0 = 0xf7;//1111 0111
	wela = 0;
	P0=0xff;
	dula = 1;
	P0 = 0x66;
	dula = 0;
	Delayms(1);
	P0=0xff;
//5
	wela = 1;
	P0 = 0xef;//1110 1111
	wela = 0;
	P0=0xff;
	dula = 1;
	P0 = 0x6d;
	dula = 0;
	Delayms(1);
	P0=0xff;
//6
	wela = 1;
	P0 = 0xdf;//1101 1111
	wela = 0;
	P0=0xff;
	dula = 1;
	P0 = 0x7d;
	dula = 0;
	P0=0xff;
	Delayms(1);
}
}

注:

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值