一、为什么移植RT-Thread RT-Thread是一个完全国产化的嵌入式实时多线程操作系统,看到AT32例程并没有关于RT-Thread的移植,鉴于AT32F425最大FLASH只有64K,故移植RT-Thread极简版,也就是RT-Thread Nano。 二、准备工作 1、AT32F425 BSP以及固件库。 下载链接:雅特力科技 : 32位微控制器的创新领导者! (arterytek.com) 2、RT-Thread Nano源码安装包 方法一、通过KEIL安装 1)打开 MDK 软件,点击工具栏的 Pack Installer 图标
2)点击右侧的 Pack,展开 Generic,可以找到 RealThread::RT-Thread,点击 Action 栏对应的 Install ,就可以在线安装 Nano Pack 了。另外,如果需要安装其他版本,则需要展开 RealThread::RT-Thread,进行选择
方法二、从官网下载即可。 https://www.rt-thread.org/download/mdk/RealThread.RT-Thread.3.1.5.pack 下载完,直接双击即可。 三、移植流程 1、新建AT32F425的基本工程(官方给的是所有的工程共用BSP) 1)复制官方的library到自己所新建的文件夹,并且添加at32f425_board.c、at32f425_board.h、at32f425_clock.c、at32f425_clock.h、at32f425_int.c、at32f425_int.h、main.c、at32f425_conf.h文件。 2)添加相应的C文件、添加.h文件目录。然后编译。 2、添加RT-Thread Nano到工程 1)点击工具栏Manage Run-Time Environment图标,如下图: 2)在 Manage Rum-Time Environment 里"Software Component" 栏找到 RTOS,sel 栏选择 RT-Thread,然后勾选 kernel,点击 "OK" 就添加 RT-Thread 内核到工程了。展开RTOS就可以看到添加到工程的文件。如图所示。
3、适配RT-Thread Nano 1)在at32f425_init.c文件中注释HardFault_Handler、PendSV_Handler、SysTick_Handler,这些已经由RT-Thread实现了。 2)在borad.c中实现系统时钟配置和OS tick配置。然后在main.c函数里面加入LED显示配置,编译,检查是否移植正确 /*
* Copyright (c) 2006-2019, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
* 2021-05-24 the first version
*/
#include <rthw.h>
#include <rtthread.h>
#include "at32f425_board.h"
#include "at32f425_clock.h"
#include "at32f425.h"
#if defined(RT_USING_USER_MAIN) && defined(RT_USING_HEAP)
/*
* Please modify RT_HEAP_SIZE if you enable RT_USING_HEAP
* the RT_HEAP_SIZE max value = (sram size - ZI size), 1024 means 1024 bytes
*/
#define RT_HEAP_SIZE (15*1024)
static rt_uint8_t rt_heap[RT_HEAP_SIZE];
RT_WEAK void *rt_heap_begin_get(void)
{
return rt_heap;
}
RT_WEAK void *rt_heap_end_get(void)
{
return rt_heap + RT_HEAP_SIZE;
}
#endif
void rt_os_tick_callback(void)
{
rt_interrupt_enter();
rt_tick_increase();
rt_interrupt_leave();
}
/* cortex-m ¼Ü¹¹Ê¹Óà SysTick_Handler() */
void SysTick_Handler(void)
{
rt_os_tick_callback();
}
/**
* This function will initial your board.
*/
void rt_hw_board_init(void)
{
/*
* TODO 1: OS Tick Configuration
* Enable the hardware timer and call the rt_os_tick_callback function
* periodically with the frequency RT_TICK_PER_SECOND.
*/
system_clock_config();//system clock config
/* init LED2 LED3 LED4 */
at32_board_init();
/* init usart1 */
uart_print_init(115200);
/* 2¡¢OS Tick ƵÂÊÅäÖã¬RT_TICK_PER_SECOND = 1000 ±íʾ 1ms ´¥·¢Ò»´ÎÖÐ¶Ï */
SysTick_Config(system_core_clock / RT_TICK_PER_SECOND);
/* Call components board initial (use INIT_BOARD_EXPORT()) */
#ifdef RT_USING_COMPONENTS_INIT
rt_components_board_init();
#endif
#if defined(RT_USING_USER_MAIN) && defined(RT_USING_HEAP)
rt_system_heap_init(rt_heap_begin_get(), rt_heap_end_get()); //use dynamic memory heap
#endif
}
#ifdef RT_USING_CONSOLE
static int uart_init(void)
{
/* init usart1 */
uart_print_init(115200);
return 0;
}
INIT_BOARD_EXPORT(uart_init);
void rt_hw_console_output(const char *str)
{
rt_enter_critical(); //enter critial area
while(*str != '\0')
{
if(*str == '\n')
{
usart_data_transmit(USART1, '\r');
while(usart_flag_get(USART1, USART_TDBE_FLAG) == RESET);
}
usart_data_transmit(USART1, *str++);
while(usart_flag_get(USART1, USART_TDBE_FLAG) == RESET);
}
rt_exit_critical();//exit critial area
}
#endif
4、编写OLED驱动
#include "OLED.h"
#include "oledfont.h"
#include <rtthread.h>
/*OLED¶ÎÂë·Ö²¼
Õý³£
£¨page0) SEG0-SEG128
COM0
|
COM7
·´ÖÃ
£¨page0) SEG128-SEG0
COM63
|
COM56
дÃüÁÆäʵÊÇд¼Ä´æÆ÷
*/
/****************************************************************************
* Ãû ³Æ£ºvoid OLED_Config(void)
* ¹¦ ÄÜ£ºÅäÖÃOLEDÏà¹ØÅäÖÃ
* Èë¿Ú²ÎÊý£ºÎÞ
* ³ö¿Ú²ÎÊý£ºÎÞ
* ˵ Ã÷£º
****************************************************************************/
void OLED_Config(void)
{
OLED_GPIO_Init();
OLED_SPI_Init();
OLED_Init();
}
/****************************************************************************
* Ãû ³Æ£ºvoid OLED_GPIO_Init(void)
* ¹¦ ÄÜ£ºÅäÖÃÔÚOLEDÓëstm32¼äspiͨÐŵÄÒý½Å¼°¿ØÖÆOLEDµÄÒý½Å
* Èë¿Ú²ÎÊý£ºÎÞ
* ³ö¿Ú²ÎÊý£ºÎÞ
* ˵ Ã÷£º
****************************************************************************/
void OLED_GPIO_Init(void)
{
gpio_init_type gpio_init_struct;
/* enable the button clock */
crm_periph_clock_enable(CRM_GPIOA_PERIPH_CLOCK, TRUE);
crm_periph_clock_enable(CRM_GPIOB_PERIPH_CLOCK, TRUE);
/* set default parameter */
gpio_default_para_init(&gpio_init_struct);
/* configure button pin as input with pull-up/pull-down */
//OLED ƬѡÒý½Å
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_4 ;
gpio_init_struct.gpio_pull = GPIO_PULL_NONE;
gpio_init(GPIOA, &gpio_init_struct);
gpio_bits_set(GPIOA, GPIO_PINS_4);
//OLED ¸´Î»Òý½Å
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_6;
gpio_init_struct.gpio_pull = GPIO_PULL_NONE;
gpio_init(GPIOA, &gpio_init_struct);
gpio_bits_set(GPIOA, GPIO_PINS_6);
//OLED SCLK¹Ü½Å
gpio_init_struct.gpio_drive_strength = GPIO_DRIVE_STRENGTH_STRONGER;
gpio_init_struct.gpio_out_type = GPIO_OUTPUT_PUSH_PULL;
gpio_init_struct.gpio_pull = GPIO_PULL_DOWN;
gpio_init_struct.gpio_mode = GPIO_MODE_MUX;
gpio_init_struct.gpio_pins = GPIO_PINS_5;
gpio_init(GPIOA, &gpio_init_struct);
gpio_pin_mux_config(GPIOA, GPIO_PINS_SOURCE5, GPIO_MUX_0);
//OLED MOSI¹Ü½Å
gpio_init_struct.gpio_drive_strength = GPIO_DRIVE_STRENGTH_STRONGER;
gpio_init_struct.gpio_out_type = GPIO_OUTPUT_PUSH_PULL;
gpio_init_struct.gpio_pull = GPIO_PULL_DOWN;
gpio_init_struct.gpio_mode = GPIO_MODE_MUX;
gpio_init_struct.gpio_pins = GPIO_PINS_7;
gpio_init(GPIOA, &gpio_init_struct);
gpio_pin_mux_config(GPIOA, GPIO_PINS_SOURCE7, GPIO_MUX_0);
//OLED Êý¾ÝºÍÃüÁî¿ØÖÆÒý½Å
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_0;
gpio_init_struct.gpio_pull = GPIO_PULL_NONE;
gpio_init(GPIOB, &gpio_init_struct);
gpio_bits_set(GPIOB, GPIO_PINS_0);
}
/****************************************************************************
* Ãû ³Æ£ºvoid OLED_SPI_Init(void)
* ¹¦ ÄÜ£ºÅäÖÃÔÚOLEDÓëstm32¼äspiͨÐŵijõʼ»¯
* Èë¿Ú²ÎÊý£ºÎÞ
* ³ö¿Ú²ÎÊý£ºÎÞ
* ˵ Ã÷£º
****************************************************************************/
void OLED_SPI_Init(void)
{
spi_init_type SPI_InitStructure;
crm_periph_clock_enable(CRM_SPI1_PERIPH_CLOCK, TRUE);
//ÅäÖÃSPI1Ïà¹Ø²ÎÊý£ºÈ«Ë«¹¤Í¨ÐÅ¡¢MSB/LSB¡¢Í¨ÐÅËٶȡ¢¹¤×÷ģʽ£¨mode0~mode3£©......
SPI_InitStructure.transmission_mode = SPI_TRANSMIT_FULL_DUPLEX; //È«Ë«¹¤Í¨ÐÅ
SPI_InitStructure.master_slave_mode = SPI_MODE_MASTER; //Ö÷»ú½ÇÉ«
SPI_InitStructure.frame_bit_num = SPI_FRAME_8BIT; //¿´Ê±Ðòͼ£¬8λÊý¾Ýλ
SPI_InitStructure.clock_polarity = SPI_CLOCK_POLARITY_LOW; //ʱÖÓÏß¿ÕÏеÄʱºòÊÇʲôµçƽ£¬µ±Ç°ÅäÖÃΪµÍµçƽ
SPI_InitStructure.clock_phase = SPI_CLOCK_PHASE_1EDGE; //Ö÷»úÔÚʱÖÓÏßÄÄÒ»¸öʱ¿Ì¶ÁÈ¡MISOÒý½ÅµÄµçƽ£¬ÔÚʱÖÓµÚÒ»¸ö±ßÑØÀ´²É¼¯Êý¾Ý
SPI_InitStructure.cs_mode_selection = SPI_CS_SOFTWARE_MODE; //ƬѡÐèÒª´úÂë¿ØÖÆ
SPI_InitStructure.mclk_freq_division = SPI_MCLK_DIV_256; //SPI1µÄͨÐÅÓ²¼þʱÖÓ=72MHz/256
SPI_InitStructure.first_bit_transmission = SPI_FIRST_BIT_MSB; //×î¸ßÓÐЧλÓÅÏÈ´«Êä
spi_init(SPI1,&SPI_InitStructure);
spi_enable(SPI1, TRUE);
}
/****************************************************************************
* Ãû ³Æ£ºvoid OLED_Init(void)
* ¹¦ ÄÜ£ºOLED³õʼ»¯
* Èë¿Ú²ÎÊý£ºÎÞ
* ³ö¿Ú²ÎÊý£ºÎÞ
* ˵ Ã÷£º²ÎÕÕÉϵçÐòÁгõʼ»¯£¨24/40£©
****************************************************************************/
void OLED_Init(void)
{
OLED_CS_High;
//¸´Î»OLED
OLED_RST_High;
rt_thread_mdelay(200);
OLED_RST_Low;
rt_thread_mdelay(200);
OLED_RST_High;
OLED_Write_Operate(OLED_Mode_Cmd,0xAE); //¹Ø±ÕOLED
OLED_Write_Operate(OLED_Mode_Cmd,0x00); //ÉèÖÃÁеÍλµØÖ·
OLED_Write_Operate(OLED_Mode_Cmd,0x10); //ÉèÖÃÁиßλµØÖ·
OLED_Write_Operate(OLED_Mode_Cmd,0x40); //ÉèÖÃÆðʼÐеØÖ·¼°Ó³ÉäRAMÏÔʾÆðʼÐÐ (0x00~0x3F£©
OLED_Write_Operate(OLED_Mode_Cmd,0xB0); //ÉèÖÃÒ³µØÖ·
OLED_Write_Operate(OLED_Mode_Cmd,0x81); //¶Ô±È¶ÈÉèÖÃ
OLED_Write_Operate(OLED_Mode_Cmd,0xCF); //Set SEG Output Current Brightness
OLED_Write_Operate(OLED_Mode_Cmd,0xA1); //Set SEG/Column Mapping 0xa0×óÓÒ·´ÖÃ 0xa1Õý³£
OLED_Write_Operate(OLED_Mode_Cmd,0xA6); //
OLED_Write_Operate(OLED_Mode_Cmd,0xA8); //ÉèÖÃÇý¶¯Â·Êý(1 to 64)
OLED_Write_Operate(OLED_Mode_Cmd,0x3F); //*duty = 1/64*/
OLED_Write_Operate(OLED_Mode_Cmd,0xC8); //0xc0ÉÏÏ·´Öà 0xc8Õý³£
OLED_Write_Operate(OLED_Mode_Cmd,0xD3); //ÉèÖÃÏÔʾƫÒÆ(0x00~0x3F)
OLED_Write_Operate(OLED_Mode_Cmd,0x00); //not offset
OLED_Write_Operate(OLED_Mode_Cmd,0xD5); //--set Display clock divide ratio/oscillator frequency
OLED_Write_Operate(OLED_Mode_Cmd,0x80); //--set divide ratio, Set Clock as 100 Frames/Sec
OLED_Write_Operate(OLED_Mode_Cmd,0xD9); //*set pre-charge period*/
OLED_Write_Operate(OLED_Mode_Cmd,0Xf1); //Set Pre-Charge as 15 Clocks & Discharge as 1 Clock
OLED_Write_Operate(OLED_Mode_Cmd,0xDA); //*set COM pins*/
OLED_Write_Operate(OLED_Mode_Cmd,0x12); //
OLED_Write_Operate(OLED_Mode_Cmd,0xdb); //*set vcomh*/
OLED_Write_Operate(OLED_Mode_Cmd,0x40); //Set VCOM Deselect Level
/**/
OLED_Write_Operate(OLED_Mode_Cmd,0x20); //ÉèÖô洢ģʽ£¨0x00,0x02£¬0x01£©
OLED_Write_Operate(OLED_Mode_Cmd,0x02); //Ò³µØַģʽ
OLED_Write_Operate(OLED_Mode_Cmd,0x8d); //*set charge pump disable*/
OLED_Write_Operate(OLED_Mode_Cmd,0x14); //--set(0x10) disable
/**/
OLED_Write_Operate(OLED_Mode_Cmd,0xA4); //ÏÔʾ¿ªÆô£¨A4£¬ÏÔʾ£¬A5ÎÞÏÔʾ£©
OLED_Write_Operate(OLED_Mode_Cmd,0xA6); //±³¾°Õý·´ÏòÏÔʾ£¨0xa6,ÕýÏÔ£¬0xa7£¬·´ÏÔ£©
OLED_Display_Clear(); //ÇåÆÁ
OLED_Write_Operate(OLED_Mode_Cmd,0xAF); //´ò¿ªÏÔʾ
}
/****************************************************************************
* Ãû ³Æ£ºu8 SPI1_WriteReadByte(u8 Data)
* ¹¦ ÄÜ£ºSPI1¶Áдһ¸ö×Ö½Ú
* Èë¿Ú²ÎÊý£ºÎÞ
* ³ö¿Ú²ÎÊý£º½ÓÊÕµÄÊý¾Ý
* ·µ»ØÖµ £º0£¬·¢ËͽÓÊÕ³¬Ê±£¬1³É¹¦
* ˵ Ã÷£ºÎÞ
****************************************************************************/
u8 SPI1_WriteReadByte(u8 Data)
{
u8 cnt = 0;
while(spi_i2s_flag_get(SPI2, SPI_I2S_TDBE_FLAG) == RESET) //µÈ´ý·¢ËÍÇøΪ¿Õ
{
cnt++;
if( cnt > 100)
return 0;
}
spi_i2s_data_transmit(SPI1,Data); //·¢ËÍÒ»¸ö×Ö½ÚµÄÊý¾Ý
cnt = 0;
while(spi_i2s_flag_get(SPI1, SPI_I2S_RDBF_FLAG) == RESET) //µÈ´ý½ÓÊÕÍêÒ»¸öByte
{
cnt++;
if( cnt > 100)
return 0;
}
return spi_i2s_data_receive(SPI1); //½ÓÊÕÒ»¸ö×Ö½ÚµÄÊý¾Ý
}
/****************************************************************************
* Ãû ³Æ£ºu8 OLED_Write_Byte(u8 data)
* ¹¦ ÄÜ£ºOLEDдһ¸ö×Ö½Ú
* Èë¿Ú²ÎÊý£ºÎÞ
* ³ö¿Ú²ÎÊý£º½ÓÊÕµÄÊý¾Ý
* ·µ»ØÖµ £º0ʧ°Ü£¬1³É¹¦
* ˵ Ã÷£ºÎÞ
****************************************************************************/
u8 OLED_Write_Byte(u8 data)
{
if(!SPI1_WriteReadByte(data))
return 0;
else
return 1;
}
/****************************************************************************
* Ãû ³Æ£ºvoid OLED_Write_Operate(u8 mode,u8 data)
* ¹¦ ÄÜ£ºOLEDд²Ù×÷
* Èë¿Ú²ÎÊý£ºÄ£Ê½£¬Êý¾Ý
* ³ö¿Ú²ÎÊý£ºÎÞ
* ·µ»ØÖµ £ºÎÞ
* ˵ Ã÷£ºÎÞ
****************************************************************************/
void OLED_Write_Operate(u8 mode,u8 data)
{
OLED_CS_Low;
if(mode)
{
OLED_Write_Data;
}
else
{
OLED_Write_Cmd;
}
OLED_Write_Byte(data);
OLED_CS_High;
}
/****************************************************************************
* Ãû ³Æ£ºvoid OLED_Display_Clear(void)
* ¹¦ ÄÜ£ºOLEDÇåÆÁ
* Èë¿Ú²ÎÊý£ºÎÞ
* ³ö¿Ú²ÎÊý£ºÎÞ
* ·µ»ØÖµ £ºÎÞ
* ˵ Ã÷£ºÎÞ
****************************************************************************/
void OLED_Display_Clear(void)
{
u8 page = 0;
u8 i=0;
OLED_CS_Low;
for(page=0;page < 8; page++)
{
OLED_Write_Operate(OLED_Mode_Cmd,0xB0+page);//ÉèÖÃÒ³µØÖ·
OLED_Write_Operate(OLED_Mode_Cmd,0x00); //ÉèÖÃÏÔʾλÖÃ-Áе͵ØÖ·
OLED_Write_Operate(OLED_Mode_Cmd,0x10); //ÉèÖÃÏÔʾλÖÃ-ÁиߵØÖ·
for(i = 0;i< 128; i++)
{
OLED_Write_Operate(OLED_Mode_Data,0x00); //ÇåÆÁ
}
}
}
/****************************************************************************
* Ãû ³Æ£ºvoid OLED_Set_Positon(void)
* ¹¦ ÄÜ£ºÉèÖÃÏÔʾ×ø±ê
* Èë¿Ú²ÎÊý£ºx,y
* ³ö¿Ú²ÎÊý£ºÎÞ
* ·µ»ØÖµ £ºÎÞ
* ˵ Ã÷£ºÎÞ
****************************************************************************/
void OLED_Set_Positon(u8 x,u8 y)
{
OLED_Write_Operate(OLED_Mode_Cmd,0xB0 + y); //ÉèÖÃÒ³µØÖ·
OLED_Write_Operate(OLED_Mode_Cmd,((x & 0xf0) >>4 ) | 0x10); //ÉèÖÃÁиßËÄλµØÖ·
OLED_Write_Operate(OLED_Mode_Cmd,(x & 0x0f) | 0x01); //ÉèÖÃÁеÍËÄλµØÖ·
}
/****************************************************************************
* Ãû ³Æ£ºvoid OLED_Display_on(void)
* ¹¦ ÄÜ£ºÏÔʾ´ò¿ª
* Èë¿Ú²ÎÊý£ºÎÞ
* ³ö¿Ú²ÎÊý£ºÎÞ
* ·µ»ØÖµ £ºÎÞ
* ˵ Ã÷£ºÎÞ
****************************************************************************/
void OLED_Display_on(void)
{
OLED_Write_Operate(OLED_Mode_Cmd,0x8d); //д³äµç±Ã¼Ä´æÆ÷
OLED_Write_Operate(OLED_Mode_Cmd,0x14); //´ò¿ª³äµç±Ã
OLED_Write_Operate(OLED_Mode_Cmd,0xAF); //´ò¿ªOLEDÏÔʾ
}
/****************************************************************************
* Ãû ³Æ£ºvoid OLED_Display_offvoid)
* ¹¦ ÄÜ£ºÏÔʾ¹Ø±Õ
* Èë¿Ú²ÎÊý£ºÎÞ
* ³ö¿Ú²ÎÊý£ºÎÞ
* ·µ»ØÖµ £ºÎÞ
* ˵ Ã÷£ºÎÞ
****************************************************************************/
void OLED_Display_off(void)
{
OLED_Write_Operate(OLED_Mode_Cmd,0x8d); //д³äµç±Ã¼Ä´æÆ÷
OLED_Write_Operate(OLED_Mode_Cmd,0x10); //¹Ø±Õ³äµç±Ã
OLED_Write_Operate(OLED_Mode_Cmd,0xAE); //¹Ø±ÕOLEDÏÔʾ
}
/****************************************************************************
* Ãû ³Æ£ºvoid OLED_Display_onechar(u8 x,u8 y,u8 character,u8 size)
* ¹¦ ÄÜ£ºÏÔʾµ¥¸ö×Ö·û
* Èë¿Ú²ÎÊý£º
x ,y×ø±êλÖÃ
character ×Ö·û
size ×ֺŴóС
* ³ö¿Ú²ÎÊý£ºÎÞ
* ·µ»ØÖµ £ºÎÞ
* ˵ Ã÷£ºÎÞ
****************************************************************************/
void OLED_Display_onechar(u8 x,u8 y,u8 character,u8 size)
{
u8 c=0,i=0;
c = character-' ';
if(x > MAX_COLUMN - 1)
{
x= 0;
if(size == SIZE8)
{
y = y+1;
}
if(size == SIZE16)
{
y = y+2;
}
}
if(size == SIZE16)
{
OLED_Set_Positon(x,y);
for( i =0;i< 8; i++)
{
OLED_Write_Operate(OLED_Mode_Data,F8X16[c*16 + i]);
}
OLED_Set_Positon(x,y+1);
for( i =0;i< 8; i++)
{
OLED_Write_Operate(OLED_Mode_Data,F8X16[c*16 + i+8]);
}
}
else
{
OLED_Set_Positon(x,y+1);
for( i =0;i< 6; i++)
{
OLED_Write_Operate(OLED_Mode_Data,F6x8[c][i]);
}
}
}
/****************************************************************************
* Ãû ³Æ£ºvoid OLED_Display_string(u8 x,u8 y,u8 *str,u8 size)
* ¹¦ ÄÜ£ºÏÔʾ×Ö·û´®
* Èë¿Ú²ÎÊý£º
x ,y×ø±êλÖÃ
str ×Ö·û´®
size ×ֺŴóС
* ³ö¿Ú²ÎÊý£ºÎÞ
* ·µ»ØÖµ £ºÎÞ
* ˵ Ã÷£ºÎÞ
****************************************************************************/
void OLED_Display_string(u8 x,u8 y,u8 *str,u8 size)
{
u8 i=0;
while(str[i]!='\0')
{
OLED_Display_onechar(x,y,str[i],size);
x += 8;
if(x > 120)
{
x = 0;
y += 2;
}
i++;
}
}
/****************************************************************************
* Ãû ³Æ£ºvoid OLED_Display_Chinese(u8 x,u8 y,u8 Sno)
* ¹¦ ÄÜ£ºÏÔʾµ¥¸ö×Ö·û
* Èë¿Ú²ÎÊý£º
x ,y×ø±êλÖÃ
Sno ±íʾºº×ÖÊý×éÖÐÒ»¸ö×ÖµÄÂëËùÕ¼µÄÐòºÅ
* ³ö¿Ú²ÎÊý£ºÎÞ
* ·µ»ØÖµ £ºÎÞ
* ˵ Ã÷£ºÎÞ
****************************************************************************/
void OLED_Display_Chinese(u8 x,u8 y,u8 Sno)
{
u8 adder=0,i=0;
OLED_Set_Positon(x,y);
for(i = 0;i< 16;i++)
{
OLED_Write_Operate(OLED_Mode_Data,Hzk[2*Sno][i]);
adder += 1;
}
OLED_Set_Positon(x,y+1);
for(i = 0;i< 16;i++)
{
OLED_Write_Operate(OLED_Mode_Data,Hzk[2*Sno+1][i]);
adder += 1;
}
}
/****************************************************************************
* Ãû ³Æ£ºu32 OLED_POW(u8 m, u8 n)
* ¹¦ ÄÜ£ºmµÄn´Î·½
* Èë¿Ú²ÎÊý£º
mΪµ×Êý£¬nΪָÊý
* ³ö¿Ú²ÎÊý£ºÎÞ
* ·µ»ØÖµ £ºÎÞ
* ˵ Ã÷£ºÎÞ
****************************************************************************/
u32 OLED_POW(u8 m, u8 n)
{
u32 result=1;
while(n--)
{
result *= m;
}
return result;
}
/****************************************************************************
* Ãû ³Æ£ºvoid OLED_Display_Num(u8 x,u8 y,u32 num, u8 Len,u8 size)
* ¹¦ ÄÜ£ºÏÔʾµ¥¸ö×Ö·û
* Èë¿Ú²ÎÊý£º
x ,y×ø±êλÖÃ
Sno ±íʾºº×ÖÊý×éÖÐÒ»¸ö×ÖµÄÂëËùÕ¼µÄÐòºÅ
* ³ö¿Ú²ÎÊý£ºÎÞ
* ·µ»ØÖµ £ºÎÞ
* ˵ Ã÷£ºÎÞ
****************************************************************************/
void OLED_Display_Num(u8 x,u8 y,u32 num, u8 len,u8 size)
{
u8 i=0;
u8 endisplay=0;
u8 temp=0;
for(i = 0;i < len;i++)
{
temp = (num / (OLED_POW(10,len-i-1)))%10;
if(endisplay == 0 && i < len-1)
{
if(temp == 0)
{
OLED_Display_onechar(x + (size / 2) * i,y,' ',size);
continue;
}
else
{
endisplay = 1;
}
}
OLED_Display_onechar(x + (size / 2) * i,y,temp + '0',size);
}
}
/****************************************************************************
* Ãû ³Æ£ºvoid OLED_Display_Picture(u8 x0, u8 y0, u8 x1, u8 y1, u8 BMP[])
* ¹¦ ÄÜ£ºÏÔʾһÕÅͼƬ
* Èë¿Ú²ÎÊý£º
x0 ,y0£¬x1£¬y1ͼƬµÄ´óС
BMP[] ͼƬµÄÂë
* ³ö¿Ú²ÎÊý£ºÎÞ
* ·µ»ØÖµ £ºÎÞ
* ˵ Ã÷£ºÎÞ
****************************************************************************/
void OLED_Display_Picture(u8 x0, u8 y0, u8 x1, u8 y1, u8 BMP[])
{
u8 i=0;
u8 x,y;
if(y1 == 8)
{
y= y1/ 8;
}
else
{
y = y1/ 8 + 1;
}
for(y = y0;y < y1;y++)
{
OLED_Set_Positon(x0,y);
for(x = x0;x< x1; x++)
{
OLED_Write_Operate(OLED_Mode_Data,BMP[i++]);
}
}
}
5、最后的现象
源代码:
RTT-4250.zip
(9.55 MB)
|