当前位置:网站首页>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);
}
}
边栏推荐
- An executable binary file contains more than machine instructions
- openEuler kernel 技術分享 - 第1期 - kdump 基本原理、使用及案例介紹
- Notes on C language learning of migrant workers majoring in electronic information engineering
- Comment la base de données mémoire joue - t - elle l'avantage de la mémoire?
- Runtime.getRuntime().gc() 和 Runtime.getRuntime().runFinalization() 的区别
- Exception handling of arm
- Design of charging pile mqtt transplantation based on 4G EC20 module
- Programming ideas are more important than anything, not more than who can use several functions, but more than the understanding of the program
- Serial port programming
- 【顺利毕业】[1]-游览 [学生管理信息系统]
猜你喜欢
You need to use MySQL in the opening experiment. How can you forget the basic select statement? Remedy is coming~
I think all friends should know that the basic law of learning is: from easy to difficult
Stm32-hal library learning, using cubemx to generate program framework
应用最广泛的8位单片机当然也是初学者们最容易上手学习的单片机
[male nanny style] teach you to open the first wechat applet
我想各位朋友都应该知道学习的基本规律就是:从易到难
PRACH --- originator
[successful graduation] [1] - visit [student management information system]
[CSDN] C1 training problem analysis_ Part II_ Web Foundation
手机都算是单片机的一种,只不过它用的硬件不是51的芯片
随机推荐
uniapp 实现微信小程序全局分享及自定义分享按钮样式
Timer and counter of 51 single chip microcomputer
C language enumeration type
Serial communication based on 51 single chip microcomputer
Liquid crystal display
自動裝箱與拆箱了解嗎?原理是什麼?
Basic knowledge of MySQL database (an introduction to systematization)
Application of 51 single chip microcomputer timer
MySQL的简单使用(增删改查)
03 FastJson 解决循环引用
【力扣刷题笔记(二)】特别技巧,模块突破,45道经典题目分类总结,在不断巩固中精进
2020-08-23
Drive and control program of Dianchuan charging board for charging pile design
byte alignment
How does the memory database give full play to the advantages of memory?
Stm32-hal library learning, using cubemx to generate program framework
STM32 general timer output PWM control steering gear
2020-08-23
Programming ideas are more important than anything, not more than who can use several functions, but more than the understanding of the program
Project cost management__ Cost management technology__ Article 6 prediction