前言
有几天没更新了,最近一直忙着电赛,学习这个TI处理器芯片,因为我之前并没有接触过。毕竟我学的51单片机和32单片机,感觉这个16位的单片机“食之乏味,弃之可惜”,但是没办法,电赛TI公司赞助的,还是得准备准备哈哈,这里我是用CCS软件来入门的。
一、1.44寸OLED “独白”
其实相对于0.96寸OLED ,该OLED 最明显的特点就是它多出了四个接口(RES、DC、CS、BLK),同时保留了原有的接口(VCC、GND、SCL、SDA),下面讲一下接线问题:
电源接线:
VCC :接 5V
GND :接地
液晶屏数据线接线:
CS : 片选信号
SCL(CLK): SPI 时钟信号引脚
SDA(SDI) : SPI 总线数据信号引脚
液晶屏控制线接线:
BLK(LED): 背光控制信号,高电平点亮
DC(RS) : 寄存器/数据选择信号(RS=0 数据总线发送的是指令;RS=1 数据总线 发送的是像素数据)
RES(RST): 液晶屏复位信号,低电平复位
上图利用MSP430F5529实现对1.44寸OLED的驱动+显示(9只小企鹅哈哈)
后面大家可以根据自己喜欢去模后显示出来,附上文字和图片取模软件:
链接:https://pan.baidu.com/s/14uSXRJGgxpHG_FlqXhDNKQ
提取码:2580
也可以点此链接到浏览器打开:
PCtoLCD2 ()_3 次经济不等|次次要的"无政府"的"无政府之比" (baidu.com)
二、 驱动OLED 主要代码
这里代码确实比较多,我就列举一些,具体会分享出来
下面讲一下主函数:首选就是原先自带的系统时钟默认就是1MHZ,相比于32F1板的72MHZ和那肯定是不用比了,大家也可以试一下升时钟,直接运行,结果你会发现,运行速度龟速,因此升级时钟频率尤为重要,在升级时钟频率前也要先升压。
#include #include "type.h" #include "timeup.h" #include "QDTFT_demo.h" #include "Lcd_Driver.h" #include "GUI.h" #include "Picture.h" void main(void) { WDTCTL = WDTPW + WDTHOLD; upVcc();//核心电压上升 delay_ms(200); timerup();//配置时钟25MHZ delay_ms(500); Lcd_Init();//初始化 LCD_LED_SET;//通过IO控制背光亮 showimage(gImage_qq);//取模图像的代码显示企鹅 while(1) { } } 下面是关键代码: #include "msp430.h" #include "Lcd_Driver.h" #include "LCD_Config.h" //液晶IO初始化配置 void LCD_GPIO_Init(void) { LCD_SDA; LCD_RS ; LCD_CS ; LCD_RST ; LCD_SCL ; LCD_LED ; } //向SPI总线传输一个8位数据 void SPI_WriteData(u8 Data) { unsigned char i=0; for(i=8;i>0;i--) { if(Data&0x80) LCD_SDA_SET; //输出数据 else LCD_SDA_CLR; LCD_SCL_CLR; LCD_SCL_SET; Data<<=1; } } //向液晶屏写一个8位指令 void Lcd_WriteIndex(u8 Index) { //SPI 写命令时序开始 LCD_CS_CLR; LCD_RS_CLR; SPI_WriteData(Index); LCD_CS_SET; } //向液晶屏写一个8位数据 void Lcd_WriteData(u8 Data) { LCD_CS_CLR; LCD_RS_SET; SPI_WriteData(Data); LCD_CS_SET; } //向液晶屏写一个16位数据 void LCD_WriteData_16Bit(u16 Data) { LCD_CS_CLR; LCD_RS_SET; SPI_WriteData(Data>>8); //写入高8位数据 SPI_WriteData(Data); //写入低8位数据 LCD_CS_SET; } void Lcd_WriteReg(u8 Index,u8 Data) { Lcd_WriteIndex(Index); Lcd_WriteData(Data); } void Lcd_Reset(void) { LCD_RST_CLR; delay_ms(100); LCD_RST_SET; delay_ms(50); } //LCD Init For 1.44Inch LCD Panel with ST7735R. void Lcd_Init(void) { LCD_GPIO_Init(); Lcd_Reset(); //Reset before LCD Init. //LCD Init For 1.44Inch LCD Panel with ST7735R. Lcd_WriteIndex(0x11);//Sleep exit delay_ms (120); //ST7735R Frame Rate Lcd_WriteIndex(0xB1); Lcd_WriteData(0x01); Lcd_WriteData(0x2C); Lcd_WriteData(0x2D); Lcd_WriteIndex(0xB2); Lcd_WriteData(0x01); Lcd_WriteData(0x2C); Lcd_WriteData(0x2D); Lcd_WriteIndex(0xB3); Lcd_WriteData(0x01); Lcd_WriteData(0x2C); Lcd_WriteData(0x2D); Lcd_WriteData(0x01); Lcd_WriteData(0x2C); Lcd_WriteData(0x2D); Lcd_WriteIndex(0xB4); //Column inversion Lcd_WriteData(0x07); //ST7735R Power Sequence Lcd_WriteIndex(0xC0); Lcd_WriteData(0xA2); Lcd_WriteData(0x02); Lcd_WriteData(0x84); Lcd_WriteIndex(0xC1); Lcd_WriteData(0xC5); Lcd_WriteIndex(0xC2); Lcd_WriteData(0x0A); Lcd_WriteData(0x00); Lcd_WriteIndex(0xC3); Lcd_WriteData(0x8A); Lcd_WriteData(0x2A); Lcd_WriteIndex(0xC4); Lcd_WriteData(0x8A); Lcd_WriteData(0xEE); Lcd_WriteIndex(0xC5); //VCOM Lcd_WriteData(0x0E); Lcd_WriteIndex(0x36); //MX, MY, RGB mode Lcd_WriteData(0xC8); //ST7735R Gamma Sequence Lcd_WriteIndex(0xe0); Lcd_WriteData(0x0f); Lcd_WriteData(0x1a); Lcd_WriteData(0x0f); Lcd_WriteData(0x18); Lcd_WriteData(0x2f); Lcd_WriteData(0x28); Lcd_WriteData(0x20); Lcd_WriteData(0x22); Lcd_WriteData(0x1f); Lcd_WriteData(0x1b); Lcd_WriteData(0x23); Lcd_WriteData(0x37); Lcd_WriteData(0x00); Lcd_WriteData(0x07); Lcd_WriteData(0x02); Lcd_WriteData(0x10); Lcd_WriteIndex(0xe1); Lcd_WriteData(0x0f); Lcd_WriteData(0x1b); Lcd_WriteData(0x0f); Lcd_WriteData(0x17); Lcd_WriteData(0x33); Lcd_WriteData(0x2c); Lcd_WriteData(0x29); Lcd_WriteData(0x2e); Lcd_WriteData(0x30); Lcd_WriteData(0x30); Lcd_WriteData(0x39); Lcd_WriteData(0x3f); Lcd_WriteData(0x00); Lcd_WriteData(0x07); Lcd_WriteData(0x03); Lcd_WriteData(0x10); Lcd_WriteIndex(0x2a); Lcd_WriteData(0x00); Lcd_WriteData(0x00); Lcd_WriteData(0x00); Lcd_WriteData(0x7f); Lcd_WriteIndex(0x2b); Lcd_WriteData(0x00); Lcd_WriteData(0x00); Lcd_WriteData(0x00); Lcd_WriteData(0x9f); Lcd_WriteIndex(0xF0); //Enable test command Lcd_WriteData(0x01); Lcd_WriteIndex(0xF6); //Disable ram power save mode Lcd_WriteData(0x00); Lcd_WriteIndex(0x3A); //65k mode Lcd_WriteData(0x05); Lcd_WriteIndex(0x29);//Display on } /************************************************* 函数名:LCD_Set_Region 功能:设置lcd显示区域,在此区域写点数据自动换行 入口参数:xy起点和终点 返回值:无 *************************************************/ void Lcd_SetRegion(u16 x_start,u16 y_start,u16 x_end,u16 y_end) { Lcd_WriteIndex(0x2a); Lcd_WriteData(0x00); Lcd_WriteData(x_start+2); Lcd_WriteData(0x00); Lcd_WriteData(x_end+2); Lcd_WriteIndex(0x2b); Lcd_WriteData(0x00); Lcd_WriteData(y_start+3); Lcd_WriteData(0x00); Lcd_WriteData(y_end+3); Lcd_WriteIndex(0x2c); } /************************************************* 函数名:LCD_Set_XY 功能:设置lcd显示起始点 入口参数:xy坐标 返回值:无 *************************************************/ void Lcd_SetXY(u16 x,u16 y) { Lcd_SetRegion(x,y,x,y); } /************************************************* 函数名:LCD_DrawPoint 功能:画一个点 入口参数:无 返回值:无 *************************************************/ void Gui_DrawPoint(u16 x,u16 y,u16 Data) { Lcd_SetRegion(x,y,x+1,y+1); LCD_WriteData_16Bit(Data); } /***************************************** 函数功能:读TFT某一点的颜色 出口参数:color 点颜色值 ******************************************/ unsigned int Lcd_ReadPoint(u16 x,u16 y) { unsigned int Data; Lcd_SetXY(x,y); //Lcd_ReadData();//丢掉无用字节 //Data=Lcd_ReadData(); Lcd_WriteData(Data); return Data; } /************************************************* 函数名:Lcd_Clear 功能:全屏清屏函数 入口参数:填充颜色COLOR 返回值:无 *************************************************/ void Lcd_Clear(u16 Color) { unsigned int i,m; Lcd_SetRegion(0,0,X_MAX_PIXEL-1,Y_MAX_PIXEL-1); Lcd_WriteIndex(0x2C); for(i=0;i LCD_WriteData_16Bit(Color); } } 附上其头文件: #include "type.h" #define CPU_F ((double)1000000) #define delay_us(x) __delay_cycles((long)(CPU_F*(double)x/1000000.0)) #define delay_ms(x) __delay_cycles((long)(CPU_F*(double)x/1000.0)) #define RED 0xf800 #define GREEN 0x07e0 #define BLUE 0x001f #define WHITE 0xffff #define BLACK 0x0000 #define YELLOW 0xFFE0 #define GRAY0 0xEF7D //灰色0 3165 00110 001011 00101 #define GRAY1 0x8410 //灰色1 00000 000000 00000 #define GRAY2 0x4208 //灰色2 1111111111011111 #define LCD_SDA P6DIR |= BIT0 #define LCD_RS P6DIR |= BIT1 #define LCD_CS P6DIR |= BIT2 #define LCD_RST P6DIR |= BIT3 #define LCD_SCL P6DIR |= BIT4 #define LCD_LED P6DIR |= BIT5 //液晶控制口置1操作语句宏定义 #define LCD_CS_SET P6OUT |= BIT2 #define LCD_RS_SET P6OUT |= BIT1 #define LCD_SDA_SET P6OUT |= BIT0 #define LCD_SCL_SET P6OUT |= BIT4 #define LCD_RST_SET P6OUT |= BIT3 #define LCD_LED_SET P6OUT |= BIT5 //液晶控制口置0操作语句宏定义 #define LCD_CS_CLR P6OUT &=~ BIT2 #define LCD_RS_CLR P6OUT &=~ BIT1 #define LCD_SDA_CLR P6OUT &=~ BIT0 #define LCD_SCL_CLR P6OUT &=~ BIT4 #define LCD_RST_CLR P6OUT &=~ BIT3 #define LCD_LED_CLR P6OUT &=~ BIT5 void LCD_GPIO_Init(void); void Lcd_WriteIndex(u8 Index); void Lcd_WriteData(u8 Data); void Lcd_WriteReg(u8 Index,u8 Data); u16 Lcd_ReadReg(u8 LCD_Reg); void Lcd_Reset(void); void Lcd_Init(void); void Lcd_Clear(u16 Color); void Lcd_SetXY(u16 x,u16 y); void Gui_DrawPoint(u16 x,u16 y,u16 Data); unsigned int Lcd_ReadPoint(u16 x,u16 y); void Lcd_SetRegion(u16 x_start,u16 y_start,u16 x_end,u16 y_end); void LCD_WriteData_16Bit(u16 Data); 具体接线在上面头文件已经声明了,这个代码大家简单修改就可以直接上手了 代码确实会比较多,因此我就不再一一列举 这个代码也是在STM32基础上改造出来的,32的代码有时间再写一份,其实原理都是差不多的。 大家也可以根据自己实际情况再加以修改。 三、取模使用与总结 开门见山: 取好这些选项,就可以开始取模了,其他的哪里不明白欢迎随时评论,一起探讨交流! 觉得有用的话点个赞再走呗! 四、代码链接 链接:https://pan.baidu.com/s/1qhu37QGhI8jmy8sGuwZn_g 提取码:2580
上一篇:MSP430F5529之超声波测距+OLED 显示
下一篇:使用MSP430F5529的ADC测量,并用OLED显示传感器输出的模拟量
推荐阅读最新更新时间:2024-11-12 11:50
设计资源 培训 开发板 精华推荐
- Purple Pi开发板
- 桌面时钟小熊款(协会培训参考案例)
- ADP2166-EVALZ,用于评估 ADP2166 降压稳压器的评估板
- MC33074ADTBR2G快速建立逆变器的典型应用
- TDA8763M-12位高速A/D转换器演示板
- STEVAL-ISB003V1,基于USB锂离子电池充电器的演示板,基于微控制器ST7260E2
- 【P2009006-1】0.96‘OLED显示模块IIC接口
- LT1085CT-12、12V/7.5A 电池后备稳压电源的典型应用电路
- DC1532A-H,LTC2267-12 演示板,12 位,105 Msps,1.8V 双串行 ADC,5MHz
- 有线网络的以太网接口