当掌握了编译和下载方法后,真正发挥LM4F120XL开发板用途的工作才算开始。要想学会编程,最好的方法就是看看例程,了解他人是怎么来使用的。当然在ARM中最易于着手的就是GPIO了,下面就看看闪灯程序是如何编写的,内容如下:while(1)
{
// Set the GPIO high.
GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_3, GPIO_PIN_3);
// Delay for a while.
SysCtlDelay(1000000);
// Set the GPIO low.
GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_3, 0);
// Delay for a while.
SysCtlDelay(1000000);
}
原来输出低电平是这样用:GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_3, 0); 而输出高电平则是:GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_3, GPIO_PIN_3); 延时则是这样来实现: SysCtlDelay(1000000); 下面就看看IIC接口的双色OLED屏怎样来控制,首先要确定一下连接关系,即SCLK与PD6连接,SDIN与PD3连接。这样就可以如下来定义输出电平的高低: #define OLED_SCLK_Clr() GPIOPinWrite(GPIO_PORTD_BASE, GPIO_PIN_6, 0) #define OLED_SCLK_Set() GPIOPinWrite(GPIO_PORTD_BASE, GPIO_PIN_6, GPIO_PIN_6) #define OLED_SDIN_Clr() GPIOPinWrite(GPIO_PORTD_BASE, GPIO_PIN_3, 0); #define OLED_SDIN_Set() GPIOPinWrite(GPIO_PORTD_BASE, GPIO_PIN_3, GPIO_PIN_3) ; 随后可以用下面的语句来设置PD3和PD6为输出口: SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD); SysCtlDelay(1); GPIOPinTypeGPIOOutput(GPIO_PORTD_BASE, GPIO_PIN_6|GPIO_PIN_3); 有了前面的准备工作,再配上中英文的小字库,就可以在OLED原驱动程序的基础上来实现显示功能了。 对应的OLED初始化程序如下: //SSD1306
void OLED_Init(void)
{
OLED_SCLK_Set();
OLED_SDIN_Set();
Delay_1ms(800);
OLED_WR_Byte(0xAE,OLED_CMD);//--display off
OLED_WR_Byte(0x00,OLED_CMD);//---set low column address
OLED_WR_Byte(0x10,OLED_CMD);//---set high column address
OLED_WR_Byte(0x40,OLED_CMD);//--set start line address
OLED_WR_Byte(0xB0,OLED_CMD);//--set page address
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
d OLED_WR_Byte(0xA8,OLED_CMD);//--set multiplex ratio(1 to 64)
OLED_WR_Byte(0x3F,OLED_CMD);//--1/32 duty
OLED_WR_Byte(0xC8,OLED_CMD);//Com scan direction
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(0x80,OLED_CMD);//
OLED_WR_Byte(0xD8,OLED_CMD);//set area color mode off
OLED_WR_Byte(0x05,OLED_CMD);//
OLED_WR_Byte(0xD9,OLED_CMD);//Set Pre-Charge Period
OLED_WR_Byte(0xF1,OLED_CMD);//
OLED_WR_Byte(0xDA,OLED_CMD);//set com pin configuartion
OLED_WR_Byte(0x12,OLED_CMD);//
OLED_WR_Byte(0xDB,OLED_CMD);//set Vcomh
OLED_WR_Byte(0x30,OLED_CMD);//
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
}
下图是为MP3点播器制作的界面效果,在添加键控函数和通讯函数的条件下,可以实现MP3的播放,其主程序为: int main(void)
{
// Enable the GPIO module.
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD);
SysCtlDelay(1);
// Configure PD as an output.
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD);
SysCtlDelay(1);
GPIOPinTypeGPIOOutput(GPIO_PORTD_BASE, GPIO_PIN_6|GPIO_PIN_3);
OLED_Init();
OLED_Clear();
OLED_ShowString(2,0,"mini MP3",16);
OLED_ShowCHinese(72,0,33);
OLED_ShowCHinese(90,0,34);
OLED_ShowCHinese(108,0,35);
OLED_ShowCHinese(2,2,36);
OLED_ShowCHinese(20,2,37);
OLED_ShowString(40,2,":jinglixixi",16);
OLED_ShowString(32,6,"2016.7.2",16);
while(1);
}
|