硬件
display.c程序
#include "display.h"
unsigned char Tab[] = {0xc0,0xF9,0xa4,0xb0,0x99,0x92,0x82, 0xf8,0x80,
0x90, 0x88,0x83,0xc6,0xa1,0x86,0x8e,0x8c,0xc1,0x91,0xC7,0xff,0x7f,0x00};
//0 1 2 3 4 5 6 7 8 9 A b C d F P U y L 灭 . 亮// 共阳数码管 20220804liu矫正
unsigned char Tab3[] = {0xc0,0xcf,0xa4,0xb0,0x99,0x92,0x82, 0xf8,0x80,
0x90, 0x88,0x83,0xc6,0xa1,0x86,0x8e,0x8c,0xE3,0x91,0x7c,0xff,0x7f,0x00};
//0 1 2 3 4 5 6 7 8 9 A B C D F P u Y L 灭 . 亮// 共阳数码管,与Tab[]仅修改了u;
unsigned char Tab2[] = {0x40,0x79,0x24,0x30,0x19,0x12,0x02,0x78,0x00,0x10,0x08,0x03,0x46,0x21,0x06,0x0e};
//带小数点0~F //共阳数码管
unsigned char Tab7[] = {0xA3,0x8E,0xFF,0xC0}; // 共阳极数码管 o,F,不显示
void delay10ms(uint16_t temp)
{
uint16_t i,t;
t=temp;
while(t!=0)
{
for(i=200;i>0;i--)
;
t--;
}
}
void Display_Init(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOB, ENABLE);//使能GPIOF时钟
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_12 | GPIO_Pin_13| GPIO_Pin_14;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;//普通输出模式
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;//推挽输出
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;//100MHz
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;//上拉
GPIO_Init(GPIOB, &GPIO_InitStructure);//初始化
GPIO_ResetBits(GPIOB,GPIO_Pin_12 | GPIO_Pin_13| GPIO_Pin_14);//GPIOF9,F10设置高,灯灭
}
void Spi_Display(unsigned char value)
{
unsigned char i;
for(i = 0; i < 8; i++)
{
GPIO_ResetBits(GPIOB, GPIO_Pin_13);
delay_us(1);
if(0x80 & value)
GPIO_SetBits(GPIOB, GPIO_Pin_14);
else
GPIO_ResetBits(GPIOB, GPIO_Pin_14);
value<<= 1;
delay_us(1);
GPIO_SetBits(GPIOB, GPIO_Pin_13);
delay_us(1);
}
GPIO_ResetBits(GPIOB, GPIO_Pin_13);
GPIO_ResetBits(GPIOB, GPIO_Pin_14);
}
void Load(void)
{
GPIO_SetBits(GPIOB, GPIO_Pin_12);
delay_us(1);
GPIO_ResetBits(GPIOB, GPIO_Pin_12);
}
main函数中的初始化及自检程序
Display_Init();
Spi_Display(Tab[22]); //全亮
Spi_Display(Tab[22]);
Spi_Display(Tab[22]);
Spi_Display(Tab[22]);
Load();
Spi_Display(Tab[22]); //全亮
Spi_Display(Tab[22]);
Spi_Display(Tab[22]);
Spi_Display(Tab[22]);
Load();
delay_ms(2000);
//数码管显示OFF
Spi_Display(Tab7[1]);
Spi_Display(Tab7[1]);
Spi_Display(Tab7[3]);
Spi_Display(Tab7[2]);
Load();
Spi_Display(Tab7[1]);
Spi_Display(Tab7[1]);
Spi_Display(Tab7[3]);
Spi_Display(Tab7[2]);
Load();
主循环中的刷新程序
void can_display(void)
{
if(CAN_RX_FINISH == 1)
{
CAN_RX_FINISH = 0;
AC_V = RX_BUF[0][3] + (RX_BUF[0][2] << 8);
if(AC_V < 500)
{
Spi_Display(Tab7[1]); //第一位不显示 + OFF;
Spi_Display(Tab7[1]);
Spi_Display(Tab7[3]);
Spi_Display(Tab7[2]);
Spi_Display(Tab7[1]);
Spi_Display(Tab7[1]);
Spi_Display(Tab7[3]);
Spi_Display(Tab7[2]);
Load();
}
else
{
DC_V = RX_BUF[2][3] + (RX_BUF[2][2] << 8);
Spi_Display(Tab7[2]);
Spi_Display(Tab7[2]);
Spi_Display(Tab7[2]);
Spi_Display(Tab7[2]);
// Load();
Spi_Display(Tab7[2]);
Spi_Display(Tab7[2]);
Spi_Display(Tab7[2]);
Spi_Display(Tab7[2]);
Load();
Spi_Display(Tab[AC_V/10%10]);
Spi_Display(Tab[AC_V/100%10]);
Spi_Display(Tab[AC_V/1000%10]);
Spi_Display(Tab[17]);
// Load();
Spi_Display(Tab[DC_V%10]);
Spi_Display(Tab2[DC_V/10%10]);
Spi_Display(Tab[DC_V/100%10]);
Spi_Display(Tab3[17]);
Load();
if((DC_V >490)&& (DC_V< 500)) // 2022年11月1日修改为下main的条件;
// if(DC_V< 500)
{
DC_V_OK = 1;
}
else
{
DC_V_OK = 0;
}
}
}
}