单片机数码管程序

  1. 主程序
cpp 复制代码
#include <reg51.h>
#include "showNumber.h"

void Delay(unsigned int n)
{
	while (--n);
}

int main(void)
{
	NumberInit();
	while (1)
	{	
		showNumber(6666);	
	}
}
  1. 源文件
cpp 复制代码
#include <reg51.h>
#include "showNumber.h"


void NumberInit(void)
{
	P0 = 0;
}

void showNumber(int n)
{
	const unsigned char a[10] = {0x3f, 0x06, 0x5b, 0x4f, 0x66, 0x6d, 0x7d, 0x07, 0x7f, 0x6f}; 
	int i = 0;

	for (i = 0; i < 4; ++i)
	{
		P1 = 0;;
		P1 |= (1 << i);
		P0 = a[n % 10];
		n /= 10;	
	}	
}
  1. 头文件
cpp 复制代码
#ifndef _SHOWNUMBER_H_
#define _SHOWNUMBER_H_

extern void NumberInit(void);
extern void showNumber(int n);

#endif
相关推荐
深蓝海拓1 天前
PySide6从0开始学习的笔记(四)QMainWindow
笔记·python·学习·pyqt
深蓝海拓1 天前
PySide6 的 QSettings简单应用学习笔记
python·学习·pyqt
嵌入式学习和实践1 天前
C语言-BCD码转换为十进制的测试和说明
c语言·转换·bcd码
喵了meme1 天前
C语言实战4
c语言·开发语言
码界奇点1 天前
Python从0到100一站式学习路线图与实战指南
开发语言·python·学习·青少年编程·贴图
智者知已应修善业1 天前
【求中位数】2024-1-23
c语言·c++·经验分享·笔记·算法
YJlio1 天前
Active Directory 工具学习笔记(10.8):AdInsight——保存与导出(证据留存、共享与二次分析)
数据库·笔记·学习
BT-BOX1 天前
普中开发板基于51单片机贪吃蛇游戏设计
单片机·游戏·51单片机
驴友花雕1 天前
【花雕动手做】CanMV K230 AI视觉识别模块之使用CanMV IDE调试运行人脸代码
ide·人工智能·单片机·嵌入式硬件·canmv k230 ai视觉·canmv ide 人脸代码
程序员zgh1 天前
Linux系统常用命令集合
linux·运维·服务器·c语言·开发语言·c++