本帖最后由 jinglixixi 于 2022-3-1 11:52 编辑
要对AT-START-F425开发板进行编程设计,其电路原理图是不可或缺的,然而寻了许多遍也未找到,无奈之下只好参照AT-START-F421开发板的原理图来使用,其Arduino接口的原理图见图1所示。
图1 Arduino接口电路 为了使用的方便,特对SCL、SDA周围的4个GPIO口进行了测试,说明其与图1所标识的是一致的,其中测试SDA引脚的效果如图2所示。
图2 测试引脚连接关系 在确定了所用引脚的连接关系后,就可以使用这4个引脚来驱动OLED显示屏了。 受OLED屏的引脚制约,在OLED屏使用Arduino接口时,是按照下面的连接关系来驱动0.96寸双色OLED屏。 CLK----PA5 SDA---PA6 控制相关引脚输出高低电平的语句定义为: #define OLED_SCLK_Clr() GPIOA->clr = GPIO_PINS_5 #define OLED_SCLK_Set() GPIOA->scr = GPIO_PINS_5 #define OLED_SDIN_Clr() GPIOA->clr = GPIO_PINS_6 #define OLED_SDIN_Set() GPIOA->scr = GPIO_PINS_6 配置所用引脚为输出口的初始化函数为: void app_oled_init(void)
{
gpio_init_type gpio_init_struct;
crm_periph_clock_enable(CRM_GPIOA_PERIPH_CLOCK, TRUE);
gpio_default_para_init(&gpio_init_struct);
gpio_init_struct.gpio_drive_strength = GPIO_DRIVE_STRENGTH_STRONGER;
gpio_init_struct.gpio_out_type = GPIO_OUTPUT_PUSH_PULL;
gpio_init_struct.gpio_mode = GPIO_MODE_OUTPUT;
gpio_init_struct.gpio_pins = GPIO_PINS_5|GPIO_PINS_6;
gpio_init_struct.gpio_pull = GPIO_PULL_NONE;
gpio_init(GPIOA, &gpio_init_struct);
}
对OLED屏的初始化函数为: void OLED_Init(void)
{
Write_IIC_Command(0xAE);
Write_IIC_Command(0x20);
Write_IIC_Command(0x10);
Write_IIC_Command(0xb0);
Write_IIC_Command(0xc8);
Write_IIC_Command(0x00);
Write_IIC_Command(0x10);
Write_IIC_Command(0x40);
Write_IIC_Command(0x81);
Write_IIC_Command(0xdf);
Write_IIC_Command(0xa1);
Write_IIC_Command(0xa6);
Write_IIC_Command(0xa8);
Write_IIC_Command(0x3F);
Write_IIC_Command(0xa4);
Write_IIC_Command(0xd3);
Write_IIC_Command(0x00);
Write_IIC_Command(0xd5);
Write_IIC_Command(0xf0);
Write_IIC_Command(0xd9);
Write_IIC_Command(0x22);
Write_IIC_Command(0xda);
Write_IIC_Command(0x12);
Write_IIC_Command(0xdb);
Write_IIC_Command(0x20);
Write_IIC_Command(0x8d);
Write_IIC_Command(0x14);
Write_IIC_Command(0xaf);
}
实现字符串显示的函数为: void OLED_ShowString(uint8_t x,uint8_t y,uint8_t *chr,uint8_t Char_Size)
{
unsigned char j=0;
while (chr[j]!='\0')
{
OLED_ShowChar(x,y,chr[j],Char_Size);
x+=8;
if(x>120)
{
x=0;
y+=2;
}
j++;
}
}
实现图3所示效果的主程序为: int main(void)
{
system_clock_config();
at32_board_init();
app_oled_init();
OLED_Init();
OLED_Clear();
OLED_ShowString(0,0,"AT32F425",16);
OLED_ShowString(0,2,"OLED TEST",16);
OLED_ShowString(8,4,"jinglixixi",16);
OLED_ShowString(8,6,"2022.2.26",16);
while(1)
{
at32_led_toggle(LED2);
delay_ms(200);
at32_led_toggle(LED3);
delay_ms(200);
at32_led_toggle(LED4);
delay_ms(200);
}
}
图3 字符串显示效果
若使用Arduino接口来驱动0.91寸单色OLED屏,则其连接关系为: CLK----PB9 SDA---PB8 控制相关引脚输出高低电平的语句定义为: #define OLED_SCLK_Clr() GPIOB->clr = GPIO_PINS_9 #define OLED_SCLK_Set() GPIOB->scr = GPIO_PINS_9 #define OLED_SDIN_Clr() GPIOB->clr = GPIO_PINS_8 #define OLED_SDIN_Set() GPIOB->scr = GPIO_PINS_8 配置所用引脚为输出口的初始化函数为: void app_oled_init(void)
{
gpio_init_type gpio_init_struct;
crm_periph_clock_enable(CRM_GPIOB_PERIPH_CLOCK, TRUE);
gpio_default_para_init(&gpio_init_struct);
gpio_init_struct.gpio_drive_strength = GPIO_DRIVE_STRENGTH_STRONGER;
gpio_init_struct.gpio_out_type = GPIO_OUTPUT_PUSH_PULL;
gpio_init_struct.gpio_mode = GPIO_MODE_OUTPUT;
gpio_init_struct.gpio_pins = GPIO_PINS_8|GPIO_PINS_9;
gpio_init_struct.gpio_pull = GPIO_PULL_NONE;
gpio_init(GPIOB, &gpio_init_struct);
}
单色OLED屏的初始化函数为: void OLED_Init(void)
{
Write_IIC_Command(0xAE);
Write_IIC_Command(0x40);
Write_IIC_Command(0xb0);
Write_IIC_Command(0xc8);
Write_IIC_Command(0x81);
Write_IIC_Command(0xff);
Write_IIC_Command(0xa1);
Write_IIC_Command(0xa6);
Write_IIC_Command(0xa8);
Write_IIC_Command(0x1F);
Write_IIC_Command(0xd3);
Write_IIC_Command(0x00);
Write_IIC_Command(0xd5);
Write_IIC_Command(0xf0);
Write_IIC_Command(0xd9);
Write_IIC_Command(0x22);
Write_IIC_Command(0xda);
Write_IIC_Command(0x02);
Write_IIC_Command(0x8d);
Write_IIC_Command(0x14);
Write_IIC_Command(0xdb);
Write_IIC_Command(0x49);
Write_IIC_Command(0xaf);
}
至于单色屏的其它函数,则与双色屏的基本一致无需修改。 实现图4所示效果的主程序为: int main(void)
{
system_clock_config();
at32_board_init();
app_oled_init();
OLED_Init();
OLED_Clear();
OLED_ShowString(48,0,"AT32F425",16);
OLED_ShowString(48,2,"OLED TEST",16);
while(1)
{
at32_led_toggle(LED2);
delay_ms(200);
at32_led_toggle(LED3);
delay_ms(200);
at32_led_toggle(LED4);
delay_ms(200);
}
}
图4 字符串显示效果
|