[Lanqiao Cup Embedded Expansion Board] Detailed explanation of digital tube (with program source code)

Lanqiao Cup Embedded-Digital Tube Detailed Explanation

From the circuit diagram, the key to controlling the display of the digital tube is to master the working principle of this " SN74LS595N " shift data latch.

1. The internal structure of the chip

Insert picture description here
Assuming that you have a good knowledge of counting electronics, you can see that the internal structure of the chip is a shift register:

  1. SRCLR/ reset port, active low. Generally, it is connected to VCC by default.
  2. Data enters from the SER . Under the trigger of the SRCK clock, the rising edge data is shifted, and the falling edge data is retained. When the data moves 8 times, that is, SRCK has 8 high and low levels toggling. 8bit data has been completely inputted to the shift data register .
  3. After giving RCK a rising edge, the data of the 595 shift data register is all input to the data register for output.
    This is a 595 chip that connects three 595s together for expansion. Three digital control, would be eight, after expansion into 24 bits, SER continuously input data, inverted 24 times and a total of SRCK, 24bit input data to the shift register data . After the rising edge of the RCK, Make the data output to the data register , three-digit digital tube display

Two, schematic diagram

Before the experiment, first connect the corresponding jumpers [A1->SER] , [A2->RCK] , [A3->SCK] and
Insert picture description here
then analyze the corresponding schematic diagram of the digital tube.
Insert picture description here
3. Programming
1. void SEG_GPIO_Config(void)

void SEG_GPIO_Config(void)
{
    
    
	GPIO_InitTypeDef GPIO_InitStruct;
	RCC_APB2PeriphClockCmd(SEG_GPIO_SER_CLK|
						   SEG_GPIO_RCK_CLK|
						   SEG_GPIO_SCK_CLK,ENABLE);
	
	GPIO_InitStruct.GPIO_Mode = GPIO_Mode_Out_PP; 
	GPIO_InitStruct.GPIO_Speed = GPIO_Speed_50MHz;
	
	GPIO_InitStruct.GPIO_Pin = SEG_GPIO_SER_PIN;		//SER
	GPIO_Init(SEG_GPIO_SER_PORT,&GPIO_InitStruct);
	
	GPIO_InitStruct.GPIO_Pin = SEG_GPIO_RCK_PIN;		//RCK
	GPIO_Init(SEG_GPIO_RCK_PORT,&GPIO_InitStruct);
	
	GPIO_InitStruct.GPIO_Pin = SEG_GPIO_SCK_PIN;		//SCK
	GPIO_Init(SEG_GPIO_SCK_PORT,&GPIO_InitStruct);
}

2、void SEG_Display(uint8_t Seg1,uint8_t Seg2,uint8_t Seg3)


uint8_t Seg7[17] = {
    
     0x3f,0x06,0x5b,0x4f, 0x66,0x6d,0x7d,0x07,
					 0x7f,0x6f,0x77,0x7c, 0x39,0x5e,0x79,0x71,0x00}; 
void SEG_Display(uint8_t Seg1,uint8_t Seg2,uint8_t Seg3)
{
    
    
	uint8_t i = 0;
	uint8_t	seg_temp = 0;
	
	seg_temp = Seg7[Seg3]; //从码表读出Seg3对应的码值
	for(i = 0;i<8;i++)
	{
    
    
		SCK_L;		//先拉低,等待SER数据输入
		if(seg_temp&0x80)  //取出最高位
		{
    
    
			SER_H;
		}
		else
		{
    
    
			SER_L;
		}
		SCK_H;		//高电平触发移位
		seg_temp = seg_temp<<1;//左移一位
	}
	seg_temp = Seg7[Seg2];
	for(i = 0;i<8;i++)
	{
    
    
		SCK_L;
		if(seg_temp&0x80)
		{
    
    
			SER_H;
		}
		else
		{
    
    
			SER_L;
		}
		SCK_H;
		seg_temp = seg_temp<<1;
	}
	seg_temp = Seg7[Seg1];
	for(i = 0;i<8;i++)
	{
    
    
		SCK_L;
		if(seg_temp&0x80)
		{
    
    
			SER_H;
		}
		else
		{
    
    
			SER_L;
		}
		SCK_H;
		seg_temp = seg_temp<<1;
	}
	RCK_H;
	RCK_L;
}

3. Header file

#ifndef _BSP_SEG_H
#define _BSP_SEG_H
#include "stm32f10x.h"

#define SEG_GPIO_SER_PORT		GPIOA
#define SEG_GPIO_SER_PIN		GPIO_Pin_1
#define SEG_GPIO_SER_CLK		RCC_APB2Periph_GPIOA

#define SEG_GPIO_RCK_PORT		GPIOA
#define SEG_GPIO_RCK_PIN		GPIO_Pin_2
#define SEG_GPIO_RCK_CLK		RCC_APB2Periph_GPIOA

#define SEG_GPIO_SCK_PORT		GPIOA
#define SEG_GPIO_SCK_PIN		GPIO_Pin_3
#define SEG_GPIO_SCK_CLK		RCC_APB2Periph_GPIOA

#define	SER_H					GPIO_SetBits(SEG_GPIO_SER_PORT,SEG_GPIO_SER_PIN)
#define	SER_L					GPIO_ResetBits(SEG_GPIO_SER_PORT,SEG_GPIO_SER_PIN)

#define	RCK_H					GPIO_SetBits(SEG_GPIO_RCK_PORT,SEG_GPIO_RCK_PIN)
#define	RCK_L					GPIO_ResetBits(SEG_GPIO_RCK_PORT,SEG_GPIO_RCK_PIN)

#define	SCK_H					GPIO_SetBits(SEG_GPIO_SCK_PORT,SEG_GPIO_SCK_PIN)
#define	SCK_L					GPIO_ResetBits(SEG_GPIO_SCK_PORT,SEG_GPIO_SCK_PIN)

void SEG_GPIO_Config(void);
void SEG_Display(uint8_t Seg1,uint8_t Seg2,uint8_t Seg3);

#endif /*_BSP_SEG_H*/

Guess you like

Origin blog.csdn.net/qq_45689790/article/details/114106264