当前位置:网站首页>Screen display of charging pile design -- led driver ta6932
Screen display of charging pile design -- led driver ta6932
2022-07-03 09:59:00 【Wukong is so timid】
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include "stm32f10x.h"
#include "stm32f10x_it.h"
#include "ta6932.h"
#define ta6932_mosi_l() (GPIO_ResetBits(GPIOB,GPIO_Pin_5))
#define ta6932_mosi_h() (GPIO_SetBits(GPIOB,GPIO_Pin_5))
#define ta6932_sck_l() (GPIO_ResetBits(GPIOB,GPIO_Pin_3))
#define ta6932_sck_h() (GPIO_SetBits(GPIOB,GPIO_Pin_3))
#define TIME_US 400
#define STB_IO_REVERT 1
#if (STB_IO_REVERT == 1)
#if 1
#define ta6932_cs_l_a() (GPIO_SetBits(GPIOD,GPIO_Pin_4))
#define ta6932_cs_h_a() (GPIO_ResetBits(GPIOD,GPIO_Pin_4))
#define ta6932_cs_l_b() (GPIO_SetBits(GPIOD,GPIO_Pin_3))
#define ta6932_cs_h_b() (GPIO_ResetBits(GPIOD,GPIO_Pin_3))
#else
#define ta6932_cs_l_a() (GPIO_SetBits(GPIOD,GPIO_Pin_3))
#define ta6932_cs_h_a() (GPIO_ResetBits(GPIOD,GPIO_Pin_3))
#define ta6932_cs_l_b() (GPIO_SetBits(GPIOD,GPIO_Pin_4))
#define ta6932_cs_h_b() (GPIO_ResetBits(GPIOD,GPIO_Pin_4))
#endif
#define ta6932_cs_l_c() (GPIO_SetBits(GPIOD,GPIO_Pin_5))
#define ta6932_cs_h_c() (GPIO_ResetBits(GPIOD,GPIO_Pin_5))
#define ta6932_cs_l_d() (GPIO_SetBits(GPIOD,GPIO_Pin_6))
#define ta6932_cs_h_d() (GPIO_ResetBits(GPIOD,GPIO_Pin_6))
#else
#define ta6932_cs_l_a() (GPIO_ResetBits(GPIOD,GPIO_Pin_3))
#define ta6932_cs_h_a() (GPIO_SetBits(GPIOD,GPIO_Pin_3))
#define ta6932_cs_l_b() (GPIO_ResetBits(GPIOD,GPIO_Pin_4))
#define ta6932_cs_h_b() (GPIO_SetBits(GPIOD,GPIO_Pin_4))
#define ta6932_cs_l_c() (GPIO_ResetBits(GPIOD,GPIO_Pin_5))
#define ta6932_cs_h_c() (GPIO_SetBits(GPIOD,GPIO_Pin_5))
#define ta6932_cs_l_d() (GPIO_ResetBits(GPIOD,GPIO_Pin_6))
#define ta6932_cs_h_d() (GPIO_SetBits(GPIOD,GPIO_Pin_6))
#endif
#define delay_us Delay_us
Display_num dis_num = {0};
const unsigned char tab[]= {0x3F,0x06,0x5B,0x4F,0x66,0x6D,0x7D,0x07,0x7F,0x6F,0x77,0x7C,0x39,0x5E,0x79,0x71,0x40,0xef};
u16 ta6932_number[TA6932_LEDCOUNT] = {0};
unsigned char channel_num = TA6932_LEDCOUNT;
void ta6932_channel_num_init(unsigned char num)
{
channel_num = num;
}
void TA6932_Init(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
// u8 i = 0;
// RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB|RCC_APB2Periph_GPIOD, ENABLE);
GPIO_PinRemapConfig(GPIO_Remap_SWJ_JTAGDisable, ENABLE);
//PB3 ÊÇSPI_SCK PB5 ÊÇSPI1_MOSI
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3|GPIO_Pin_5;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_Init(GPIOB, &GPIO_InitStructure);
// GPIO_SetBits(GPIOB, GPIO_Pin_3|GPIO_Pin_5); sck h mosi h
//GPIO_ResetBits(GPIOB, GPIO_Pin_3|GPIO_Pin_5); //sck h mosi l
//PD3456 ÓÃÓÚÆ¬Ñ¡
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3|GPIO_Pin_4|GPIO_Pin_5|GPIO_Pin_6;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_Init(GPIOD, &GPIO_InitStructure);
//GPIO_SetBits(GPIOD, GPIO_Pin_3|GPIO_Pin_4|GPIO_Pin_5|GPIO_Pin_6);
//GPIO_ResetBits(GPIOD, GPIO_Pin_3|GPIO_Pin_4|GPIO_Pin_5|GPIO_Pin_6);
//TEST
ta6932_mosi_h();
ta6932_sck_h();
//ta6932_mosi_l();
//ta6932_sck_l();
ta6932_cs_h_a();
ta6932_cs_h_b();
ta6932_cs_h_c();
ta6932_cs_h_d();
/*
for(i = 0; i < TA6932_LEDCOUNT; i++)
{
ta6932_number[i] = 0;
}
TA6932_DisplayAllNumber(ta6932_number);
*/
}
void TA6932_Write_Byte(unsigned char dat)
{
unsigned char i;
for(i=0; i<8; i++)
{
if(dat&0x01)
{
ta6932_sck_l();
delay_us(TIME_US);
ta6932_mosi_h();
delay_us(TIME_US);
// delay_us(10);
ta6932_sck_h();
delay_us(TIME_US);
// delay_us(10);
}
else
{
ta6932_sck_l();
delay_us(TIME_US);
ta6932_mosi_l();
delay_us(TIME_US);
// delay_us(10);
ta6932_sck_h();
delay_us(TIME_US);
// delay_us(10);
}
dat>>=1;
}
}
/*ÏÔʾÿ¸öta6932µÄled
dat ÊÇÏÔʾµÄÊý¾Ý½á¹¹£¬20¸ö¶Ë¿ÚµÄÊý¾Ý
num ÊÇÆ¬Ñ¡ºÅ
*/
void TA6932_Display_Number(Display_num *dat,u8 stb)
{
u8 i =0;
u8 j =0;
switch(stb)
{
case 1:
ta6932_cs_l_a();
delay_us (TIME_US);
TA6932_Write_Byte(0x40);
ta6932_cs_h_a();
ta6932_sck_h();
delay_us (TIME_US);
ta6932_cs_l_a();
delay_us (TIME_US);
TA6932_Write_Byte(0xC0);
// ta6932_sck_h();
// delay_us (TIME_US);
for(i=0; i<5; i++)
{
for(j=0; j<3; j++)
{
//printf("dat[%d][%d]=0x%x \r\n",i,j,dat->num[i][j]);
TA6932_Write_Byte(dat->num[i][j]);
}
}
ta6932_cs_h_a();
ta6932_sck_h();
delay_us (TIME_US);
ta6932_cs_l_a();
delay_us (TIME_US);
TA6932_Write_Byte(0x8f);
ta6932_cs_h_a();
ta6932_sck_h();
break;
case 2:
ta6932_cs_l_b();
delay_us (TIME_US);
TA6932_Write_Byte(0x40);
ta6932_cs_h_b();
ta6932_sck_h();
delay_us (TIME_US);
ta6932_cs_l_b();
delay_us (TIME_US);
TA6932_Write_Byte(0xC0);
// ta6932_sck_h();
//delay_us (TIME_US);
for(i=0; i<5; i++)
{
for(j=0; j<3; j++)
{
// printf("dat[%d][%d]=0x%x \r\n",i,j,dat->num[i][j]);
TA6932_Write_Byte(dat->num[i+5][j]);
}
}
ta6932_cs_h_b();
ta6932_sck_h();
delay_us (TIME_US);
ta6932_cs_l_b();
delay_us (TIME_US);
TA6932_Write_Byte(0x8f);
ta6932_cs_h_b();
ta6932_sck_h();
break;
case 3:
ta6932_cs_l_c();
delay_us (TIME_US);
TA6932_Write_Byte(0x40);
ta6932_cs_h_c();
ta6932_sck_h();
delay_us (TIME_US);
ta6932_cs_l_c();
delay_us (TIME_US);
TA6932_Write_Byte(0xC0);
for(i=0; i<5; i++)
{
for(j=0; j<3; j++)
{
TA6932_Write_Byte(dat->num[i+10][j]);
}
}
ta6932_cs_h_c();
ta6932_sck_h();
delay_us (TIME_US);
ta6932_cs_l_c();
delay_us (TIME_US);
TA6932_Write_Byte(0x8f);
ta6932_cs_h_c();
ta6932_sck_h();
break;
case 4:
ta6932_cs_l_d();
delay_us (TIME_US);
TA6932_Write_Byte(0x40);
ta6932_cs_h_d();
ta6932_sck_h();
delay_us (TIME_US);
ta6932_cs_l_d();
delay_us (TIME_US);
TA6932_Write_Byte(0xC0);
for(i=0; i<5; i++)
{
for(j=0; j<3; j++)
{
TA6932_Write_Byte(dat->num[i+15][j]);
}
}
ta6932_cs_h_d();
ta6932_sck_h();
delay_us (TIME_US);
ta6932_cs_l_d();
delay_us (TIME_US);
TA6932_Write_Byte(0x8f);
ta6932_cs_h_d();
ta6932_sck_h();
break ;
default :
break;
}
}
/*ÏÔʾËùÓÐ20¸ö¶Ë¿ÚµÄÊý×Ö£¬numberÊÇÒ»¸öu16 number[20]µÄÊý×é */
void TA6932_DisplayAllNumber(u16 *number)
{
u16 num = 0;
u16 temp = 0;
u8 i = 0;
if(number == NULL)
{
return ;
}
memcpy(ta6932_number,number,sizeof(ta6932_number));
for(i = 0; i < channel_num; i++ )
{
num = ta6932_number[i];
/*°Ù*/
temp = num %1000 / 100;
dis_num.num[i][0] = tab[temp];
/*Ê*/
temp = num %100 / 10;
dis_num.num[i][1] = tab[temp];
/*¸ö*/
temp = num %10;
dis_num.num[i][2] = tab[temp];
}
if(channel_num == 10)
{
TA6932_Display_Number(&dis_num, 1);
TA6932_Display_Number(&dis_num, 2);
}
else if(channel_num == 20)
{
TA6932_Display_Number(&dis_num, 1);
TA6932_Display_Number(&dis_num, 2);
TA6932_Display_Number(&dis_num, 3);
TA6932_Display_Number(&dis_num, 4);
}
}
/*ÏÔʾij¸ö¶Ë¿ÚµÄÊý×Ö£¬
portÊǶ˿ںŠ[1~20]
numberÊÇÏÔʾÊý¾Ý£¬¼´³äµç·ÖÖÓÊý£¬
*/
void TA6932_DisplayPortNumber(u8 port, u16 number)
{
if(port < 1 || port > TA6932_LEDCOUNT)
{
return;
}
port = (port-1)%TA6932_LEDCOUNT;
if(number != ta6932_number[port])
{
ta6932_number[port] = number;
TA6932_DisplayAllNumber(ta6932_number);
}
}
边栏推荐
- STM32 running lantern experiment - library function version
- JS foundation - prototype prototype chain and macro task / micro task / event mechanism
- [successful graduation] [1] - visit [student management information system]
- There is no shortcut to learning and development, and there is almost no situation that you can learn faster by leading the way
- 01仿B站项目业务架构
- You need to use MySQL in the opening experiment. How can you forget the basic select statement? Remedy is coming~
- Open Euler Kernel Technology Sharing - Issue 1 - kdump Basic Principles, use and Case Introduction
- Runtime. getRuntime(). GC () and runtime getRuntime(). The difference between runfinalization()
- MYSQL数据库底层基础专栏
- Successful graduation [2] - student health management system function development...
猜你喜欢
IDEA远程断点调试jar包项目
Of course, the most widely used 8-bit single chip microcomputer is also the single chip microcomputer that beginners are most easy to learn
Gpiof6, 7, 8 configuration
C language enumeration type
[Li Kou brush question notes (II)] special skills, module breakthroughs, classification and summary of 45 classic questions, and refinement in continuous consolidation
Hal library sets STM32 clock
UCI and data multiplexing are transmitted on Pusch (Part 4) --small block lengths
Project cost management__ Topic of comprehensive calculation
SCM is now overwhelming, a wide variety, so that developers are overwhelmed
How does the memory database give full play to the advantages of memory?
随机推荐
单片机学到什么程度能找到工作,这个标准不好量化
The third paper of information system project manager in soft examination
Timer and counter of 51 single chip microcomputer
Introduction to chromium embedded framework (CEF)
嵌入式本来就很坑,相对于互联网来说那个坑多得简直是难走
[CSDN] C1 training problem analysis_ Part II_ Web Foundation
Gpiof6, 7, 8 configuration
Fundamentals of Electronic Technology (III)__ Chapter 6 combinational logic circuit
Project cost management__ Cost management technology__ Article 8 performance review
Exception handling of arm
2.Elment Ui 日期选择器 格式化问题
(2)接口中新增的方法
【男保姆式】教你打开第一个微信小程序
Runtime. getRuntime(). GC () and runtime getRuntime(). The difference between runfinalization()
For new students, if you have no contact with single-chip microcomputer, it is recommended to get started with 51 single-chip microcomputer
Quelle langue choisir pour programmer un micro - ordinateur à puce unique
01仿B站项目业务架构
03 FastJson 解决循环引用
一个可执行的二进制文件包含的不仅仅是机器指令
Fundamentals of Electronic Technology (III)__ Fundamentals of circuit analysis__ Basic amplifier operating principle