TA的每日心情 | 开心 2019-11-4 13:48 |
---|
签到天数: 14 天 连续签到: 1 天 [LV.3]偶尔看看II
|
工作中经常要用到大量的数码管,点阵,LED
一般都是用74系列的芯片去驱动,因为公司的项目需求找了这颗芯片现在分享驱动和原理图过
- enum Brightness
- {
- Level1 = 0x88,
- Level2,
- Level3,
- Level4,
- Level5,
- Level6,
- Level7,
- Level8,
- LEDOFF = 0x80
- };
- uint8_t NUM[11][5] =
- {
- {0xFF, 0x41, 0x41, 0x41, 0xFF},//0
- {0x00, 0x00, 0x7F, 0x00, 0x00},//1
- {0x79, 0x49, 0x49, 0x49, 0x4F},//2
- {0x49, 0x49, 0x49, 0x49, 0xFF},//3
- {0x0F, 0x08, 0x08, 0x08, 0xFF},//4
- {0x4F, 0x49, 0x49, 0x49, 0x79},//5
- {0xFF, 0x49, 0x49, 0x49, 0x79},//6
- {0x01, 0x01, 0x01, 0x01, 0xFF},//7
- {0xFF, 0x49, 0x49, 0x49, 0xFF},//8
- {0x4F, 0x49, 0x49, 0x49, 0xFF},//9
- {0x00, 0x00, 0x22, 0x00, 0x00},//:
- };
- void TM1640_GPIO_Init(void)
- {
- GPIO_Init(GPIOA, (GPIO_Pin_TypeDef)(GPIO_PIN_1), GPIO_MODE_OUT_PP_HIGH_FAST);
- GPIO_Init(GPIOA, (GPIO_Pin_TypeDef)(GPIO_PIN_2), GPIO_MODE_OUT_PP_HIGH_FAST);
- GPIO_Init(GPIOC, (GPIO_Pin_TypeDef)(T2_Din | T2_Clk), GPIO_MODE_OUT_PP_HIGH_FAST);
- }
- void Delay(uint16_t nCount)
- {
- while (nCount != 0)
- {
- nCount--;
- }
- }
- void TM1640_Start(void)
- {
- GPIO_WriteHigh(GPIOA, T1_Clk);
- Delay(10);
- GPIO_WriteHigh(GPIOA, T1_Din);
- Delay(10);
- GPIO_WriteLow(GPIOA, T1_Din);
- Delay(10);
- GPIO_WriteLow(GPIOA, T1_Clk);
- Delay(10);
- }
- void TM1640_Stop(void)
- {
- GPIO_WriteLow(GPIOA, T1_Clk);
- Delay(10);
- GPIO_WriteLow(GPIOA, T1_Din);
- Delay(10);
- GPIO_WriteHigh(GPIOA, T1_Clk);
- Delay(10);
- GPIO_WriteHigh(GPIOA, T1_Din);
- Delay(10);
- }
- void TM1640_2_Start(void)
- {
- GPIO_WriteHigh(GPIOC, T2_Clk);
- Delay(10);
- GPIO_WriteHigh(GPIOC, T2_Din);
- Delay(10);
- GPIO_WriteLow(GPIOC, T2_Din);
- Delay(10);
- GPIO_WriteLow(GPIOC, T2_Clk);
- Delay(10);
- }
- void TM1640_2_Stop(void)
- {
- GPIO_WriteLow(GPIOC, T2_Clk);
- Delay(10);
- GPIO_WriteLow(GPIOC, T2_Din);
- Delay(10);
- GPIO_WriteHigh(GPIOC, T2_Clk);
- Delay(10);
- GPIO_WriteHigh(GPIOC, T2_Din);
- Delay(10);
- }
- void TM1640_Write_Byte(uint8_t dat)
- {
- uint8_t i;
- for(i = 0; i < 8; i++)
- {
- GPIO_WriteLow(GPIOA, T1_Clk);
- if(dat & 0x01)
- {
- GPIO_WriteHigh(GPIOA, T1_Din);
- }
- else
- {
- GPIO_WriteLow(GPIOA, T1_Din);
- }
- Delay(10);
- GPIO_WriteHigh(GPIOA, T1_Clk);
- Delay(10);
- dat >>= 1;
- }
- GPIO_WriteLow(GPIOA, T1_Clk);
- Delay(10);
- }
- void TM1640_2_Write_Byte(uint8_t dat)
- {
- uint8_t i;
- for(i = 0; i < 8; i++)
- {
- GPIO_WriteLow(GPIOC, T2_Clk);
- if(dat & 0x01)
- {
- GPIO_WriteHigh(GPIOC, T2_Din);
- }
- else
- {
- GPIO_WriteLow(GPIOC, T2_Din);
- }
- Delay(10);
- GPIO_WriteHigh(GPIOC, T2_Clk);
- Delay(10);
- dat >>= 1;
- }
- GPIO_WriteLow(GPIOC, T2_Clk);
- Delay(10);
- }
- void TM1640_Init(void)
- {
- TM1640_GPIO_Init();
- Delay(10);
- TM1640_Start();
- TM1640_Write_Byte(Level8);
- TM1640_Stop();
- TM1640_2_Start();
- TM1640_2_Write_Byte(Level8);
- TM1640_2_Stop();
- }
- void TM1640_Bit1(uint8_t *Dat)
- {
- uint8_t i;
- TM1640_Start();
- TM1640_Write_Byte(0x40);
- TM1640_Stop();
- Delay(10);
- TM1640_Start();
- TM1640_Write_Byte(0xC0);
- for(i = 0; i < 5; i++)
- {
- TM1640_Write_Byte(*(Dat++));
- }
- TM1640_Stop();
- }
- void TM1640_Clear_C5(void)
- {
- TM1640_Start();
- TM1640_Write_Byte(0x44);
- TM1640_Stop();
- Delay(10);
- TM1640_Start();
- TM1640_Write_Byte(0xC5);
- TM1640_Write_Byte(0x00);
- TM1640_Stop();
- TM1640_Start();
- TM1640_Write_Byte(0x44);
- TM1640_Stop();
- Delay(10);
- TM1640_Start();
- TM1640_Write_Byte(0xCD);
- TM1640_Write_Byte(0x00);
- TM1640_Stop();
- TM1640_2_Start();
- TM1640_2_Write_Byte(0xC4);
- TM1640_2_Write_Byte(0x00);
- TM1640_2_Stop();
- }
- void TM1640_ClearAll(void)
- {
- uint8_t i;
- TM1640_Start();
- TM1640_Write_Byte(0x40);
- TM1640_Stop();
- Delay(10);
- TM1640_Start();
- TM1640_Write_Byte(0xC0);
- for(i = 0; i < 16; i++)
- {
- TM1640_Write_Byte(0x00);
- }
- TM1640_Stop();
- TM1640_2_Start();
- TM1640_2_Write_Byte(0x40);
- TM1640_2_Stop();
- Delay(10);
- TM1640_2_Start();
- TM1640_2_Write_Byte(0xC6);
- for(i = 0; i < 16; i++)
- {
- TM1640_2_Write_Byte(0x00);
- }
- TM1640_2_Stop();
- }
- void TM1640_Bit2(uint8_t *Dat)
- {
- uint8_t i;
- TM1640_Start();
- TM1640_Write_Byte(0x40);
- TM1640_Stop();
- Delay(10);
- TM1640_Start();
- TM1640_Write_Byte(0xC6);
- for(i = 0; i < 5; i++)
- {
- TM1640_Write_Byte(*(Dat++));
- }
- TM1640_Stop();
- }
- void TM1640_Bit3(uint8_t En)
- {
- TM1640_Start();
- TM1640_Write_Byte(0x44);
- TM1640_Stop();
- Delay(10);
- TM1640_Start();
- TM1640_Write_Byte(0xCC);
- if(En)
- TM1640_Write_Byte(NUM[10][2]);
- else
- TM1640_Write_Byte(0x00);
- TM1640_Stop();
- }
- void TM1640_2_Bit4(uint8_t *Dat)
- {
- uint8_t i;
- TM1640_Start();
- TM1640_Write_Byte(0x44);
- TM1640_Stop();
- Delay(10);
- TM1640_Start();
- TM1640_Write_Byte(0xCE);
- TM1640_Write_Byte(*(Dat++));
- TM1640_Stop();
- TM1640_2_Start();
- TM1640_2_Write_Byte(0x44);
- TM1640_2_Stop();
- Delay(10);
- TM1640_2_Start();
- TM1640_2_Write_Byte(0xC0);
- for(i = 1; i < 5; i++)
- {
- TM1640_2_Write_Byte(*(Dat++));
- }
- TM1640_2_Stop();
- }
- void TM1640_2_Bit5(uint8_t *Dat)
- {
- uint8_t i;
- TM1640_2_Start();
- TM1640_2_Write_Byte(0x40);
- TM1640_2_Stop();
- Delay(10);
- TM1640_2_Start();
- TM1640_2_Write_Byte(0xC5);
- for(i = 0; i < 5; i++)
- {
- TM1640_2_Write_Byte(*(Dat++));
- }
- TM1640_2_Stop();
- }
[color=rgb(51, 102, 153) !important]复制代码
--------------------------------------------------------------------------------------------
调试器都忘记放啦,做了几十片,大家可以看一下
|
|