当前位置:网站首页>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);
}
}
边栏推荐
- MySQL 数据库基础知识(系统化一篇入门)
- MySQL的简单使用(增删改查)
- 端午节快乐!—— canvas写的粽子~~~~~
- Interruption system of 51 single chip microcomputer
- STM32 serial port usart1 routine
- 开学实验里要用到mysql,忘记基本的select语句怎么玩啦?补救来啦~
- UCI and data multiplexing are transmitted on Pusch - placement of data and UCI positions (Part III)
- Mysql database underlying foundation column
- The cyclic shift of PUCCH in NR channel is generated by MATLAB
- How does the memory database give full play to the advantages of memory?
猜你喜欢

For new students, if you have no contact with single-chip microcomputer, it is recommended to get started with 51 single-chip microcomputer
![[Li Kou brush question notes (II)] special skills, module breakthroughs, classification and summary of 45 classic questions, and refinement in continuous consolidation](/img/06/7fd985faf8806ceface3864d4b3180.png)
[Li Kou brush question notes (II)] special skills, module breakthroughs, classification and summary of 45 classic questions, and refinement in continuous consolidation

The new series of MCU also continues the two advantages of STM32 product family: low voltage and energy saving

03 FastJson 解决循环引用

How does the nr-prach receiver detect the relationship between prembleid and Ta

我想各位朋友都应该知道学习的基本规律就是:从易到难

Fundamentals of Electronic Technology (III)_ Integrated operational amplifier and its application__ Basic arithmetic circuit

单片机现在可谓是铺天盖地,种类繁多,让开发者们应接不暇

CEF下载,编译工程

STM32 interrupt priority management
随机推荐
The third paper of information system project manager in soft examination
Runtime.getRuntime().gc() 和 Runtime.getRuntime().runFinalization() 的区别
SCM is now overwhelming, a wide variety, so that developers are overwhelmed
Learn the contents of 5g toolbox supporting NR through the NR resources provided by MATLAB
Stm32f407 key interrupt
Idea remote breakpoint debugging jar package project
NR technology -- MIMO
01仿B站项目业务架构
2020-08-23
Raspberry pie installation SciPy
The new series of MCU also continues the two advantages of STM32 product family: low voltage and energy saving
JMX、MBean、MXBean、MBeanServer 入门
Runtime. getRuntime(). GC () and runtime getRuntime(). The difference between runfinalization()
Emballage automatique et déballage compris? Quel est le principe?
Quelle langue choisir pour programmer un micro - ordinateur à puce unique
【顺利毕业】[1]-游览 [学生管理信息系统]
How does the memory database give full play to the advantages of memory?
Nr-prach:prach format and time-frequency domain
没有多少人能够最终把自己的兴趣带到大学毕业上
uniapp 实现微信小程序全局分享及自定义分享按钮样式