TA的每日心情 | 开心 2019-11-19 11:07 |
---|
签到天数: 226 天 连续签到: 1 天 [LV.7]常住居民III
|
本帖最后由 zhjb1 于 2017-5-26 09:50 编辑
这个实验的内容较多,包括LED、各种时钟下的消耗电流、驱显串口黑白LCD0713等。
点亮LED,只是测试开发板的所有首选,可以测试开发板的主芯片和IO状况,尽管是有限个IO和基本代码,但很能说明问题。为了接着的实验,控制串口LCD,因此线修改gd32f4xx_eval.h函数中的定义LED的那一段,直接改为:
/* exported types */
typedef enum{
LED1 = 0,
LED2 = 1,
LED3 = 2,
LED4 = 3,
SDIN = 4,
SCLK = 5,
SREG = 6,
SRES = 7
} led_typedef_enum;
增加一段LCD定义:
/eval board LCD pins
#define LEDn 8U
#define SDIN_PIN GPIO_PIN_2
#define SDIN_GPIO_PORT GPIOE
#define SDIN_GPIO_CLK RCU_GPIOE
#define SCLK_PIN GPIO_PIN_5
#define SCLK_GPIO_PORT GPIOE
#define SCLK_GPIO_CLK RCU_GPIOE
#define SREG_PIN GPIO_PIN_4
#define SREG_GPIO_PORT GPIOE
#define SREG_GPIO_CLK RCU_GPIOE
#define SRES_PIN GPIO_PIN_6
#define SRES_GPIO_PORT GPIOE
#define SRES_GPIO_CLK RCU_GPIOE
打开Utilities\gd32f4xx_eval.c文档,修改如下几个函数:
static uint32_t GPIO_PORT[LEDn]={LED1_GPIO_PORT,LED2_GPIO_PORT,LED3_GPIO_PORT,LED4_GPIO_PORT,SDIN_GPIO_PORT,SCLK_GPIO_PORT,SREG_GPIO_PORT,SRES_GPIO_PORT};
static uint32_t GPIO_PIN[LEDn]={LED1_PIN,LED2_PIN,LED3_PIN,LED4_PIN,SDIN_PIN,SCLK_PIN,SREG_PIN,SRES_PIN};
static rcu_periph_enum GPIO_CLK[LEDn]={LED1_GPIO_CLK,LED2_GPIO_CLK,LED3_GPIO_CLK,LED4_GPIO_CLK,SDIN_GPIO_CLK,SCLK_GPIO_CLK,SREG_GPIO_CLK,SRES_GPIO_CLK};
在main.c中增加:
//GPIO Initial
void ioInit(void){
gd_eval_led_init(LED1);
gd_eval_led_init(LED2);
gd_eval_led_init(LED3);
gd_eval_led_init(LED4);
gd_eval_led_init(SDIN);
gd_eval_led_init(SCLK);
gd_eval_led_init(SREG);
gd_eval_led_init(SRES);
}
//LED Test
void ledTest(void){
int tts=500;
gd_eval_led_on(LED1);gd_eval_led_off(SRES);delay_1ms(tts);
gd_eval_led_on(LED2);gd_eval_led_off(LED1);delay_1ms(tts);
gd_eval_led_on(LED3);gd_eval_led_off(LED2);delay_1ms(tts);
gd_eval_led_on(LED4);gd_eval_led_off(LED3);delay_1ms(tts);
gd_eval_led_on(SDIN);gd_eval_led_off(LED4);delay_1ms(tts);
gd_eval_led_on(SCLK);gd_eval_led_off(SDIN);delay_1ms(tts);
gd_eval_led_on(SREG);gd_eval_led_off(SCLK);delay_1ms(tts);
gd_eval_led_on(SRES);gd_eval_led_off(SREG);delay_1ms(tts);
}
最后的main函数中:
//main function
int main(void){
systick_config();
ioInit();
while(1){
ledTest();
}
}
编译下载,结果照片见11。为了测试不同PLL下的功耗——就是测近似电流[USB测表,很不准的,只是大意吧],PLL200MHz、PLL168MHz、PLL120MHz、和IRC16MHz的照片分别是12,13,14,15。可见当打开PLL频率在120MHz以上是的电流增加的不多。就是说PLL打开后的功耗可以忽略了。
接着作串口LCD实验。首先创建一个文件夹,先在1.4 项目中创建一个文件夹incs,将0713.h拷贝到里面,再在项目中创建1个组:incs;并且在Option中声明此incs文件夹默认路径。将0713.h加到里面,0713.h代码如下:
#include "gd32f4xx.h"
#include "gd32f4xx_eval.h"
#include "systick.h"
#include <stdio.h>
//KS0713 LCD
const unsigned char asc2[][6]={//8x8 Dots 32-126[0-94]
{0x00,0x3E,0x45,0x49,0x51,0x3E},//0
{0x00,0x00,0x21,0x7F,0x01,0x00},//1
{0x00,0x31,0x43,0x45,0x49,0x31},//2
{0x00,0x22,0x49,0x49,0x49,0x36},//3
{0x00,0x04,0x0C,0x14,0x7F,0x04},//4
{0x00,0x72,0x51,0x51,0x51,0x4E},//5-5
{0x00,0x3E,0x49,0x49,0x49,0x06},//6
{0x00,0x40,0x43,0x4C,0x50,0x60},//7
{0x00,0x36,0x49,0x49,0x49,0x36},//8
{0x00,0x30,0x48,0x48,0x48,0x3F},//9
{0x00,0x1F,0x24,0x64,0x24,0x1F},//A-10
{0x00,0x41,0x7F,0x49,0x49,0x36},//B
{0x00,0x3E,0x41,0x41,0x41,0x22},//C
{0x00,0x41,0x7F,0x41,0x41,0x3E},//D
{0x00,0x41,0x7F,0x49,0x49,0x63},//E
{0x00,0x41,0x7F,0x49,0x5C,0x60},//F-15
{0x00,0x3E,0x41,0x45,0x47,0x24},//G
{0x41,0x7F,0x08,0x08,0x08,0x7F},//H
{0x00,0x00,0x41,0x7F,0x41,0x00},//I
{0x00,0x42,0x41,0x7F,0x40,0x40},//J
{0x00,0x41,0x7F,0x59,0x24,0x43},//K-20
{0x00,0x40,0x7F,0x41,0x01,0x03},//L
{0x00,0x7F,0x20,0x1E,0x20,0x7F},//M
{0x00,0x7F,0x30,0x18,0x06,0x7F},//N
{0x00,0x3E,0x41,0x41,0x41,0x3E},//O
{0x00,0x41,0x7F,0x49,0x48,0x30},//P-25
{0x00,0x3E,0x41,0x47,0x42,0x3D},//Q
{0x00,0x41,0x7F,0x49,0x4C,0x33},//R
{0x00,0x32,0x49,0x49,0x49,0x26},//S
{0x00,0x60,0x41,0x7F,0x41,0x60},//T
{0x00,0x7E,0x01,0x01,0x01,0x7E},//U-30
{0x00,0x7C,0x02,0x01,0x02,0x7C},//V
{0x00,0x7C,0x03,0x3C,0x03,0x7C},//W
{0x00,0x43,0x24,0x18,0x24,0x43},//X
{0x00,0x60,0x18,0x07,0x18,0x60},//Y
{0x00,0x63,0x45,0x49,0x51,0x63},//Z-35
{0x00,0x00,0x00,0x01,0x00,0x00},//.
{0x00,0x14,0x14,0x14,0x14,0x14},//=
{0x00,0x08,0x08,0x3E,0x08,0x08},//+
{0x00,0x08,0x08,0x08,0x08,0x08},//-
{0x00,0x00,0x00,0x24,0x00,0x00},//:-40
};
//Delayer
void delay(int counter){
int i,j;
for(i=0;i<counter;i++) for(j=0;j<i;j++){;}
}
//Write Plus//1=clk,2=dat,3=reg,4=res
void wri(void){
gd_eval_led_off(SCLK);
gd_eval_led_on(SCLK);
}
//a B Data to LCD,dt:data,com:1-dat/0-com//1=clk,2=dat,3=reg,4=res
void b2l(unsigned char dt,unsigned char com){
unsigned char i;
if(com)gd_eval_led_on(SREG);else gd_eval_led_off(SREG);
for(i=0;i<8;i++){
if(dt&0x80){gd_eval_led_on(SDIN);}else{gd_eval_led_off(SDIN);};
dt=dt<<1;
wri();
}
}
//Set LCD X:0-102 Y:0-3
void setXY(unsigned char pag,unsigned char col){
b2l(0xB0+pag,0);//page
//col+=0x04;//+4-->4bit
b2l(0x10+((col&0x70)>>4),0);//row-H4
b2l(col&0x0F,0);//row-L4
}
//LCD Clear
void lcdClear(void){
unsigned char pag,col;
for(pag=0;pag<8;pag++){
setXY(pag,0);
for(col=0;col<132;col++){b2l(0x00,1);};
}
}
//c:Char,cha[]
void c2l(unsigned char pag,unsigned char col,unsigned char c){
unsigned char line;
setXY(pag,col*6);//6
for (line=0;line<6;line++)//6
b2l(asc2[c][line],1);//b2l(hanzi[c*8+line],1);
}
//KS0713LCD Initial
void lcdInit(void){
gd_eval_led_off(SRES);
delay(2000);
gd_eval_led_on(SRES);
delay(2000);
b2l(0xAE,0);//AE=关闭显示/AF=开显示
b2l(0xE2,0);//LCD初始化
b2l(0xA1,0);//刷新行顺序A0=1~132列/A1=132~1
b2l(0xC8,0);//刷新纵顺序C0=1~64行/C8=64~1
b2l(0xA2,0);//A2=1/65=1/7__A3=1/65=1/9速率
b2l(0x2F,0);//电源模式28+VC+VR+VF
delay(200);
b2l(0x23,0);//20~27=1.9,2.19,2.55,3.02,3.61,4.35,5.29,6.48V/偏压
delay(200);
b2l(0x81,0);//V0电压,后跟参数
b2l(0x2C,0);//000000~111111=0~63=8.83~11.17V/30=10V
delay(200);
b2l(0xAD,0);//AC=关闭游标/AD=打开游标
b2l(0x00,0);//跟上00=OFF/01=1S/02=0.5S/03=AllOn
b2l(0xAF,0);//开始显示
delay(200);
}
//0713 Display ASCII Test
void dispAsc(void){
int i,j,k=0;
for(i=0;i<4;i++){
for(j=0;j<16;j++){
c2l(i,j,k);
if(k>39){k=0;}else{k++;}
}
}
}
//END Files//
由于设置LED实验已经定义了串口的4根引脚的信号:SDIN、SCLK、SREG、SRES,因此这里省略了。main.c中需要增加一个定时函数:
//DELAYER
void delaym(int counter){
int i,j;
for(i=0;i<counter;i++) for(j=0;j<i;j++){;}
}
更改ledTest函数,只是为了测试主函数在运行,所以1个LED闪亮就可以了:
void ledTest(void){
int tts=1000;
gd_eval_led_on(LED1);
delaym(tts);
gd_eval_led_off(LED1);
}
main更改为:
//main function
int main(void){
systick_config();
ioInit();
lcdInit();
lcdClear();
while(1){
js++;
ledTest();
dispAsc();
delaym(10000);
lcdClear();
}
}
最后修改system_gd32f4xx.c,开通下一行,其他的时钟注释掉[#define __SYSTEM_CLOCK_IRC16M (uint32_t)(__IRC16M)这一行开通,刷屏明显]
#define __SYSTEM_CLOCK_120M_PLL_IRC16M (uint32_t)(120000000)
下载后的待测试电流的结果照片见16,没有测电流的照片17。
|
|