#申请原创#
在开发板上配有一个OLED屏接口,见图1所示,利用它可直接来连接一个0.96寸的准双色OLED屏。
图1 OLED接口
值得注意的是,OLED屏所用的引脚是与AT24C02所共享的!
OLED屏与开发板的具体连接关系为: SCL---PB7 SDA---PB8
所有引脚输出高低电平的定义语句为: #defineSCL_high GPIO_SetPinLevel(GPIOB,GPIO_PIN7, GPIO_LEVEL_HIGH) #defineSCL_low GPIO_SetPinLevel(GPIOB,GPIO_PIN7, GPIO_LEVEL_LOW) #defineSDA_high GPIO_SetPinLevel(GPIOB,GPIO_PIN8, GPIO_LEVEL_HIGH) #defineSDA_low GPIO_SetPinLevel(GPIOB,GPIO_PIN8, GPIO_LEVEL_LOW)
OLED屏的引脚配置函数为: void GPIO_OLEDInit(void)
{
GPIO_SetFunc(GPIOB, GPIO_PIN7, GPIO_FUN0);
GPIO_SetFunc(GPIOB, GPIO_PIN8, GPIO_FUN0);
GPIO_SetDir(GPIOB, GPIO_PIN7, GPIO_OUT);
GPIO_SetDir(GPIOB, GPIO_PIN8, GPIO_OUT);
}
OLED屏的初始化函数为: void OLED_Init(void)
{
OLED_WR_Byte(0xAE,OLED_CMD);
OLED_WR_Byte(0x02,OLED_CMD);
OLED_WR_Byte(0x10,OLED_CMD);
OLED_WR_Byte(0x40,OLED_CMD);
OLED_WR_Byte(0x81,OLED_CMD);
OLED_WR_Byte(0xff,OLED_CMD);
OLED_WR_Byte(0xA1,OLED_CMD);
OLED_WR_Byte(0xC8,OLED_CMD);
OLED_WR_Byte(0xA6,OLED_CMD);
OLED_WR_Byte(0xA8,OLED_CMD);
OLED_WR_Byte(0x3f,OLED_CMD);
OLED_WR_Byte(0xD3,OLED_CMD);
OLED_WR_Byte(0x00,OLED_CMD);
OLED_WR_Byte(0xd5,OLED_CMD);
OLED_WR_Byte(0x80,OLED_CMD);
OLED_WR_Byte(0xD9,OLED_CMD);
OLED_WR_Byte(0xF1,OLED_CMD);
OLED_WR_Byte(0xDA,OLED_CMD);
OLED_WR_Byte(0x12,OLED_CMD);
OLED_WR_Byte(0xDB,OLED_CMD);
OLED_WR_Byte(0x40,OLED_CMD);
OLED_WR_Byte(0x20,OLED_CMD);
OLED_WR_Byte(0x02,OLED_CMD);
OLED_WR_Byte(0x8D,OLED_CMD);
OLED_WR_Byte(0x14,OLED_CMD);
OLED_WR_Byte(0xA4,OLED_CMD);
OLED_WR_Byte(0xA6,OLED_CMD);
OLED_WR_Byte(0xAF,OLED_CMD);
OLED_WR_Byte(0xAF,OLED_CMD);
OLED_Clear();
OLED_Set_Pos(0,0);
}
OLED屏的清屏函数为: void OLED_Clear(void)
{
uint8_t i,n;
for(i=0;i<8;i++)
{
OLED_WR_Byte (0xb0+i,OLED_CMD);
OLED_WR_Byte (0x00,OLED_CMD);
OLED_WR_Byte (0x10,OLED_CMD);
for(n=0;n<128;n++) OLED_WR_Byte(0,OLED_DATA);
}
}
OLED屏的字符串显示函数为: 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++;
}
}
实现显示效果测试的主程序为: int main(void)
{
InitDelay();
InitDebug();
GPIO_LedInit();
TIMER_PrdInit();
GPIO_OLEDInit();
OLED_Init();
OLED_Clear();
OLED_ShowString(0,0,"AC7802x Test",16);
OLED_ShowString(0,4,"jinglixixi",16);
while (1)
{
GPIO_ToggleLedPrd();
}
}
图2 显示效果
有了显示功能,再测试开发板的其它功能就方便了许多。
|