OLED屏是一种小巧的显示器件,特别是I2C接口的OLED 屏更能节省I/O口资源。本次使用的是一款0.91'的单色OLED屏,它比常规的OLED屏要长且窄,故更适于显示信息和参数,也更适于用在便携装置上。 1. OLED屏显示 1)OLED屏与NV32F100的连接关系如下: SCL --- PE1 SDA --- PE0 2)为进行显示定义引脚输出高低电平的语句为: #defineOLED_SCLK_Clr() GPIO_PinClear(GPIO_PTE1); #defineOLED_SCLK_Set() GPIO_PinSet(GPIO_PTE1); #defineOLED_SDIN_Clr() GPIO_PinClear(GPIO_PTE0); #defineOLED_SDIN_Set() GPIO_PinSet(GPIO_PTE0); 3)OLED屏初始化函数为: void OLED_Init(void)
{
Delay_1ms(800);
OLED_WR_Byte(0xAE,OLED_CMD);//--display off
OLED_WR_Byte(0x40,OLED_CMD);//--set start line address
OLED_WR_Byte(0xB0,OLED_CMD);//--set page address
OLED_WR_Byte(0xC8,OLED_CMD);//Com scan direction
OLED_WR_Byte(0x81,OLED_CMD); // contract control
OLED_WR_Byte(0xFF,OLED_CMD);//--128
OLED_WR_Byte(0xA1,OLED_CMD);//set segment remap
OLED_WR_Byte(0xA6,OLED_CMD);//--normal / reverse
OLED_WR_Byte(0xA8,OLED_CMD);//--set multiplex ratio(1 to 64)
OLED_WR_Byte(0x1F,OLED_CMD);//--1/32 duty
OLED_WR_Byte(0xD3,OLED_CMD);//-set display offset
OLED_WR_Byte(0x00,OLED_CMD);
OLED_WR_Byte(0xD5,OLED_CMD);//set osc division
OLED_WR_Byte(0xF0,OLED_CMD);
OLED_WR_Byte(0xD9,OLED_CMD);//Set Pre-Charge Period
OLED_WR_Byte(0x22,OLED_CMD);
OLED_WR_Byte(0xDA,OLED_CMD);//set com pin configuartion
OLED_WR_Byte(0x02,OLED_CMD);
OLED_WR_Byte(0xDB,OLED_CMD);//set Vcomh
OLED_WR_Byte(0x49,OLED_CMD);//30
OLED_WR_Byte(0x8D,OLED_CMD);//set charge pump enable
OLED_WR_Byte(0x14,OLED_CMD);
OLED_WR_Byte(0xAF,OLED_CMD);//--turn on oled panel
OLED_Clear();
}
4)字符串显示函数为: void OLED_ShowChar(unsigned char x,unsigned char y,unsigned char chr,unsigned char Char_Size)
{
unsigned char c=0,i=0;
c=chr-' ';
if(x>Max_Column-1){x=0;y=y+2;}
if(Char_Size ==16)
{
OLED_Set_Pos(x,y);
for(i=0;i<8;i++)
OLED_WR_Byte(F8X16[c*16+i],OLED_DATA);
OLED_Set_Pos(x,y+1);
for(i=0;i<8;i++)
OLED_WR_Byte(F8X16[c*16+i+8],OLED_DATA);
}
else
{
OLED_Set_Pos(x,y);
for(i=0;i<6;i++)
OLED_WR_Byte(F6x8[c][i],OLED_DATA);
}
}
2. RTC计时 NV32F100提供了RTC计时器,但并未提供相关的寄存器进行计时的进制控制。为此。我们可以RTC提供的基准计时信号来自行构建进制处理。 1)以RTC进行秒计时,并利用变量ss来进行计时,所用的函数如下: void RTC_Task(void)
{
GPIO_Toggle(GPIOB, GPIO_PTE7_MASK);
ss++;
}
2)进制处理,采用如下代码: if(ss==60)
{
ss=0;
mm=mm+1;
}
if(mm==60)
{
mm=0;
hh=hh+1;
}
if(hh==24)
{
hh=0;
}
3)RTC计时主程序,其代码如下: int main (void)
{
sysinit();
cpu_identify();
RTC_ConfigType sRTCConfig;
RTC_ConfigType *pRTCConfig = &sRTCConfig;
pRTCConfig->u16ModuloValue = 9;
pRTCConfig->bInterruptEn = RTC_INTERRUPT_ENABLE;
pRTCConfig->bClockSource = RTC_CLKSRC_1KHZ;
pRTCConfig->bClockPresaler = RTC_CLK_PRESCALER_100;
RTC_SetCallback(RTC_Task);
RTC_Init(pRTCConfig);
GPIO_Init(GPIOB, GPIO_PTE7_MASK, GPIO_PinOutput);
GPIO_Init(GPIOB, GPIO_PTE7_MASK, GPIO_PinOutput);
GPIO_Init(GPIOB, GPIO_PTE0_MASK, GPIO_PinOutput);
GPIO_Init(GPIOB, GPIO_PTE1_MASK, GPIO_PinOutput);
OLED_Init();
OLED_Clear();
cd ();
while (1)
{
OLED_ShowNum(24,2,hh,2,16);
OLED_ShowChar(40,2,':',16);
OLED_ShowNum(48,2,mm,2,16);
OLED_ShowChar(64,2,':',16);
OLED_ShowNum(72,2,ss,2,16);
if(ss==60)
{
ss=0;
mm=mm+1;
}
if(mm==60)
{
mm=0;
hh=hh+1;
}
if(hh==24)
{
hh=0;
}
}
}
4)运行效果如图所示 运行效果图
|