单片机/MCU论坛
直播中

jf_00891203

未满1年用户 6经验值
私信 关注
[讨论]

学习笔记

#include <reg52.h>
#define duan P0 //定义数码管的(段选)信号

#define on 0
#define off 1

//定义蜂鸣器
//sbit fm = P2^3;

//定义数码管的(位选)信号
sbit qian = P2^4;
sbit bai = P2^5;
sbit shi = P2^6;
sbit ge = P2^7;

//字符编码
char array [10] ={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};

unsigned int cnt_on = 0;
unsigned int cnt_off = 0;

/延时函数/
void delay(unsigned int xms)
{
int i,j;
for (i = xms;i > 0;i--)
{
for (j = 120; j > 0; j--)
{
//do nothing
}
}
}

void main()
{
//初始化
ge = 0;
shi = 0;
bai = 0;
qian = 0;

//循环函数
while(1)
	{
		//千位
		ge = 0;
		shi = 0;
		bai = 0;
		qian = 1;
		duan = array[6];
		delay(100);

/* fm = on;
delay(50);
fm = off;
delay(50);

方案一
	  	fm = 0;
		delay(100);
		fm = 1;

*/

//百位
		ge = 0;
		shi = 0;
		bai = 1;
		qian = 0;
		duan = array[9];
		delay(100);

// fm = on;
// delay(50);
// fm = off;
// delay(50);

//十位
		ge = 0;
		shi = 1;
		bai = 0;
		qian = 0;
		duan = array[3];
		delay(100);

// fm = on;
// delay(50);
// fm = off;
// delay(50);

//个位
		ge = 1;
		shi = 0;
		bai = 0;
		qian = 0;
		duan = array[0];
		delay(100);

// fm = on;
// delay(50);
// fm = off;
// delay(50);

/*
方案二

if(cnt_on > 100)
		{
			cnt_on = 0;
			fm = 0;
		}
		
		if(cnt_off > 2000)
		{
			cnt_off = 0;
			fm = 1;
		}

*/

}

}

更多回帖

发帖
×
20
完善资料,
赚取积分