本实验采用官方提供的案例程序,经过修改将数据显示在LCD屏幕上,为了省事,渐亮采用源码。改动不大,具体如下: 首先打开stm32f401_discovery.h文档,更改和增加以下内容: 定义led对象: typedef enum { LED4 = 0, LED3 = 1, LED5 = 2, LED6 = 3, LCDVDD = 4, LCDSDA = 5, LCDSCL = 6, LCDSRE = 7, LCDSRG = 8 } Led_TypeDef; leds属性定义: #define LEDn 9 #define LED4_PIN GPIO_Pin_12 #define LED4_GPIO_PORT GPIOD #define LED4_GPIO_CLK RCC_AHB1Periph_GPIOD #define LED3_PIN GPIO_Pin_13 #define LED3_GPIO_PORT GPIOD #define LED3_GPIO_CLK RCC_AHB1Periph_GPIOD #define LED5_PIN GPIO_Pin_14 #define LED5_GPIO_PORT GPIOD #define LED5_GPIO_CLK RCC_AHB1Periph_GPIOD #define LED6_PIN GPIO_Pin_15 #define LED6_GPIO_PORT GPIOD #define LED6_GPIO_CLK RCC_AHB1Periph_GPIOD #define LCDVDD_PIN GPIO_Pin_7//此引脚第一位高电平,为ks0713专用 #define LCDVDD_GPIO_PORT GPIOE #define LCDVDD_GPIO_CLK RCC_AHB1Periph_GPIOE #define LCDSDA_PIN GPIO_Pin_15 #define LCDSDA_GPIO_PORT GPIOE #define LCDSDA_GPIO_CLK RCC_AHB1Periph_GPIOE #define LCDSCL_PIN GPIO_Pin_13 #define LCDSCL_GPIO_PORT GPIOE #define LCDSCL_GPIO_CLK RCC_AHB1Periph_GPIOE #define LCDSRG_PIN GPIO_Pin_11 #define LCDSRG_GPIO_PORT GPIOE #define LCDSRG_GPIO_CLK RCC_AHB1Periph_GPIOE #define LCDSRE_PIN GPIO_Pin_9 #define LCDSRE_GPIO_PORT GPIOE #define LCDSRE_GPIO_CLK RCC_AHB1Periph_GPIOE 而后打开stm32f401_doscover.c,更改以下内容: GPIO_TypeDef* GPIO_PORT[LEDn] = {LED4_GPIO_PORT,LED3_GPIO_PORT,LED5_GPIO_PORT,LED6_GPIO_PORT,LCDVDD_GPIO_PORT,LCDSDA_GPIO_PORT,LCDSCL_GPIO_PORT,LCDSRE_GPIO_PORT,LCDSRG_GPIO_PORT}; const uint16_t GPIO_PIN[LEDn] = {LED4_PIN, LED3_PIN, LED5_PIN,LED6_PIN,LCDVDD_PIN,LCDSDA_PIN,LCDSCL_PIN,LCDSRE_PIN,LCDSRG_PIN}; const uint32_t GPIO_CLK[LEDn] = {LED4_GPIO_CLK,LED3_GPIO_CLK,LED5_GPIO_CLK,LED6_GPIO_CLK,LCDVDD_GPIO_CLK,LCDSDA_GPIO_CLK,LCDSCL_GPIO_CLK,LCDSRE_GPIO_CLK,LCDSRG_GPIO_CLK}; 之后打开主函数main.cpp 增加include文件: #include "6903.h" 增加函数定义: void delay(int counter); void dispBase(void); void dispMes(void); void ioInit(void); 增加自定义变量: int32_t jsq; //float ; int pdir0=1,pdir1=1,twAddr1=0xBC,twAddr2=0xBB,k=0,graX,graY,val0,val1,val2,val3,k; 增加4个函数: //Delayer void delay(int counter){ int i,j; for(i=0;i<counter;i++){for(j=0;j<i;j++){;}} } //GPIO Initial void ioInit(void){ STM_EVAL_LEDInit(LED3); STM_EVAL_LEDInit(LED4); STM_EVAL_LEDInit(LED5); STM_EVAL_LEDInit(LED6); STM_EVAL_LEDInit(LCDVDD); STM_EVAL_LEDInit(LCDSDA); STM_EVAL_LEDInit(LCDSCL); STM_EVAL_LEDInit(LCDSRE); STM_EVAL_LEDInit(LCDSRG); STM_EVAL_LEDOn(LCDVDD); } //Display Base Meseger void dispBase(void){ c2l(0,0,19);c2l(1,0,28);c2l(2,0,26);c2l(3,0,40);//JSQ: c2l(0,1,16);c2l(1,1,33);c2l(2,1,40);//c2l(1,3,40);//GX: c2l(9,1,16);c2l(10,1,34);c2l(11,1,40);//c2l(1,12,40);//GY: c2l(0,2,16);c2l(1,2,35);c2l(2,2,40);//c2l(2,3,40);//PW0: c2l(9,2,16);c2l(10,2,10);c2l(11,2,40);//c2l(2,12,40);//PW1: //c2l(0,3,29);c2l(1,3,14);c2l(2,3,22);c2l(3,3,40);//TEM: //c2l(9,3,17);c2l(10,3,30);c2l(11,3,22);c2l(12,3,40);//HUM: } //Display Messeg void dispMes(void){ c2l(4,0,(jsq/1000000)%10);c2l(5,0,(jsq/100000)%10);c2l(6,0,(jsq/10000)%10);c2l(7,0,(jsq/1000)%10);//JSQ: c2l(8,0,(jsq/100)%10);c2l(9,0,(jsq/10)%10);c2l(10,0,(jsq)%10);//JSQ: if(val0>0)c2l(3,1,38);else c2l(3,1,39);val0=ABS(val0); c2l(4,1,(val0/100)%10);c2l(5,1,(val0/10)%10);c2l(6,1,(val0)%10);//c2l(1,7,(val2)%10);//X if(val1>0)c2l(12,1,38);else c2l(12,1,39);val1=ABS(val1); c2l(13,1,(val1/100)%10);c2l(14,1,(val1/10)%10);c2l(15,1,(val1)%10);//c2l(1,16,(val3)%10);//Y if(val2>0)c2l(3,2,38);else c2l(3,2,39);val2=ABS(val2); c2l(4,2,(val2/100)%10);c2l(5,2,(val2/10)%10);c2l(6,2,(val2)%10);//c2l(2,7,(val0)%10);//Z if(val3>0)c2l(12,2,38);else c2l(12,2,39);val3=ABS(val3); c2l(13,2,(val3/100)%10);c2l(14,2,(val3/10)%10);c2l(15,2,(val3)%10);//c2l(2,16,(val1)%10);//第4个变量——实际永远为0 } 编译下载运行结果见视频:41-3轴加速度计L3GD20采样实验 |
STM32
超强工具——STM32CubeMX 你会用吗?
集结出发! STM32全国研讨会系列之一:ST智能门铃中国首秀
关于STM32启动文件的几个小问题
【银杏科技ARM+FPGA双核心应用】STM32H7系列35——USB_VCP_FS
【银杏科技ARM+FPGA双核心应用】STM32H7系列28——USB_HID
粉丝分享 | 图说CRC原理应用及STM32硬件CRC外设
STM32L151进入低功耗,并由RTC唤醒的故事
[转]stm32控制NFC模块(PN532)源码(P2P,模拟卡,读写卡等
STM32G070RB+LVGL移植
谢谢!80元买的板子不玩玩也对不起她。