Embedded design and development project - digital tube static display program design
1. Implemented functions
Three-digit digital tube circuit schematic diagram:
pin chip diagram:
pin function diagram:
- ①Realize 3-digit digital tube polling display to display 0~F, and display once every second;
- ② Write the display driver of the digital tube to understand the principle of the display of the digital tube;
- ③Understand the function of changing the serial data of 74LS595 chip into parallel data, and how to drive the digital tube;
2. Realize the code according to the function
1. The main file main.c
#include"key.h"
#include"led.h"
#include"lcd.h"
#include"stdio.h"
#include <stm32f10x.h>
#include"seg.h"
unsigned int uiSeg;
unsigned char ucSec,ucSec1,ucDot;
unsigned long ulTick_ms;
int main(void)
{
SysTick_Config(72000); //定时1ms(HCLK = 72MHz)
KEY_Init();
LED_Init();
STM3210B_LCD_Init();
LCD_Clear(Blue);
LCD_SetBackColor(Blue);
LCD_SetTextColor(White);
SEG_Init();
SEG_Disp(0x10,0x10,0x10,0);
while(1)
{
if(ucSec != ucSec1)
{
ucSec1 = ucSec;
SEG_Disp((uiSeg&0xf00)>>8,(uiSeg&0xf0)>>4,uiSeg&0xf,ucDot++);
uiSeg +=0x111;
if(uiSeg > 0x1000)
uiSeg = 0;
}
}
}
//SysTick 中断处理程序
void SysTick_Handler(void)
{
ulTick_ms++;
if(ulTick_ms % 1000 ==0)
ucSec++;
}
Main function analysis: ❤️ ❤️ ❤️
- Add the initialization function of the digital tube, and turn off the display of the 3-digit digital tube ;
- The 3-digit digital tube displays from 0 to f, displays a number every 1s, and repeats the above actions ;
2. Nixie tube header file "seg.h"
#include "stm32f10x.h"
void SEG_Init(void);
void SEG_Disp(unsigned char ucData1,unsigned char ucData2,
unsigned char ucData3,unsigned char ucDot);
Brief analysis: ❤️ ❤️
- The corresponding pins of 74LS595 are initialized;
- The display function of the 3-digit digital tube;
3. Nixie tube source file "seg.c"
#include "seg.h"
//SEG接口初始化
void SEG_Init(void)
{
GPIO_InitTypeDef GPIO_InitStruct;
//允许GPIOA时钟
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA,ENABLE);
//配置引脚、速率、模式
GPIO_InitStruct.GPIO_Pin = GPIO_Pin_1 | GPIO_Pin_2 | GPIO_Pin_3;
GPIO_InitStruct.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStruct.GPIO_Mode = GPIO_Mode_Out_PP;
//初始化结构体
GPIO_Init(GPIOA,&GPIO_InitStruct);
}
//SEG显示
//入口参数:ucData1,ucData2,UCData3-3个显示数据,ucDot-3个小数点
void SEG_Disp(unsigned char ucData1,unsigned char ucData2,
unsigned char ucData3,unsigned char ucDot)
{
unsigned char i;
unsigned char code[17]={
0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,
0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71,0x00};
unsigned long ulData = (code[ucData3] << 16) + (code[ucData2] << 8)
+ (code[ucData1]);
ulData += (ucDot & 1) << 23;
ulData += (ucDot & 2) << 14;
ulData += (ucDot & 4) << 5;
GPIO_ResetBits(GPIOA,GPIO_Pin_2); //PA2(RCK)输出锁存时钟置低电平
for(i=0;i<24;i++)
{
GPIO_ResetBits(GPIOA,GPIO_Pin_3); //PA3(SCK)移位寄存器时钟置低电平
if(ulData & 0x800000) //从高位开始发送
GPIO_SetBits(GPIOA,GPIO_Pin_1);//PA1(SER)串行数据置高电平
else
GPIO_ResetBits(GPIOA,GPIO_Pin_1);//PA1(SER)串行数据置低电平
ulData <<= 1;
GPIO_SetBits(GPIOA,GPIO_Pin_3); //PA3(SCK)移位寄存器置高电平
}
GPIO_SetBits(GPIOA,GPIO_Pin_2); //PA2(RCK)输出锁存时钟置高电平
}
Brief analysis: ❤️ ❤️
- The 3 pins of 74LS595 corresponding to SER, SRCLK, and RCLK are set to push-pull output mode ;
- The serial data of the 3-digit digital tube is encapsulated into 24 bits , consisting of 3 bytes, and the number of bytes of data corresponds to the number of digital tubes;
- The decimal point is composed of three bytes, and the display method is opposite to that of the digital tube number ;
- Workflow: ① Pull down RCK (latch clock) → ② Poll 24 times, first pull down the SCK shift register clock → ③ Determine whether the highest bit of the 24-bit data is equal to 1, if so, pull up SER (serial data ) high level, otherwise pull down SER (serial data) low level → ④ ulData shifts one bit to the left, pull up the SCK shift register clock, and judge the next bit again → ⑤ After polling ends, pull up RCK ( Latch clock), the data is output.
- The numbers displayed by the digital tube can be found on the Internet for transplantation, and generally display 0 ~ 9 and a ~ F characters;
3. Attention and learning points in the process of realizing functions
1. Precautions
- In the process of converting serial data to parallel data of 74LS595, it must be carried out in order;
- Note that the MCU connected to the 74LS595 pin outputs high and low levels, otherwise the data cannot be displayed normally;
2. Knowledge points learned
- ①Learn the operation of converting serial data to parallel data of the 74LS595 chip to reduce the use of the IO pins of the single-chip microcomputer;
- ② Master the display function of the digital tube;
- ③Learn to encapsulate three separate bytes of data into long variables;
- ④Through circulation and shifting, the data judgment of each bit of data is realized;
❤️ ❤️ ❤️ ❤️ ❤️ ❤️