?? 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
/*********************************************
函數(shù)聲明
***********************************************/
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--);
}
/**************************實現(xiàn)函數(shù)********************************************
*函數(shù)原型: unsigned char ReadCommand(void);
*功 能: 從oled上讀當(dāng)前命令到控制器。
*******************************************************************************/
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;
}
/**************************實現(xiàn)函數(shù)********************************************
*函數(shù)原型: void WriteData(unsigned dat);
*功 能: 寫數(shù)據(jù)到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;
}
/**************************實現(xiàn)函數(shù)********************************************
*函數(shù)原型: void esbusini(void);
*功 能: 總線初始化。
*******************************************************************************/
void esbusini(void)
{
P3OUT&=~RES; //RES=0;
Delay(30);
P3OUT|=RES; //RES=1;
}
/**************************實現(xiàn)函數(shù)********************************************
*函數(shù)原型: void ini_dis(void);
*功 能: 顯示初始化。
*******************************************************************************/
void ini_dis(void)
{
unsigned char i,j;
for(i=0;i<8;i++)
{
WriteCommand (0xb0+i); //設(shè)置顯示位置—行
WriteCommand (0x00); //設(shè)置顯示位置—列低地址
WriteCommand (0x10); //設(shè)置顯示位置—列高地址
for(j=0;j<128;j++)
WriteData(0x00); //屏幕顯示,全亮
}
}
/**************************實現(xiàn)函數(shù)********************************************
*函數(shù)原型: lcd_nimt()
*功 能: lcd io口初始化
*******************************************************************************/
void lcd_int(void)
{
P3DIR |= 0x3e;
P3SEL &= 0xc1;
P4DIR = 0xff;
P4SEL = 0x00;
}
/*=============================================================================
//函 數(shù) 名: void ONOLED(void)
//參 數(shù): 無
//返 回 值: 無
//函數(shù)功能: 顯示開啟初始化
===============================================================================*/
void ONOLED(void)
{
WriteCommand(0xAD); /* Set DC-DC */
WriteCommand(0x8B); /* 8B=ON, 8A=Off */
WriteCommand(0xdb); //設(shè)置Vcom
WriteCommand(0x35); //Vcom 0~127 當(dāng)前:53 normal
WriteCommand(0xaf);
}
/**************************實現(xiàn)函數(shù)********************************************
*函數(shù)原型: void ini_oled(void);
*功 能: oled顯示的準(zhǔn)備工作。
*******************************************************************************/
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);//配置成標(biāo)準(zhǔn)應(yīng)用
ini_dis();
ONOLED();
}
void main(void)
{
ini_oled();
WriteCommand (0x40);
WriteCommand (0xb4); //設(shè)置顯示位置—行
WriteCommand (0x00); //設(shè)置顯示位置—列低地址
WriteCommand (0x10); //設(shè)置顯示位置—列高地址
for(i=1;i<=16;i+=2)
for(j=i*16;j<16+(i*16);j++)
{
WriteData(d2[j]); //屏幕顯示,全亮 d2[] 為要顯示的字
}
while(1);
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -