IT数码 购物 网址 头条 软件 日历 阅读 图书馆
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
图片批量下载器
↓批量下载图片,美女图库↓
图片自动播放器
↓图片自动播放器↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁
 
   -> 嵌入式 -> 五脚18.8数码管显示 -> 正文阅读

[嵌入式]五脚18.8数码管显示

五脚18.8数码管显示

今天抽空用将五脚的18.8数码管驱动程序研究了一下,将其过程记录如下:
数码管段位图

电路图
数字1到5表示对应的数码管引脚,利用二极管的单向导通性来点亮单独的LED
脚位分配及段位对应图
STC8单片机脚位配置图

数码管需要亮灯的高低电平点亮,不亮灯的IO口一定要设为高阻。

例如:点亮B3段,数码管2脚(单片机P3.3设置为推挽输出模式)高电平;数码管1脚(单片机P3.2设置为准双向口模式)低电平;在将P3.2设置为低电平输出就可以点亮B3段了;
点亮B3段时的脚位配置
自己总结:
高电平推挽输出模式;
低电平准双向口模式;
其余不亮的设置高阻输入模式;

用笨办法,一段一段点亮``,

以下是测试段位的测试程序:

# include <STC8G.H>
//3位6脚的,原理差不多,用笨办法,一段一段点亮,用switch,组成段码,小数点,STC8G1K08,接的P32-P36
/************************************************************************************/
#define DELAY		1 	//设置每一个点显示的时间长度(1~20)
#define uchar unsigned char
#define uint unsigned int

void delay (uint a)//延时
	{ 
    uint i;
	  while( a-- != 0)
    { 
		for(i = 0; i < DELAY; i++); 
	  }   				   
}

/****测试段码函数*****/
void DG1()
{     
	P3M1 = 0xCF;  P3M0 = 0x10;  P3 = 0xDF;   delay(x);    //1B
	P3M1 = 0xD7;  P3M0 = 0x08;  P3 = 0xDF;   delay(x);    //1C 
	
	P3M1 = 0xE7;  P3M0 = 0x08;  P3 = 0xEF;   delay(x);    //2A
	P3M1 = 0xE7;  P3M0 = 0x10;  P3 = 0xF7;   delay(x);    //2B
	P3M1 = 0xCF;  P3M0 = 0x20;  P3 = 0xEF;   delay(x);    //2C
	P3M1 = 0xD7;  P3M0 = 0x20;  P3 = 0xF7;   delay(x);    //2D
	P3M1 = 0xB7;  P3M0 = 0x40;  P3 = 0xF7;   delay(x);    //2E
	P3M1 = 0xAF;  P3M0 = 0x40;  P3 = 0xEF;   delay(x);    //2F 
	P3M1 = 0x9F;  P3M0 = 0x40;  P3 = 0xDF;   delay(x);    //2G  	

	P3M1 = 0xF3;  P3M0 = 0x04;  P3 = 0xE7;   delay(x);    //3A
	P3M1 = 0xF3;  P3M0 = 0x08;  P3 = 0xFB;   delay(x);    //3B
	P3M1 = 0xEB;  P3M0 = 0x04;  P3 = 0xEF;   delay(x);    //3C
	P3M1 = 0xEB;  P3M0 = 0x10;  P3 = 0xFB;   delay(x);    //3D
	P3M1 = 0xDB;  P3M0 = 0x04;  P3 = 0xDF;   delay(x);    //3E 
	P3M1 = 0xDB;  P3M0 = 0x20;  P3 = 0xFB;   delay(x);    //3F
	P3M1 = 0xBB;  P3M0 = 0x40;  P3 = 0xFB;   delay(x);    //3G

	P3M1 = 0xAF;  P3M0 = 0x10;  P3 = 0xBF;   delay(x);    //I
	P3M1 = 0xB7;  P3M0 = 0x08;  P3 = 0xBF;   delay(x);    //J
	P3M1 = 0x9F;  P3M0 = 0x20;  P3 = 0xBF;   delay(x);    //H
	P3M1 = 0xBB;  P3M0 = 0x04;  P3 = 0xBF;   delay(x);    //DP

}

void main (void){ //主程序 
  init();
	while (1)
    {
		DG1(); //测试代码
	}
}

下面是将其用switch,组成段码,小数点;
从18.8倒减,

# include <STC8G.H>
单片机STC8G1K08,PIN1-PIN5接的P32-P36
/************************************************************************************/
#define DELAY		1 	//设置每一个点显示的时间长度(1~20)
#define uchar unsigned char
#define uint unsigned int
uint TIME_SS=188;
uint C=0; 
uint x=100;

void delay (uint a)//延时
	{ 
    uint i;
	  while( a-- != 0)
    { 
		for(i = 0; i < DELAY; i++); 
	  }   				   
}
/************************************************************************************/
void init (void){ //上电初始化
  	TMOD = 0x01;         // 定时/计数器0,1工作于方式1   
    TH0 = 0xcd;          // 预置产生50ms时基信号   
    TL0 = 0xd4;   
    EA  = 1;             // 开总中断   
    ET0 = 1;             // 定时/计数器0允许中断   
    TR0 = 1;             // 开闭定时/计数器0   
}

/**第一位显示,只显示1**/

void DG1(int a)
{
	P3M1 = 0xCF;  P3M0 = 0x10;  P3 = 0xDF;   delay(x);    //1B
	P3M1 = 0xD7;  P3M0 = 0x08;  P3 = 0xDF;   delay(x);    //1C	
}

/**第二位显示含小数点,只显示0.-9.**/

void DG2(int a)
{
	 switch(a)
	 {  
	 	case 0:{P3M1 = 0xE7;  P3M0 = 0x08;  P3 = 0xEF;   delay(x);    //2A   //0.
	            P3M1 = 0xE7;  P3M0 = 0x10;  P3 = 0xF7;   delay(x);    //2B
	            P3M1 = 0xCF;  P3M0 = 0x20;  P3 = 0xEF;   delay(x);    //2C
	            P3M1 = 0xD7;  P3M0 = 0x20;  P3 = 0xF7;   delay(x);    //2D
	            P3M1 = 0xB7;  P3M0 = 0x40;  P3 = 0xF7;   delay(x);    //2E
	            P3M1 = 0xAF;  P3M0 = 0x40;  P3 = 0xEF;   delay(x);    //2F 
                P3M1 = 0xBB;  P3M0 = 0x04;  P3 = 0xBF;   delay(x);    //DP			
							 break;}
		case 1:{P3M1 = 0xE7;  P3M0 = 0x10;  P3 = 0xF7;   delay(x);    //2B   //1.
	            P3M1 = 0xCF;  P3M0 = 0x20;  P3 = 0xEF;   delay(x);    //2C 
                P3M1 = 0xBB;  P3M0 = 0x04;  P3 = 0xBF;   delay(x);    //DP				
							 break;}	
		case 2:{P3M1 = 0xE7;  P3M0 = 0x08;  P3 = 0xEF;   delay(x);    //2A   //2.
	            P3M1 = 0xE7;  P3M0 = 0x10;  P3 = 0xF7;   delay(x);    //2B
	            P3M1 = 0xD7;  P3M0 = 0x20;  P3 = 0xF7;   delay(x);    //2D
	            P3M1 = 0xB7;  P3M0 = 0x40;  P3 = 0xF7;   delay(x);    //2E
	            P3M1 = 0x9F;  P3M0 = 0x40;  P3 = 0xDF;   delay(x);    //2G  
                P3M1 = 0xBB;  P3M0 = 0x04;  P3 = 0xBF;   delay(x);    //DP				
							 break;}		
		case 3:{P3M1 = 0xE7;  P3M0 = 0x08;  P3 = 0xEF;   delay(x);    //2A   //3.
	            P3M1 = 0xE7;  P3M0 = 0x10;  P3 = 0xF7;   delay(x);    //2B
	            P3M1 = 0xCF;  P3M0 = 0x20;  P3 = 0xEF;   delay(x);    //2C
	            P3M1 = 0xD7;  P3M0 = 0x20;  P3 = 0xF7;   delay(x);    //2D
	            P3M1 = 0x9F;  P3M0 = 0x40;  P3 = 0xDF;   delay(x);    //2G 
                P3M1 = 0xBB;  P3M0 = 0x04;  P3 = 0xBF;   delay(x);    //DP				
							 break;}
		case 4:{P3M1 = 0xE7;  P3M0 = 0x10;  P3 = 0xF7;   delay(x);    //2B   //4.
	            P3M1 = 0xCF;  P3M0 = 0x20;  P3 = 0xEF;   delay(x);    //2C
	            P3M1 = 0xAF;  P3M0 = 0x40;  P3 = 0xEF;   delay(x);    //2F 
	            P3M1 = 0x9F;  P3M0 = 0x40;  P3 = 0xDF;   delay(x);    //2G 
                P3M1 = 0xBB;  P3M0 = 0x04;  P3 = 0xBF;   delay(x);    //DP				
							 break;}	
		case 5:{P3M1 = 0xE7;  P3M0 = 0x08;  P3 = 0xEF;   delay(x);    //2A   //5.
	            P3M1 = 0xCF;  P3M0 = 0x20;  P3 = 0xEF;   delay(x);    //2C
	            P3M1 = 0xD7;  P3M0 = 0x20;  P3 = 0xF7;   delay(x);    //2D
	            P3M1 = 0xAF;  P3M0 = 0x40;  P3 = 0xEF;   delay(x);    //2F 
	            P3M1 = 0x9F;  P3M0 = 0x40;  P3 = 0xDF;   delay(x);    //2G
                P3M1 = 0xBB;  P3M0 = 0x04;  P3 = 0xBF;   delay(x);    //DP				
							 break;}	
		case 6:{P3M1 = 0xE7;  P3M0 = 0x08;  P3 = 0xEF;   delay(x);    //2A   //6.
	            P3M1 = 0xCF;  P3M0 = 0x20;  P3 = 0xEF;   delay(x);    //2C
	            P3M1 = 0xD7;  P3M0 = 0x20;  P3 = 0xF7;   delay(x);    //2D
	            P3M1 = 0xB7;  P3M0 = 0x40;  P3 = 0xF7;   delay(x);    //2E
	            P3M1 = 0xAF;  P3M0 = 0x40;  P3 = 0xEF;   delay(x);    //2F 
	            P3M1 = 0x9F;  P3M0 = 0x40;  P3 = 0xDF;   delay(x);    //2G 
                P3M1 = 0xBB;  P3M0 = 0x04;  P3 = 0xBF;   delay(x);    //DP				
							 break;}	
		case 7:{P3M1 = 0xE7;  P3M0 = 0x08;  P3 = 0xEF;   delay(x);    //2A   //7.
	            P3M1 = 0xE7;  P3M0 = 0x10;  P3 = 0xF7;   delay(x);    //2B
	            P3M1 = 0xCF;  P3M0 = 0x20;  P3 = 0xEF;   delay(x);    //2C
			    P3M1 = 0xBB;  P3M0 = 0x04;  P3 = 0xBF;   delay(x);    //DP	
	            	
							 break;}	
		case 8:{P3M1 = 0xE7;  P3M0 = 0x08;  P3 = 0xEF;   delay(x);    //2A  //8.
	            P3M1 = 0xE7;  P3M0 = 0x10;  P3 = 0xF7;   delay(x);    //2B
	            P3M1 = 0xCF;  P3M0 = 0x20;  P3 = 0xEF;   delay(x);    //2C
	            P3M1 = 0xD7;  P3M0 = 0x20;  P3 = 0xF7;   delay(x);    //2D
	            P3M1 = 0xB7;  P3M0 = 0x40;  P3 = 0xF7;   delay(x);    //2E
	            P3M1 = 0xAF;  P3M0 = 0x40;  P3 = 0xEF;   delay(x);    //2F 
	            P3M1 = 0x9F;  P3M0 = 0x40;  P3 = 0xDF;   delay(x);    //2G
                P3M1 = 0xBB;  P3M0 = 0x04;  P3 = 0xBF;   delay(x);    //DP				
							 break;}	
    case 9:{	P3M1 = 0xE7;  P3M0 = 0x08;  P3 = 0xEF;   delay(x);    //2A  //9.
	            P3M1 = 0xE7;  P3M0 = 0x10;  P3 = 0xF7;   delay(x);    //2B
	            P3M1 = 0xCF;  P3M0 = 0x20;  P3 = 0xEF;   delay(x);    //2C
	            P3M1 = 0xD7;  P3M0 = 0x20;  P3 = 0xF7;   delay(x);    //2D
	            P3M1 = 0xAF;  P3M0 = 0x40;  P3 = 0xEF;   delay(x);    //2F 
	            P3M1 = 0x9F;  P3M0 = 0x40;  P3 = 0xDF;   delay(x);    //2G 
                P3M1 = 0xBB;  P3M0 = 0x04;  P3 = 0xBF;   delay(x);    //DP			
							 break;}							 		 				 

	}
}
/**第三位显示,只显示0-9**/

void DG3(int a)
{
	 switch(a)
	 {  
	case 0:{
	P3M1 = 0xF3;  P3M0 = 0x04;  P3 = 0xE7;   delay(x);    //3A   //0
	P3M1 = 0xF3;  P3M0 = 0x08;  P3 = 0xFB;   delay(x);    //3B
	P3M1 = 0xEB;  P3M0 = 0x04;  P3 = 0xEF;   delay(x);    //3C
	P3M1 = 0xEB;  P3M0 = 0x10;  P3 = 0xFB;   delay(x);    //3D
	P3M1 = 0xDB;  P3M0 = 0x04;  P3 = 0xDF;   delay(x);    //3E 
	P3M1 = 0xDB;  P3M0 = 0x20;  P3 = 0xFB;   delay(x);    //3F
	 break;}	
	 	
	case 1:{ 
	P3M1 = 0xF3;  P3M0 = 0x08;  P3 = 0xFB;   delay(x);    //3B  //1
	P3M1 = 0xEB;  P3M0 = 0x04;  P3 = 0xEF;   delay(x);    //3C
	 break;}
	 
	case 2:{
	P3M1 = 0xF3;  P3M0 = 0x04;  P3 = 0xE7;   delay(x);    //3A  //2
	P3M1 = 0xF3;  P3M0 = 0x08;  P3 = 0xFB;   delay(x);    //3B
	P3M1 = 0xEB;  P3M0 = 0x10;  P3 = 0xFB;   delay(x);    //3D
	P3M1 = 0xDB;  P3M0 = 0x04;  P3 = 0xDF;   delay(x);    //3E 
	P3M1 = 0xBB;  P3M0 = 0x40;  P3 = 0xFB;   delay(x);    //3G
	 break;}	
	 
	case 3:{
	P3M1 = 0xF3;  P3M0 = 0x04;  P3 = 0xE7;   delay(x);    //3A  //3
	P3M1 = 0xF3;  P3M0 = 0x08;  P3 = 0xFB;   delay(x);    //3B
	P3M1 = 0xEB;  P3M0 = 0x04;  P3 = 0xEF;   delay(x);    //3C
	P3M1 = 0xEB;  P3M0 = 0x10;  P3 = 0xFB;   delay(x);    //3D  
	P3M1 = 0xBB;  P3M0 = 0x40;  P3 = 0xFB;   delay(x);    //3G
	 break;}	
	 
	 case 4:{ 
	P3M1 = 0xF3;  P3M0 = 0x08;  P3 = 0xFB;   delay(x);    //3B  //4
	P3M1 = 0xEB;  P3M0 = 0x04;  P3 = 0xEF;   delay(x);    //3C 
	P3M1 = 0xDB;  P3M0 = 0x20;  P3 = 0xFB;   delay(x);    //3F
	P3M1 = 0xBB;  P3M0 = 0x40;  P3 = 0xFB;   delay(x);    //3G
	 break;}	
	 
	 case 5:{
	P3M1 = 0xF3;  P3M0 = 0x04;  P3 = 0xE7;   delay(x);    //3A  //5
	P3M1 = 0xEB;  P3M0 = 0x04;  P3 = 0xEF;   delay(x);    //3C
	P3M1 = 0xEB;  P3M0 = 0x10;  P3 = 0xFB;   delay(x);    //3D
	P3M1 = 0xDB;  P3M0 = 0x20;  P3 = 0xFB;   delay(x);    //3F
	P3M1 = 0xBB;  P3M0 = 0x40;  P3 = 0xFB;   delay(x);    //3G
	 break;}	
	 
	 case 6:{
	P3M1 = 0xF3;  P3M0 = 0x04;  P3 = 0xE7;   delay(x);    //3A  //6
	P3M1 = 0xEB;  P3M0 = 0x04;  P3 = 0xEF;   delay(x);    //3C
	P3M1 = 0xEB;  P3M0 = 0x10;  P3 = 0xFB;   delay(x);    //3D
	P3M1 = 0xDB;  P3M0 = 0x04;  P3 = 0xDF;   delay(x);    //3E 
	P3M1 = 0xDB;  P3M0 = 0x20;  P3 = 0xFB;   delay(x);    //3F
	P3M1 = 0xBB;  P3M0 = 0x40;  P3 = 0xFB;   delay(x);    //3G
	 break;}	
	 
	 case 7:{
	P3M1 = 0xF3;  P3M0 = 0x04;  P3 = 0xE7;   delay(x);    //3A  //7
	P3M1 = 0xF3;  P3M0 = 0x08;  P3 = 0xFB;   delay(x);    //3B
	P3M1 = 0xEB;  P3M0 = 0x04;  P3 = 0xEF;   delay(x);    //3C
	 break;}
	 
	 case 8:{
	P3M1 = 0xF3;  P3M0 = 0x04;  P3 = 0xE7;   delay(x);    //3A  //8
	P3M1 = 0xF3;  P3M0 = 0x08;  P3 = 0xFB;   delay(x);    //3B
	P3M1 = 0xEB;  P3M0 = 0x04;  P3 = 0xEF;   delay(x);    //3C
	P3M1 = 0xEB;  P3M0 = 0x10;  P3 = 0xFB;   delay(x);    //3D
	P3M1 = 0xDB;  P3M0 = 0x04;  P3 = 0xDF;   delay(x);    //3E 
	P3M1 = 0xDB;  P3M0 = 0x20;  P3 = 0xFB;   delay(x);    //3F
	P3M1 = 0xBB;  P3M0 = 0x40;  P3 = 0xFB;   delay(x);    //3G
	 break;}
	 
	 case 9:{
	P3M1 = 0xF3;  P3M0 = 0x04;  P3 = 0xE7;   delay(x);    //3A  //9
	P3M1 = 0xF3;  P3M0 = 0x08;  P3 = 0xFB;   delay(x);    //3B
	P3M1 = 0xEB;  P3M0 = 0x04;  P3 = 0xEF;   delay(x);    //3C
	P3M1 = 0xEB;  P3M0 = 0x10;  P3 = 0xFB;   delay(x);    //3D		 
	P3M1 = 0xDB;  P3M0 = 0x20;  P3 = 0xFB;   delay(x);    //3F
	P3M1 = 0xBB;  P3M0 = 0x40;  P3 = 0xFB;   delay(x);    //3G
	 break;}	
	
	}
}


/**第四位显示,点亮H段**/

void DG4()
{
  P3M1 = 0x9F;  P3M0 = 0x20;  P3 = 0xBF;   delay(x);    //H	
}


/**第五位显示,点亮I段**/

void DG5()
{
  P3M1 = 0xAF;  P3M0 = 0x10;  P3 = 0xBF;   delay(x);    //I
}

/**第六位显示,点亮J段**/

void DG6()
{
  P3M1 = 0xB7;  P3M0 = 0x08;  P3 = 0xBF;   delay(x);    //J	
}


void main (void){ //主程序 
  init();
	while (1)
    {
      DG1(TIME_SS/100);
      DG2(TIME_SS%100/10);
      DG3(TIME_SS%100%10); 
	  DG4();
	  DG5();
	  DG6();	
    }
}	
 
/***********************************************************************************/	
void tiem0(void) interrupt 1  // 中断服务程序(产生500ms时基信号)   
  {   C++;                  
    if(C>50){                
        C = 0;              
	   TIME_SS--;              
    if(TIME_SS <0){    
        TIME_SS = 188;          
	  }  
	}       
    TH0 = 0xcd;                
    TL0 = 0xd4;   
}
  嵌入式 最新文章
基于高精度单片机开发红外测温仪方案
89C51单片机与DAC0832
基于51单片机宠物自动投料喂食器控制系统仿
《痞子衡嵌入式半月刊》 第 68 期
多思计组实验实验七 简单模型机实验
CSC7720
启明智显分享| ESP32学习笔记参考--PWM(脉冲
STM32初探
STM32 总结
【STM32】CubeMX例程四---定时器中断(附工
上一篇文章      下一篇文章      查看所有文章
加:2021-07-25 11:50:39  更:2021-07-25 11:51:08 
 
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁

360图书馆 购物 三丰科技 阅读网 日历 万年历 2024年12日历 -2024/12/27 10:40:30-

图片自动播放器
↓图片自动播放器↓
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
图片批量下载器
↓批量下载图片,美女图库↓
  网站联系: qq:121756557 email:121756557@qq.com  IT数码
数据统计