📄 msp430_oled.c
字号:
/*********************************************
LCD
***********************************************/
#include <msp430x14x.h>
#include"stdio.h"
#include"string.h"
/*********************************************
IO口连接
***********************************************/
#define RD BIT5
#define WR BIT4
#define RES BIT2
#define DC BIT3
#define CS BIT1
/*********************************************
函数声明
***********************************************/
void Delay(unsigned int cont);
void Write(unsigned char data);
void WriteCommand(unsigned char com);
void WriteData(unsigned char dat);
void esbusini(void);
void ini_dis(void);
void lcd_int(void);
void ini_oled(void);
/******************************************************************************/
void Delay(unsigned int cont)
{
for(;cont>0;cont--);
}
/**************************实现函数********************************************
*函数原型: unsigned char ReadCommand(void);
*功 能: 从oled上读当前命令到控制器。
*******************************************************************************/
void Write(unsigned char data)
{
P4OUT = data;
}
/******************************************************************************/
void WriteCommand(unsigned char com)
{
P3OUT|=CS; //CS=1;
P3OUT&=~DC; //DC=0;
P3OUT&=~WR; //WR=0;
P3OUT|=RD; //RD=1;
P3OUT&=~CS; //CS=0;
Write(com);
P3OUT|=CS; //CS=1;
}
/**************************实现函数********************************************
*函数原型: void WriteData(unsigned dat);
*功 能: 写数据到oled显示屏。
*******************************************************************************/
void WriteData(unsigned char dat)
{
P3OUT|=CS; //CS=1;
P3OUT|=DC; //DC=1;
P3OUT&=~WR; //WR=0;
P3OUT|=RD; //RD=1;
P3OUT&=~CS; //CS=0;
Write(dat); //DAT=dat;
P3OUT|=CS; //CS=1;
}
/**************************实现函数********************************************
*函数原型: void esbusini(void);
*功 能: 总线初始化。
*******************************************************************************/
void esbusini(void)
{
P3OUT&=~RES; //RES=0;
Delay(30);
P3OUT|=RES; //RES=1;
}
/**************************实现函数********************************************
*函数原型: void ini_dis(void);
*功 能: 显示初始化。
*******************************************************************************/
void ini_dis(void)
{
unsigned char i,j;
for(i=0;i<8;i++)
{
WriteCommand (0xb0+i); //设置显示位置—行
WriteCommand (0x00); //设置显示位置—列低地址
WriteCommand (0x10); //设置显示位置—列高地址
for(j=0;j<128;j++)
WriteData(0x00); //屏幕显示,全亮
}
}
/**************************实现函数********************************************
*函数原型: lcd_nimt()
*功 能: lcd io口初始化
*******************************************************************************/
void lcd_int(void)
{
P3DIR |= 0x3e;
P3SEL &= 0xc1;
P4DIR = 0xff;
P4SEL = 0x00;
}
/*=============================================================================
//函 数 名: void ONOLED(void)
//参 数: 无
//返 回 值: 无
//函数功能: 显示开启初始化
===============================================================================*/
void ONOLED(void)
{
WriteCommand(0xAD); /* Set DC-DC */
WriteCommand(0x8B); /* 8B=ON, 8A=Off */
WriteCommand(0xdb); //设置Vcom
WriteCommand(0x35); //Vcom 0~127 当前:53 normal
WriteCommand(0xaf);
}
/**************************实现函数********************************************
*函数原型: void ini_oled(void);
*功 能: oled显示的准备工作。
*******************************************************************************/
void ini_oled(void)
{
lcd_int();
esbusini();
WriteCommand(0x00); /* Set Lower Column Address */
WriteCommand(0x10); /* Set Higher Column Address*/
WriteCommand(0x40); /* Set Display Start Line */
WriteCommand(0x81); /* Set Contrast Control */
WriteCommand(0x10); /* 0 ~ 255 */
WriteCommand(0xA0); /* [A0]:column address 0 is map*/
WriteCommand(0xA4); /* A4=ON */
WriteCommand(0XA6); /* Normal Display*/
WriteCommand(0xA8); /* Set Multiplex Ratio */
WriteCommand(0x3f); /* Set to 36 Mux*/
WriteCommand(0xAD); /* Set DC-DC */
WriteCommand(0x8A); /* 8B=ON, 8A=Off */
WriteCommand(0xAE); /* AF=ON , AE=OFF*/
WriteCommand(0xD3); /* Set Display Offset */
WriteCommand(0x00); /* No offset */
WriteCommand(0xD5); /* Set Clock Divide */
WriteCommand(0x20); /* Set to 80Hz */
WriteCommand(0xD8); /* Set Area Color On or Off*/
WriteCommand(0x00); /* Mono Mode */
WriteCommand(0xDA); /* Set Pins HardwareConfiguration */
WriteCommand(0x12);
WriteCommand(0xDB); /* Set VCOMH */
WriteCommand(0x00);
WriteCommand(0xD9); /* Set VP */
WriteCommand(0x22); /* P1=2 , P2=2 */
WriteCommand(0xc0);//配置成标准应用
ini_dis();
ONOLED();
}
void main(void)
{
ini_oled();
WriteCommand (0x40);
WriteCommand (0xb4); //设置显示位置—行
WriteCommand (0x00); //设置显示位置—列低地址
WriteCommand (0x10); //设置显示位置—列高地址
for(i=1;i<=16;i+=2)
for(j=i*16;j<16+(i*16);j++)
{
WriteData(d2[j]); //屏幕显示,全亮 d2[] 为要显示的字
}
while(1);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -