MCU:STM32F103C8
点阵屏:32*64 F3.75 单元板 红绿双色 显示
接口:标准HUB08 OE :高电平有效 ,138译码 , 1/16 扫
废话不多说,直接贴代码
整个keil工程下载 https://download.csdn.net/download/qq_20490553/12918735
- #ifndef _LED_H
- #define _LED_H
- /* 包含的头文件 --------------------------------------------------------------*/
- #include "stm32f10x.h"
- /* 宏定义 --------------------------------------------------------------------*/
- #define HUB08_LA GPIO_Pin_7
- #define HUB08_LB GPIO_Pin_8
- #define HUB08_LC GPIO_Pin_9
- #define HUB08_LD GPIO_Pin_10
- #define HUB08_G1 GPIO_Pin_11
- #define HUB08_G2 GPIO_Pin_12
- #define HUB08_LT GPIO_Pin_13
- #define HUB08_SK GPIO_Pin_14
- #define HUB08_EN GPIO_Pin_15
- #define HUB08_R1 GPIO_Pin_8
- #define HUB08_R2 GPIO_Pin_9
- #define HUB08_GPIO_PORT GPIOB
- #define HUB08_GPIO_CLK RCC_APB2Periph_GPIOB
- #define HUB08_GPIO_PORTA GPIOA
- #define HUB08_GPIO_CLKA RCC_APB2Periph_GPIOA
- #define HUB08_LA_1 GPIO_SetBits(HUB08_GPIO_PORT, HUB08_LA)
- #define HUB08_LA_0 GPIO_ResetBits(HUB08_GPIO_PORT, HUB08_LA)
- #define HUB08_LB_1 GPIO_SetBits(HUB08_GPIO_PORT, HUB08_LB)
- #define HUB08_LB_0 GPIO_ResetBits(HUB08_GPIO_PORT, HUB08_LB)
- #define HUB08_LC_1 GPIO_SetBits(HUB08_GPIO_PORT, HUB08_LC)
- #define HUB08_LC_0 GPIO_ResetBits(HUB08_GPIO_PORT, HUB08_LC)
- #define HUB08_LD_1 GPIO_SetBits(HUB08_GPIO_PORT, HUB08_LD)
- #define HUB08_LD_0 GPIO_ResetBits(HUB08_GPIO_PORT, HUB08_LD)
- #define HUB08_G1_1 GPIO_SetBits(HUB08_GPIO_PORT, HUB08_G1)
- #define HUB08_G1_0 GPIO_ResetBits(HUB08_GPIO_PORT, HUB08_G1)
- #define HUB08_G2_1 GPIO_SetBits(HUB08_GPIO_PORT, HUB08_G2)
- #define HUB08_G2_0 GPIO_ResetBits(HUB08_GPIO_PORT, HUB08_G2)
- #define HUB08_R1_1 GPIO_SetBits(HUB08_GPIO_PORTA, HUB08_R1)
- #define HUB08_R1_0 GPIO_ResetBits(HUB08_GPIO_PORTA, HUB08_R1)
- #define HUB08_R2_1 GPIO_SetBits(HUB08_GPIO_PORTA, HUB08_R2)
- #define HUB08_R2_0 GPIO_ResetBits(HUB08_GPIO_PORTA, HUB08_R2)
- #define HUB08_EN_1 GPIO_SetBits(HUB08_GPIO_PORT, HUB08_EN)
- #define HUB08_EN_0 GPIO_ResetBits(HUB08_GPIO_PORT, HUB08_EN)
- #define HUB08_LT_1 GPIO_SetBits(HUB08_GPIO_PORT, HUB08_LT)
- #define HUB08_LT_0 GPIO_ResetBits(HUB08_GPIO_PORT, HUB08_LT)
- #define HUB08_SK_1 GPIO_SetBits(HUB08_GPIO_PORT, HUB08_SK)
- #define HUB08_SK_0 GPIO_ResetBits(HUB08_GPIO_PORT, HUB08_SK)
- void LED_Show_Update(void) ;
- void write_595(uint8_t DR1,uint8_t DG1,uint8_t DR2,uint8_t DG2);
- void HUB08_GPIO_Init(void);
- #endif /* _LED_H */
- #include "bsp.h"
- uint8_t disp_table[][48]=
- {
- {0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xEF,0xFF,0x0F,0xFC,0x0F,0xFC,0x1F,0xFE,0x3F,0xFF,0xFF,0xFF,0x27,0xFF,0x03,0xFC,0x1F,0xF8,0x3F,0xFB,0x3F},
- {0xFF,0x3F,0xFE,0x1F,0xFE,0xDF,0xFE,0xEF,0xFC,0xE7,0xFD,0xF3,0xFB,0xF0,0xE3,0xF0,0xF7,0xF8,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF},/*"天",0*/
- {0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFB,0xFF,0xF3,0xFF,0x37,0xFF,0x6F,0xFF,0x63,0xF7,0xC1,0xE7,0x1F,0xF4,0x1F,0xFF,0xA7,0xFF,0x87,0xFF,0x37,0xE7,0x17,0xF7,0x17},
- {0xF7,0x77,0xF7,0x17,0xF7,0x77,0xF7,0x57,0xFB,0x17,0xFB,0x67,0xF1,0xF7,0xC0,0x7F,0xFF,0x9F,0xFF,0xE0,0xFF,0xF0,0xFF,0xF0,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF},/*"道",1*/
- {0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xF3,0xFF,0xF3,0xFF,0xF7,0xFB,0x77,0xC1,0x77,0x83,0x57,0x87,0x57,0xB7,0x57,0xC3,0x57,0x83,0x57,0xAA,0x07},
- {0xA9,0x17,0xA1,0x57,0xA3,0x57,0xB2,0xD7,0xBA,0xD7,0x8A,0xD7,0xBA,0xD7,0xA8,0xF7,0x88,0xF7,0xB1,0xF7,0xFB,0xF7,0xFF,0xF7,0xFF,0xF3,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF},/*"酬",2*/
- {0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFC,0xFF,0xFC,0xFF,0xED,0xFF,0xED,0xFF,0xEC,0xFF,0xE0,0xFF,0xC9,0xFF,0xC3,0xEF,0xE3,0xEF,0xF7,0xEF,0xF0,0xC7,0xE4,0x03,0xD4,0x49},
- {0xD1,0xC9,0xC1,0xDB,0xE1,0xDB,0xF1,0x9B,0xE1,0xBB,0xF1,0xB3,0xE3,0x33,0xF1,0x77,0xF2,0x37,0xE6,0xC7,0x8F,0xC7,0xFF,0xEF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF},/*"勤",3*/
- };
- /************************************************
- 函数名称 : HUB08_GPIO_Init
- 功 能 : LED端口初始化
- 参 数 : 无
- 返 回 值 : 无
- 作 者 : LXP
- *************************************************/
- void HUB08_GPIO_Init(void)
- {
- GPIO_InitTypeDef GPIO_InitStructure;
- /* 使能RCC */
- RCC_APB2PeriphClockCmd(HUB08_GPIO_CLK|HUB08_GPIO_CLKA , ENABLE);
- GPIO_InitStructure.GPIO_Pin = HUB08_LA|HUB08_LB|HUB08_LC|HUB08_LD|HUB08_G1|HUB08_G2|HUB08_LT|HUB08_SK|HUB08_EN;
- GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
- GPIO_Init(HUB08_GPIO_PORT, &GPIO_InitStructure);
- GPIO_InitStructure.GPIO_Pin = HUB08_R1|HUB08_R2;
- GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
- GPIO_Init(HUB08_GPIO_PORTA, &GPIO_InitStructure);
- HUB08_EN_0;
- HUB08_G1_0;
- HUB08_G2_0;
- HUB08_R1_0;
- HUB08_R2_0;
- }
- /*****************************************************
- 函数名称:void write_595()
- 功能说明:给595写数据
- 参数: DR1、DG1-上半屏 DR2、DG2-下半屏
- 返回值: 无
- ****************************************************/
- void write_595(uint8_t DR1,uint8_t DG1,uint8_t DR2,uint8_t DG2)
- {
- uint8_t i;
- for(i=0;i<8;i++)
- {
- if(DR1&0x80) HUB08_R1_1;
- else HUB08_R1_0;
- if(DR2&0x80) HUB08_R2_1;
- else HUB08_R2_0;
- if(DG1&0x80) HUB08_G1_1;
- else HUB08_G1_0;
- if(DG2&0x80) HUB08_G2_1;
- else HUB08_G2_0;
- HUB08_SK_0;
- HUB08_SK_1;
- DR1<<=1;
- DR2<<=1;
- DG1<<=1;
- DG2<<=1;
- }
- }
- /*****************************************************
- 函数名称:void LED_Show_Update(void)
- 功能说明:LED 刷新显示
- 参数: DR1、DG1-上半屏 DR2、DG2-下半屏
- 返回值: 无
- ****************************************************/
- void LED_Show_Update(void)
- {
- uint8_t num = 0;
- uint8_t temp = 0;
- uint8_t number = 2;
- for(num=0;num<16;num++)
- {
- temp=0;
- write_595(0xff,disp_table[0+temp][num*number+0],disp_table[1+temp][num*number+0],0xff);
- write_595(0xff,disp_table[0+temp][num*number+1],disp_table[1+temp][num*number+1],0xff);
- write_595(0xff,disp_table[2+temp][num*number+0],disp_table[3+temp][num*number+0],0xff);
- write_595(0xff,disp_table[2+temp][num*number+1],disp_table[3+temp][num*number+1],0xff);
- write_595(disp_table[4+temp][num*number+0],disp_table[4+temp][num*number+0],0xff,disp_table[5+temp][num*number+0]);
- write_595(disp_table[4+temp][num*number+1],disp_table[4+temp][num*number+1],0xff,disp_table[5+temp][num*number+1]);
- write_595(disp_table[6+temp][num*number+0],disp_table[6+temp][num*number+0],0xff,disp_table[7+temp][num*number+0]);
- write_595(disp_table[6+temp][num*number+1],disp_table[6+temp][num*number+1],0xff,disp_table[7+temp][num*number+1]);
- GPIOB->ODR = GPIOB->ODR & 0xF87F;
- GPIOB->ODR |= (num<<7) ;
- HUB08_LT_1;
- HUB08_LT_0;
- HUB08_EN_0;
- delay_us(100);//调节亮度
- HUB08_EN_1;
- }
- }
- 完事后,直接在main.c 调用 LED_Show_Update();即可
- int main(void)
- {
- SysInit();
- delay_init();
- while(1)
- {
- LED_Show_Update();
- }
- }
复制代码
来个效果图,及单元板照片
|