完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
|
|
相关推荐
1个回答
|
|
开始之前先吐槽一下,搜这个的资料。要么都是Arduino,要么单片机的收费。小小的一个LED单元板,凭什么?
用Arduino是你速度快还是我ST,树莓派不好用?收费更离谱,这点东西还藏私?给你个中指凸。把原理都写出来看你怎么收费。 一、接口定义及原理 如图,有两个RGB通道,共占用6个IO。剩下的ABCDE为地址通道,LAT为行数据锁存通道,CLK为数据时钟,OE为低电平使能LED显示。图片这里没有E,证明它是16扫的,有E就会把B上面的地改为E。这样就是5位,2的5次方32扫。16扫控制16行显示,共2个RGB通道所以16扫可以控制16*2=32行显示。 (1)单元板的显示为单位时间内显示一行数据,然后短时间内切换到另一行显示,16扫一个显示周期为切换16次。 (2)两个RGB通道分别控制上下两部分的RGB灯。图片中的为32*16。正常来说,需要3个地址ABC,假设ABC 3个IO为高电平意味着选定第7行跟第15行,RGB1通道数据被写到第7行,RGB2数据被写到第15行。(我这个板子比较坑,有点不同) (3)数据的写入顺序,失能LED显示,写入一行数据,选定行,锁存,使能LED显示。 (4)颜色渐变,方法是同一行扫描32次,假设R1我只显示一次,那它占空比就是1/32,显示次数越多越来亮。 这方法挺麻烦,但暂时没想到别的方法。 By the way:我这板子比较奇怪,数据写入方式跟一般的板子不一样。具体看图: 数据填充的时候,RBG1通道前8个时钟周期数据在第0行,接下来8个时钟周期数据却跳到第4行去了。然后又跳回第一行。 正常的应该是一直往同一行填充数据才对的。所以我买的这个板子比较奇葩。 二、驱动代码 使用单片机为STM32F407VE,STM32CUBEMX生成代码 #include "main.h" #include "tim.h" #include "gpio.h" void SystemClock_Config(void); #define OE_H HAL_GPIO_WritePin(OE_GPIO_Port,OE_Pin,GPIO_PIN_SET) #define R1_H HAL_GPIO_WritePin(R1_GPIO_Port,R1_Pin,GPIO_PIN_SET) #define R2_H HAL_GPIO_WritePin(R2_GPIO_Port,R2_Pin,GPIO_PIN_SET) #define G1_H HAL_GPIO_WritePin(G1_GPIO_Port,G1_Pin,GPIO_PIN_SET) #define G2_H HAL_GPIO_WritePin(G2_GPIO_Port,G2_Pin,GPIO_PIN_SET) #define B1_H HAL_GPIO_WritePin(B1_GPIO_Port,B1_Pin,GPIO_PIN_SET) #define B2_H HAL_GPIO_WritePin(B2_GPIO_Port,B2_Pin,GPIO_PIN_SET) #define A_H HAL_GPIO_WritePin(A_GPIO_Port,A_Pin,GPIO_PIN_SET) #define B_H HAL_GPIO_WritePin(B_GPIO_Port,B_Pin,GPIO_PIN_SET) #define CLK_H HAL_GPIO_WritePin(CLK_GPIO_Port,CLK_Pin,GPIO_PIN_SET) #define LAT_H HAL_GPIO_WritePin(LAT_GPIO_Port,LAT_Pin,GPIO_PIN_SET) #define OE_L HAL_GPIO_WritePin(OE_GPIO_Port,OE_Pin,GPIO_PIN_RESET) #define R1_L HAL_GPIO_WritePin(R1_GPIO_Port,R1_Pin,GPIO_PIN_RESET) #define R2_L HAL_GPIO_WritePin(R2_GPIO_Port,R2_Pin,GPIO_PIN_RESET) #define G1_L HAL_GPIO_WritePin(G1_GPIO_Port,G1_Pin,GPIO_PIN_RESET) #define G2_L HAL_GPIO_WritePin(G2_GPIO_Port,G2_Pin,GPIO_PIN_RESET) #define B1_L HAL_GPIO_WritePin(B1_GPIO_Port,B1_Pin,GPIO_PIN_RESET) #define B2_L HAL_GPIO_WritePin(B2_GPIO_Port,B2_Pin,GPIO_PIN_RESET) #define A_L HAL_GPIO_WritePin(A_GPIO_Port,A_Pin,GPIO_PIN_RESET) #define B_L HAL_GPIO_WritePin(B_GPIO_Port,B_Pin,GPIO_PIN_RESET) #define CLK_L HAL_GPIO_WritePin(CLK_GPIO_Port,CLK_Pin,GPIO_PIN_RESET) #define LAT_L HAL_GPIO_WritePin(LAT_GPIO_Port,LAT_Pin,GPIO_PIN_RESET) //此单元板4扫一次性输入2行数据,2个通道,故控制2*2*LED_ROW=16行 #define LED_ROW 4 //一行32个点 #define LED_COLUMN 32 typedef struct { uint16_t B:5; uint16_t G:5; uint16_t R:5; uint16_t null:1; }led_data; extern const unsigned char gImage_111[1024]; led_data *img_data = (led_data*)gImage_111; void delay(uint16_t time) { uint16_t i,j; for(i=0;i for(j=0;j<100;j++); } void led_DRamDis(led_data *pdata) { uint16_t col_depth; uint16_t j,k,l; uint16_t row=0; uint16_t pos_down = LED_COLUMN*LED_ROW*2; //指向LED下半部分数据起点 if(pdata == NULL) return; for(row = 0;row { for(col_depth=0;col_depth<32;col_depth++) //每种颜色5bit,32种变化 { OE_H; for(l=0;l<4;l++) //一行4*8像素点数据 { for(k=0;k<2;k++) //发送16像素点数据后,数据被续写 { for(j=0;j<8;j++) //发送8像素点数据后数据会跳转 { if(col_depth else B1_L; if(col_depth else R1_L; if(col_depth else G1_L; if(col_depth else B2_L; if(col_depth else R2_L; if(col_depth else G2_L; CLK_L; CLK_H; } } } //使能一行数据 if(row&0x01) A_H; else A_L; if(row&0x02) B_H; else B_L; LAT_L; LAT_H; OE_L; delay(10); //短暂延时,让当前行数据显示一段时间 } } } led_data img_data2[512]; void RedDis(uint8_t r) { uint16_t i; for(i=0;i<512;i++) { img_data2.R = r; img_data2.G = 0; img_data2.B = 0; } for(i=0;i<5;i++) led_DRamDis(img_data2); } void BlueDis(uint8_t b) { uint16_t i; for(i=0;i<512;i++) { img_data2.R = 0; img_data2.G = 0; img_data2.B = b; } for(i=0;i<5;i++) led_DRamDis(img_data2); } void GreenDis(uint8_t g) { uint16_t i; for(i=0;i<512;i++) { img_data2.R = 0; img_data2.G = g; img_data2.B = 0; } for(i=0;i<5;i++) led_DRamDis(img_data2); } int main(void) { uint16_t i; uint16_t *p; HAL_Init(); SystemClock_Config(); MX_GPIO_Init(); MX_TIM7_Init(); while (1) { for(i=0;i<16;i++) RedDis(i); for(i=0;i<16;i++) BlueDis(i); for(i=0;i<16;i++) GreenDis(i); for(i=0;i<100;i++) led_DRamDis(img_data); } } void SystemClock_Config(void) { RCC_OscInitTypeDef RCC_OscInitStruct = {0}; RCC_ClkInitTypeDef RCC_ClkInitStruct = {0}; /** Configure the main internal regulator output voltage */ __HAL_RCC_PWR_CLK_ENABLE(); __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1); /** Initializes the CPU, AHB and APB busses clocks */ RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE; RCC_OscInitStruct.HSEState = RCC_HSE_ON; RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON; RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE; RCC_OscInitStruct.PLL.PLLM = 8; RCC_OscInitStruct.PLL.PLLN = 336; RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2; RCC_OscInitStruct.PLL.PLLQ = 4; if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK) { Error_Handler(); } /** Initializes the CPU, AHB and APB busses clocks */ RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2; RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK; RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1; RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV4; RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV2; if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_5) != HAL_OK) { Error_Handler(); } } void Error_Handler(void) { } 图像数据数组采用Image2Lcd 2.9生成,搞单片机的人应该对此很熟悉。16位RBG555数据格式 const unsigned char gImage_111[1024] = { /* 0X00,0X10,0X20,0X00,0X10,0X00,0X00,0X1B, */ 0XE9,0X03,0XE9,0X03,0XE9,0X03,0XC9,0X03,0XE9,0X03,0XC9,0X03,0XE9,0X03,0XE9,0X03, 0XE9,0X03,0XE9,0X03,0XE9,0X03,0XE9,0X03,0XE9,0X03,0XE9,0X03,0XE9,0X03,0XE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XC9,0X03,0XE9,0X03,0XE9,0X03,0XE9,0X03,0XE9,0X03, 0XC9,0X03,0XE9,0X03,0XE9,0X03,0XE9,0X03,0XC9,0X03,0XE9,0X03,0XE9,0X03,0XE9,0X03, 0XE9,0X03,0XE9,0X03,0XE9,0X03,0XE9,0X03,0XE9,0X03,0XC9,0X03,0XE9,0X03,0XC8,0X03, 0XE9,0X03,0XE9,0X03,0XE9,0X03,0XE9,0X03,0XE9,0X03,0XE9,0X03,0XE9,0X03,0XE9,0X03, 0XE9,0X03,0XE9,0X03,0XE9,0X03,0XE9,0X03,0XE9,0X03,0XE9,0X03,0XE9,0X03,0XE9,0X03, 0XE9,0X03,0XE9,0X03,0XC9,0X03,0XE9,0X03,0XE9,0X03,0XE9,0X03,0XC9,0X03,0XC9,0X03, 0XE9,0X03,0XC9,0X03,0XE9,0X03,0XE9,0X03,0XC9,0X03,0XE9,0X03,0XC9,0X03,0XE9,0X03, }; 三、效果图 改变每个RGB通道的占空比实现渐变(一行扫描32次),所以闪烁会严重些。 |
|
|
|
只有小组成员才能发言,加入小组>>
3278 浏览 9 评论
2955 浏览 16 评论
3455 浏览 1 评论
8987 浏览 16 评论
4050 浏览 18 评论
1102浏览 3评论
570浏览 2评论
const uint16_t Tab[10]={0}; const uint16_t *p; p = Tab;//报错是怎么回事?
568浏览 2评论
用NUC131单片机UART3作为打印口,但printf没有输出东西是什么原因?
2301浏览 2评论
NUC980DK61YC启动随机性出现Err-DDR是为什么?
1857浏览 2评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-11-22 04:08 , Processed in 1.148499 second(s), Total 78, Slave 58 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号