⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ledlib.c

📁 一个数字温度计源代码 MCU是AT89S52 温度传感器是DS18B20 温度测量范围-30 - 100 精度0.5度
💻 C
字号:
#include "Ledlib.h"



//=================[ledShowDigit]==============
//Description:this mathod is used to set a digit to a specified bit on the led
//Author:Decelll.Zhou
//Version
//arg: 	digit |  unsigned char |  the digit you want to show | 0-9
//		position | unsigned char | the position of the digit | 0-3
//		dp  |  unsigned  char |  if you want to show the dp, set this argument to 1
//return; 	0 | method terminated normally
//			1 | method meet critical error
//=============================================
int ledSetDigit(unsigned char digit,unsigned char position, unsigned char dp){
	
	//the Led Code table for the digit
	//0:0011 1111;0x3f
	//1:0000 0110;0x06
	//2;0101 1011:0x5b
	//3:0100 1111:0x4f
	//4;0110 0110;0x66
	//5:0110 1101:0x6d
	//6;0111 1101:0x7d
	//7:0000 0111:0x07
	//8:0111 1111:0x7f
	//9:0110 0111:0x67
	//10:0100 0000:0x40:the minius sign for a value
	unsigned char digCode[11] = {0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x67,0x40};

	//check the digit to see if it is valid
	if(digit > 9 || digit < 0){
		return 1;
	}

	//set the pin Lev. of P0 accroding to the value of digit
	P0 = digCode[digit];

	//set the dp as the argument told us
	if(dp == 1){
	P0 |= 0x80;
	}

	//check the value of the position to see whether it is valid
	if(position > 3){// we only have 4 bits Led, that is bit0-bit3
		return 1;
	}
	//set the bit of P2 to low Lev. accroding to the value of position
	P2 &= ~(0xf);//clear bit0-bit3
	P2 |= ~((0x1 << position) & 0xf);
	
	return 0;
	

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -