MSP430F149的OLED驱动(硬件SPI)

谁都会走 提交于 2020-01-17 00:43:52


简单的显示图片、ASCII、数字。文字字库太大,懒得写,道理都是一样的。。。
OLED程序在下面 可以直接跳过前面的程序,直接跳入“OLED驱动”程序
具体原理其他博主都有介绍,可以参考其它文章,我就直接上代码了…

试验主程序

main.c

#include "OLED_SPI.h"
int main( void )
{
  // Stop watchdog timer to prevent time out reset
  WDTCTL = WDTPW + WDTHOLD;
  CLK_Init();//初始化时钟
  OLED_GPIO_init();//初始化SPI
  OLED_init();//OLED初始化
  OLED_clear();//清屏
  OLED_bmp();//显示图片
  OLED_4_8_number(2,30,1);//显示149
  OLED_4_8_number(2,35,4);
  OLED_4_8_number(2,40,9);
  OLED_8_16_ASCII(4,0,10,"Vice Versa");
  return 0;
}

辅助程序

可有可无,不要的话就把main.c的初始化程序删掉。但是推荐有这个程序。

msp430f149_init.c

#include "msp430f149_init.h"
/**************************************
函数名: XT2_Init
参  数: 无
返回值: 无
功  能: 初始化XT2时钟源,选择主、辅时钟
**************************************/
void CLK_Init()
{
  u8 i;
  BCSCTL1 &= ~XT2OFF;
  do
  {
    IFG1 &= ~OFIFG;
    for(i=0xff;i;i--);
  }while(IFG1&OFIFG);
  BCSCTL2 |= SELM_2 | SELS;//MCLK和SMCLK选择XT2
}

msp430f149_init.h

#ifndef __msp430f149_init_H__
#define __msp430f149_init_H__
//---------------------------------------
#include <msp430f149.h>
//---------------------------------------
typedef unsigned char u8;
typedef unsigned int u16;
typedef unsigned long u32;
//---------------------------------------
void CLK_Init();//初始化XT2时钟源,设置时钟选择

#endif

OLED驱动

由于使用XT2时钟源为硬件SPI提供时钟,因此需配合上面的文件
如果没有辅助程序(msp430f149_init.c)的话,在OLED_SPI.h里需要加入#include<msp430f149.h>

OLED_SPI.c

#include "OLED_SPI.h"
/*******************************************
//                       MSP430F149
//                ^  -----------------
//               /|\|                 |
//                | |                 |
//        RC522   --|RST              |
// ┌-----------┐    |                 |
// | _____     |    |                 |
// ||     |  CS|<---|P3.0/CS          |
// ||     |MOSI|<---|P3.1/MOSI        |
// ||     |  DC|--->|P3.2/DC          |
// ||     | CLK|<---|P3.3/CLK         |
// ||_____| RES|<---|P3.4/RES         |
// |___________|    |                 |
*******************************************/

const u8 bmp[],ASCII[],number[];
/**************************************
函数名: OLED_GPIO_init
参  数: 无
返回值: 无
功  能: 初始化SPI参数及其引脚设置
**************************************/
void OLED_GPIO_init()
{
  P3SEL |= 0x0a;//P3.0 CS       P3.1 MOSI     P3.2 DC       P3.3 CLK
  P3OUT |= 0x01;
  P3DIR |= BIT0 | BIT2 | BIT4;
  ME1 |= USPIE0;
  U0CTL = SWRST | CHAR | SYNC | MM;// | LISTEN
  U0TCTL = CKPL | SSEL1 | STC;
  U0BR0=0x10;
  U0BR1=0x00;
  U0MCTL=0;
  U0CTL &= ~SWRST;
}
/**************************************
函数名: OLED_byte
参  数: 要传送的字节
返回值: 无
功  能: 以SPI协议发送字节(需要CS变化别忘了加SendComplete();)
**************************************/
void OLED_byte(u8 byte)
{
  while(!(IFG1&UTXIFG0));
  U0TXBUF = byte;
}
/**************************************
函数名: OLED_init
参  数: 无
返回值: 无
功  能: 初始化OLED,设置参数
**************************************/
void OLED_init()//高位在下
{
  OLED_RES_0;
  __delay_cycles(10000);
  OLED_RES_1;
  OLED_CS_0;
  OLED_DC_0;
  OLED_byte(0xAE);//AE关闭显示      AF开启显示
  OLED_byte(0xA7);//A6正常显示      A7反白显示
  OLED_byte(0xA4);//A4跟随RAM       A5点亮全部像素
  OLED_byte(0x20);//开始设置寻址模式
  OLED_byte(0x02);//x00水平寻址      x01垂直寻址    x02页寻址    x03无效
  OLED_byte(0x81);//设置对比控制寄存器
  OLED_byte(0xff);
  OLED_byte(0x21);//设置列地址开始和结束
  OLED_byte(0x00);//设置列开始
  OLED_byte(0x7F);//设置列结束
  OLED_byte(0x22);//设置页的开始结束
  OLED_byte(0x00);//设置页的开始
  OLED_byte(0x07);//设置页的结束
  OLED_byte(0x40);//设置开始行
  OLED_byte(0xA1);//写入顺序A0 0~127        A1 127~0//水平翻转
  OLED_byte(0xA8);//多路复用率
  OLED_byte(0x3F);
  OLED_byte(0xC8);//C0正常显示      C8垂直翻转
  OLED_byte(0xD3);//垂直行偏移量(0~64)
  OLED_byte(0x00);
  OLED_byte(0xDA);//设置端口硬件配置
  OLED_byte(0x12);//0x12 0~128
  OLED_byte(0xD5);//时钟分频系数
  OLED_byte(0xF0);//
  OLED_byte(0xD9);//预充电周期
  OLED_byte(0x22);//
  OLED_byte(0xDB);//设置电压
  OLED_byte(0x20);//0x20 0.77*Vcc       0x30 0.83*Vcc
  OLED_byte(0x8d); //DC-DC使能 电荷泵
  OLED_byte(0x14); //
  OLED_byte(0xAF);//开显示
  SendComplete();
  OLED_CS_1;
}
/**************************************
函数名: OLED_clear
参  数: 无
返回值: 无
功  能: 清屏
**************************************/
void OLED_clear()
{
  u8 i,j;
  OLED_CS_0;
  for(i=0;i<8;i++)
  {
    OLED_DC_0;//cmd
    OLED_byte(0xb0|i);
    OLED_byte(0x10);
    OLED_byte(0x00);
    SendComplete();
    OLED_DC_1;//data
    for(j=0;j<128;j++)
      OLED_byte(0x00);
    SendComplete();
  }
  OLED_CS_1;
}
/**************************************
函数名: OLED_bmp
参  数: 无
返回值: 无
功  能: 显示图片
**************************************/
void OLED_bmp()
{
  u8 i,j;
  OLED_CS_0;
  for(i=0;i<8;i++)
  {
    OLED_DC_0;//cmd
    OLED_byte(0xb0|i);
    OLED_byte(0x10);
    OLED_byte(0x00);
    SendComplete();
    OLED_DC_1;//data
    for(j=0;j<128;j++)
      OLED_byte(bmp[i*128+j]);
    SendComplete();
  }
  OLED_CS_1;
}
/**************************************
函数名: OLED_8_16_ASCII
参  数: 所在页,所在列,字符串长度,要显示的字符串
返回值: 无
功  能: 显示8*16像素的ASCII文字
**************************************/
void OLED_8_16_ASCII(u8 page,u8 lie,u8 amount,u8 *ascii)
{
  u8 i,j;
  OLED_CS_0;
  OLED_DC_0;
  OLED_byte(0xb0+page);
  OLED_byte((lie>>4)|0x10);
  OLED_byte(lie&0x0f);
  SendComplete();
  OLED_DC_1;
  for(i=amount;i;i--)
  {
    for(j=0;j<8;j++)
      OLED_byte(ASCII[(*ascii-0x20)*16+j]);
    ascii++;
  }
  SendComplete();
  ascii-=amount;
  OLED_DC_0;
  OLED_byte(0xb1+page);
  OLED_byte((lie>>4)|0x10);
  OLED_byte(lie&0x0f);
  SendComplete();
  OLED_DC_1;
  for(i=amount;i;i--)
  {
    for(j=8;j<16;j++)
      OLED_byte(ASCII[(*ascii-0x20)*16+j]);
    ascii++;
  }
  SendComplete();
  OLED_CS_1;
}
/**************************************
函数名: OLED_4_8_number
参  数: 所在页,所在列,要显示的数字
返回值: 无
功  能: 显示4*8像素的数字
**************************************/
void OLED_4_8_number(u8 page,u8 lie,u8 num)
{
  u8 i;
  OLED_CS_0;
  OLED_DC_0;
  OLED_byte(0xb0+page);
  OLED_byte((lie>>4)|0x10);
  OLED_byte(lie&0x0f);
  SendComplete();
  OLED_DC_1;
  for(i=0;i<4;i++)
    OLED_byte(number[num*4+i]);
  SendComplete();
  OLED_CS_1;
}

const u8 number[]={
0x7C,0x82,0x82,0x7C,0x00,0x84,0xFE,0x80,0xC4,0xA2,0x92,0x8C,
0x44,0x92,0x92,0x6C,0x30,0xAC,0xFE,0xA0,0x4E,0x8A,0x8A,0x72,
0x7C,0x92,0x92,0x64,0x06,0xF2,0x0A,0x06,0x6C,0x92,0x92,0x6C,
0x4C,0x92,0x92,0x7C,0xFC,0x12,0x12,0xFC,0xFE,0x92,0x92,0x6C,
0x7C,0x82,0x82,0x44,0xFE,0x82,0x82,0x7C,0xFE,0x92,0x92,0x92,
0xFE,0x12,0x12,0x12};
const u8 bmp[]={
0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
0X00,0X00,0X00,0X00,0X00,0X00,0XC0,0XF8,0XFC,0XFE,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,
0X7F,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,
0XFF,0XFF,0XFF,0XFF,0XFE,0XF8,0XE0,0X80,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
0X00,0X00,0X00,0X00,0X00,0X00,0X7F,0XFB,0XFF,0XFF,0XDF,0X3E,0X3F,0X3F,0X3F,0X5F,
0X7F,0XFF,0XFF,0X3F,0X33,0XE7,0XF7,0X1F,0X0F,0X1F,0X3F,0X3F,0XFF,0XFF,0XFF,0X3F,
0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XF8,0X00,0X00,0X04,0X00,0X00,0X00,0X00,
0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X30,0XFF,0XFF,0XFF,0X8B,0X00,0XC0,0XC0,
0XC0,0XC1,0X01,0X03,0X00,0X7F,0XFF,0X00,0X00,0X00,0XC0,0X70,0X77,0XF3,0XFC,0XFE,
0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0X7C,0XF8,0XE0,0X00,0X00,0X00,
0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
0X00,0X00,0X00,0XC0,0X80,0X00,0XF0,0X7F,0X90,0X77,0X1F,0XFF,0XFF,0XFE,0XFC,0XF9,
0XF1,0XF0,0XF0,0XF8,0XF8,0XF8,0XFF,0XFF,0X7E,0X3F,0X0E,0X03,0X8F,0XDF,0XFF,0XFF,
0XFF,0X7F,0XBF,0XFF,0XFF,0XFF,0X7F,0XFF,0XFF,0XFF,0X30,0X1F,0X0F,0X00,0X00,0X00,
0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
0X00,0X0C,0XFC,0X2F,0X6E,0XDD,0X92,0X07,0X19,0X07,0X1B,0X06,0XF5,0XD7,0X15,0X8B,
0X17,0X0F,0X85,0X27,0XDA,0X07,0X07,0X3F,0X28,0X20,0X12,0X93,0X71,0X37,0X1F,0X19,
0X0A,0X17,0X0F,0X11,0X64,0X86,0X07,0X03,0X01,0X00,0X40,0X00,0X00,0X00,0X00,0X00,
0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
0X00,0X00,0XFF,0X00,0X00,0X22,0XFD,0X00,0X00,0X00,0X00,0X20,0XCF,0XE0,0XF0,0XF8,
0XFC,0XFC,0XF3,0XF1,0XE0,0XE0,0XC0,0XC0,0XC0,0XF0,0X9E,0X81,0X00,0X00,0X00,0X00,
0X00,0X00,0X00,0X00,0X00,0X03,0XFC,0X00,0X00,0X00,0X00,0X40,0X00,0X00,0X00,0X00,
0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
0X00,0X00,0X3F,0X80,0X00,0X00,0X00,0X0F,0X70,0X80,0X00,0X00,0X01,0X0F,0X3E,0XFF,
0XFF,0XC7,0XBF,0XDF,0XEF,0X7B,0XBE,0XFF,0XFB,0XFF,0XFB,0XFD,0XFB,0XBF,0XDE,0XFE,
0XFE,0XFE,0XFE,0XFE,0XFF,0XFF,0X7F,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
0X00,0X00,0X00,0X03,0X0C,0X30,0X40,0X40,0X40,0X6F,0X3C,0X60,0X80,0X00,0X00,0X00,
0X01,0X07,0X0F,0X1F,0X3E,0X7F,0XFF,0XFF,0XFD,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,
0XFF,0XFF,0XFF,0XFF,0X3F,0X07,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
};
const u8 ASCII[]={
/*--  宋体12;  此字体下对应的点阵为:宽x高=8x16   --*/
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,

/*--  文字:  !  --*/
/*--  宋体12;  此字体下对应的点阵为:宽x高=8x16   --*/
0x00,0x00,0x00,0xF8,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x33,0x30,0x00,0x00,0x00,

/*--  文字:  "  --*/
/*--  宋体12;  此字体下对应的点阵为:宽x高=8x16   --*/
0x00,0x10,0x0C,0x06,0x10,0x0C,0x06,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,

/*--  文字:  #  --*/
/*--  宋体12;  此字体下对应的点阵为:宽x高=8x16   --*/
0x40,0xC0,0x78,0x40,0xC0,0x78,0x40,0x00,0x04,0x3F,0x04,0x04,0x3F,0x04,0x04,0x00,

/*--  文字:  $  --*/
/*--  宋体12;  此字体下对应的点阵为:宽x高=8x16   --*/
0x00,0x70,0x88,0xFC,0x08,0x30,0x00,0x00,0x00,0x18,0x20,0xFF,0x21,0x1E,0x00,0x00,

/*--  文字:  %  --*/
/*--  宋体12;  此字体下对应的点阵为:宽x高=8x16   --*/
0xF0,0x08,0xF0,0x00,0xE0,0x18,0x00,0x00,0x00,0x21,0x1C,0x03,0x1E,0x21,0x1E,0x00,

/*--  文字:  &  --*/
/*--  宋体12;  此字体下对应的点阵为:宽x高=8x16   --*/
0x00,0xF0,0x08,0x88,0x70,0x00,0x00,0x00,0x1E,0x21,0x23,0x24,0x19,0x27,0x21,0x10,

/*--  文字:  '  --*/
/*--  宋体12;  此字体下对应的点阵为:宽x高=8x16   --*/
0x10,0x16,0x0E,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,

/*--  文字:  (  --*/
/*--  宋体12;  此字体下对应的点阵为:宽x高=8x16   --*/
0x00,0x00,0x00,0xE0,0x18,0x04,0x02,0x00,0x00,0x00,0x00,0x07,0x18,0x20,0x40,0x00,

/*--  文字:  )  --*/
/*--  宋体12;  此字体下对应的点阵为:宽x高=8x16   --*/
0x00,0x02,0x04,0x18,0xE0,0x00,0x00,0x00,0x00,0x40,0x20,0x18,0x07,0x00,0x00,0x00,

/*--  文字:  *  --*/
/*--  宋体12;  此字体下对应的点阵为:宽x高=8x16   --*/
0x40,0x40,0x80,0xF0,0x80,0x40,0x40,0x00,0x02,0x02,0x01,0x0F,0x01,0x02,0x02,0x00,

/*--  文字:  +  --*/
/*--  宋体12;  此字体下对应的点阵为:宽x高=8x16   --*/
0x00,0x00,0x00,0xF0,0x00,0x00,0x00,0x00,0x01,0x01,0x01,0x1F,0x01,0x01,0x01,0x00,

/*--  文字:  ,  --*/
/*--  宋体12;  此字体下对应的点阵为:宽x高=8x16   --*/
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0xB0,0x70,0x00,0x00,0x00,0x00,0x00,

/*--  文字:  -  --*/
/*--  宋体12;  此字体下对应的点阵为:宽x高=8x16   --*/
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x01,0x01,0x01,0x01,0x01,0x01,

/*--  文字:  .  --*/
/*--  宋体12;  此字体下对应的点阵为:宽x高=8x16   --*/
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x30,0x30,0x00,0x00,0x00,0x00,0x00,

/*--  文字:  /  --*/
/*--  宋体12;  此字体下对应的点阵为:宽x高=8x16   --*/
0x00,0x00,0x00,0x00,0x80,0x60,0x18,0x04,0x00,0x60,0x18,0x06,0x01,0x00,0x00,0x00,

/*--  文字:  0  --*/
/*--  宋体12;  此字体下对应的点阵为:宽x高=8x16   --*/
0x00,0xE0,0x10,0x08,0x08,0x10,0xE0,0x00,0x00,0x0F,0x10,0x20,0x20,0x10,0x0F,0x00,

/*--  文字:  1  --*/
/*--  宋体12;  此字体下对应的点阵为:宽x高=8x16   --*/
0x00,0x10,0x10,0xF8,0x00,0x00,0x00,0x00,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00,

/*--  文字:  2  --*/
/*--  宋体12;  此字体下对应的点阵为:宽x高=8x16   --*/
0x00,0x70,0x08,0x08,0x08,0x88,0x70,0x00,0x00,0x30,0x28,0x24,0x22,0x21,0x30,0x00,

/*--  文字:  3  --*/
/*--  宋体12;  此字体下对应的点阵为:宽x高=8x16   --*/
0x00,0x30,0x08,0x88,0x88,0x48,0x30,0x00,0x00,0x18,0x20,0x20,0x20,0x11,0x0E,0x00,

/*--  文字:  4  --*/
/*--  宋体12;  此字体下对应的点阵为:宽x高=8x16   --*/
0x00,0x00,0xC0,0x20,0x10,0xF8,0x00,0x00,0x00,0x07,0x04,0x24,0x24,0x3F,0x24,0x00,

/*--  文字:  5  --*/
/*--  宋体12;  此字体下对应的点阵为:宽x高=8x16   --*/
0x00,0xF8,0x08,0x88,0x88,0x08,0x08,0x00,0x00,0x19,0x21,0x20,0x20,0x11,0x0E,0x00,

/*--  文字:  6  --*/
/*--  宋体12;  此字体下对应的点阵为:宽x高=8x16   --*/
0x00,0xE0,0x10,0x88,0x88,0x18,0x00,0x00,0x00,0x0F,0x11,0x20,0x20,0x11,0x0E,0x00,

/*--  文字:  7  --*/
/*--  宋体12;  此字体下对应的点阵为:宽x高=8x16   --*/
0x00,0x38,0x08,0x08,0xC8,0x38,0x08,0x00,0x00,0x00,0x00,0x3F,0x00,0x00,0x00,0x00,

/*--  文字:  8  --*/
/*--  宋体12;  此字体下对应的点阵为:宽x高=8x16   --*/
0x00,0x70,0x88,0x08,0x08,0x88,0x70,0x00,0x00,0x1C,0x22,0x21,0x21,0x22,0x1C,0x00,

/*--  文字:  9  --*/
/*--  宋体12;  此字体下对应的点阵为:宽x高=8x16   --*/
0x00,0xE0,0x10,0x08,0x08,0x10,0xE0,0x00,0x00,0x00,0x31,0x22,0x22,0x11,0x0F,0x00,

/*--  文字:  :  --*/
/*--  宋体12;  此字体下对应的点阵为:宽x高=8x16   --*/
0x00,0x00,0x00,0xC0,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x30,0x30,0x00,0x00,0x00,

/*--  文字:  ;  --*/
/*--  宋体12;  此字体下对应的点阵为:宽x高=8x16   --*/
0x00,0x00,0x00,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0x60,0x00,0x00,0x00,0x00,

/*--  文字:  <  --*/
/*--  宋体12;  此字体下对应的点阵为:宽x高=8x16   --*/
0x00,0x00,0x80,0x40,0x20,0x10,0x08,0x00,0x00,0x01,0x02,0x04,0x08,0x10,0x20,0x00,

/*--  文字:  =  --*/
/*--  宋体12;  此字体下对应的点阵为:宽x高=8x16   --*/
0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x00,0x04,0x04,0x04,0x04,0x04,0x04,0x04,0x00,

/*--  文字:  >  --*/
/*--  宋体12;  此字体下对应的点阵为:宽x高=8x16   --*/
0x00,0x08,0x10,0x20,0x40,0x80,0x00,0x00,0x00,0x20,0x10,0x08,0x04,0x02,0x01,0x00,

/*--  文字:  ?  --*/
/*--  宋体12;  此字体下对应的点阵为:宽x高=8x16   --*/
0x00,0x70,0x48,0x08,0x08,0x08,0xF0,0x00,0x00,0x00,0x00,0x30,0x36,0x01,0x00,0x00,

/*--  文字:  @  --*/
/*--  宋体12;  此字体下对应的点阵为:宽x高=8x16   --*/
0xC0,0x30,0xC8,0x28,0xE8,0x10,0xE0,0x00,0x07,0x18,0x27,0x24,0x23,0x14,0x0B,0x00,

/*--  文字:  A  --*/
/*--  宋体12;  此字体下对应的点阵为:宽x高=8x16   --*/
0x00,0x00,0xC0,0x38,0xE0,0x00,0x00,0x00,0x20,0x3C,0x23,0x02,0x02,0x27,0x38,0x20,

/*--  文字:  B  --*/
/*--  宋体12;  此字体下对应的点阵为:宽x高=8x16   --*/
0x08,0xF8,0x88,0x88,0x88,0x70,0x00,0x00,0x20,0x3F,0x20,0x20,0x20,0x11,0x0E,0x00,

/*--  文字:  C  --*/
/*--  宋体12;  此字体下对应的点阵为:宽x高=8x16   --*/
0xC0,0x30,0x08,0x08,0x08,0x08,0x38,0x00,0x07,0x18,0x20,0x20,0x20,0x10,0x08,0x00,

/*--  文字:  D  --*/
/*--  宋体12;  此字体下对应的点阵为:宽x高=8x16   --*/
0x08,0xF8,0x08,0x08,0x08,0x10,0xE0,0x00,0x20,0x3F,0x20,0x20,0x20,0x10,0x0F,0x00,

/*--  文字:  E  --*/
/*--  宋体12;  此字体下对应的点阵为:宽x高=8x16   --*/
0x08,0xF8,0x88,0x88,0xE8,0x08,0x10,0x00,0x20,0x3F,0x20,0x20,0x23,0x20,0x18,0x00,

/*--  文字:  F  --*/
/*--  宋体12;  此字体下对应的点阵为:宽x高=8x16   --*/
0x08,0xF8,0x88,0x88,0xE8,0x08,0x10,0x00,0x20,0x3F,0x20,0x00,0x03,0x00,0x00,0x00,

/*--  文字:  G  --*/
/*--  宋体12;  此字体下对应的点阵为:宽x高=8x16   --*/
0xC0,0x30,0x08,0x08,0x08,0x38,0x00,0x00,0x07,0x18,0x20,0x20,0x22,0x1E,0x02,0x00,

/*--  文字:  H  --*/
/*--  宋体12;  此字体下对应的点阵为:宽x高=8x16   --*/
0x08,0xF8,0x08,0x00,0x00,0x08,0xF8,0x08,0x20,0x3F,0x21,0x01,0x01,0x21,0x3F,0x20,

/*--  文字:  I  --*/
/*--  宋体12;  此字体下对应的点阵为:宽x高=8x16   --*/
0x00,0x08,0x08,0xF8,0x08,0x08,0x00,0x00,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00,

/*--  文字:  J  --*/
/*--  宋体12;  此字体下对应的点阵为:宽x高=8x16   --*/
0x00,0x00,0x08,0x08,0xF8,0x08,0x08,0x00,0xC0,0x80,0x80,0x80,0x7F,0x00,0x00,0x00,

/*--  文字:  K  --*/
/*--  宋体12;  此字体下对应的点阵为:宽x高=8x16   --*/
0x08,0xF8,0x88,0xC0,0x28,0x18,0x08,0x00,0x20,0x3F,0x20,0x01,0x26,0x38,0x20,0x00,

/*--  文字:  L  --*/
/*--  宋体12;  此字体下对应的点阵为:宽x高=8x16   --*/
0x08,0xF8,0x08,0x00,0x00,0x00,0x00,0x00,0x20,0x3F,0x20,0x20,0x20,0x20,0x30,0x00,

/*--  文字:  M  --*/
/*--  宋体12;  此字体下对应的点阵为:宽x高=8x16   --*/
0x08,0xF8,0xF8,0x00,0xF8,0xF8,0x08,0x00,0x20,0x3F,0x00,0x3F,0x00,0x3F,0x20,0x00,

/*--  文字:  N  --*/
/*--  宋体12;  此字体下对应的点阵为:宽x高=8x16   --*/
0x08,0xF8,0x30,0xC0,0x00,0x08,0xF8,0x08,0x20,0x3F,0x20,0x00,0x07,0x18,0x3F,0x00,

/*--  文字:  O  --*/
/*--  宋体12;  此字体下对应的点阵为:宽x高=8x16   --*/
0xE0,0x10,0x08,0x08,0x08,0x10,0xE0,0x00,0x0F,0x10,0x20,0x20,0x20,0x10,0x0F,0x00,

/*--  文字:  P  --*/
/*--  宋体12;  此字体下对应的点阵为:宽x高=8x16   --*/
0x08,0xF8,0x08,0x08,0x08,0x08,0xF0,0x00,0x20,0x3F,0x21,0x01,0x01,0x01,0x00,0x00,

/*--  文字:  Q  --*/
/*--  宋体12;  此字体下对应的点阵为:宽x高=8x16   --*/
0xE0,0x10,0x08,0x08,0x08,0x10,0xE0,0x00,0x0F,0x18,0x24,0x24,0x38,0x50,0x4F,0x00,

/*--  文字:  R  --*/
/*--  宋体12;  此字体下对应的点阵为:宽x高=8x16   --*/
0x08,0xF8,0x88,0x88,0x88,0x88,0x70,0x00,0x20,0x3F,0x20,0x00,0x03,0x0C,0x30,0x20,

/*--  文字:  S  --*/
/*--  宋体12;  此字体下对应的点阵为:宽x高=8x16   --*/
0x00,0x70,0x88,0x08,0x08,0x08,0x38,0x00,0x00,0x38,0x20,0x21,0x21,0x22,0x1C,0x00,

/*--  文字:  T  --*/
/*--  宋体12;  此字体下对应的点阵为:宽x高=8x16   --*/
0x18,0x08,0x08,0xF8,0x08,0x08,0x18,0x00,0x00,0x00,0x20,0x3F,0x20,0x00,0x00,0x00,

/*--  文字:  U  --*/
/*--  宋体12;  此字体下对应的点阵为:宽x高=8x16   --*/
0x08,0xF8,0x08,0x00,0x00,0x08,0xF8,0x08,0x00,0x1F,0x20,0x20,0x20,0x20,0x1F,0x00,

/*--  文字:  V  --*/
/*--  宋体12;  此字体下对应的点阵为:宽x高=8x16   --*/
0x08,0x78,0x88,0x00,0x00,0xC8,0x38,0x08,0x00,0x00,0x07,0x38,0x0E,0x01,0x00,0x00,

/*--  文字:  W  --*/
/*--  宋体12;  此字体下对应的点阵为:宽x高=8x16   --*/
0xF8,0x08,0x00,0xF8,0x00,0x08,0xF8,0x00,0x03,0x3C,0x07,0x00,0x07,0x3C,0x03,0x00,

/*--  文字:  X  --*/
/*--  宋体12;  此字体下对应的点阵为:宽x高=8x16   --*/
0x08,0x18,0x68,0x80,0x80,0x68,0x18,0x08,0x20,0x30,0x2C,0x03,0x03,0x2C,0x30,0x20,

/*--  文字:  Y  --*/
/*--  宋体12;  此字体下对应的点阵为:宽x高=8x16   --*/
0x08,0x38,0xC8,0x00,0xC8,0x38,0x08,0x00,0x00,0x00,0x20,0x3F,0x20,0x00,0x00,0x00,

/*--  文字:  Z  --*/
/*--  宋体12;  此字体下对应的点阵为:宽x高=8x16   --*/
0x10,0x08,0x08,0x08,0xC8,0x38,0x08,0x00,0x20,0x38,0x26,0x21,0x20,0x20,0x18,0x00,

/*--  文字:  [  --*/
/*--  宋体12;  此字体下对应的点阵为:宽x高=8x16   --*/
0x00,0x00,0x00,0xFE,0x02,0x02,0x02,0x00,0x00,0x00,0x00,0x7F,0x40,0x40,0x40,0x00,

/*--  文字:  \  --*/
/*--  宋体12;  此字体下对应的点阵为:宽x高=8x16   --*/
0x00,0x0C,0x30,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x06,0x38,0xC0,0x00,

/*--  文字:  ]  --*/
/*--  宋体12;  此字体下对应的点阵为:宽x高=8x16   --*/
0x00,0x02,0x02,0x02,0xFE,0x00,0x00,0x00,0x00,0x40,0x40,0x40,0x7F,0x00,0x00,0x00,

/*--  文字:  ^  --*/
/*--  宋体12;  此字体下对应的点阵为:宽x高=8x16   --*/
0x00,0x00,0x04,0x02,0x02,0x02,0x04,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,

/*--  文字:  _  --*/
/*--  宋体12;  此字体下对应的点阵为:宽x高=8x16   --*/
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,

/*--  文字:  `  --*/
/*--  宋体12;  此字体下对应的点阵为:宽x高=8x16   --*/
0x00,0x02,0x02,0x04,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,

/*--  文字:  a  --*/
/*--  宋体12;  此字体下对应的点阵为:宽x高=8x16   --*/
0x00,0x00,0x80,0x80,0x80,0x80,0x00,0x00,0x00,0x19,0x24,0x22,0x22,0x22,0x3F,0x20,

/*--  文字:  b  --*/
/*--  宋体12;  此字体下对应的点阵为:宽x高=8x16   --*/
0x08,0xF8,0x00,0x80,0x80,0x00,0x00,0x00,0x00,0x3F,0x11,0x20,0x20,0x11,0x0E,0x00,

/*--  文字:  c  --*/
/*--  宋体12;  此字体下对应的点阵为:宽x高=8x16   --*/
0x00,0x00,0x00,0x80,0x80,0x80,0x00,0x00,0x00,0x0E,0x11,0x20,0x20,0x20,0x11,0x00,

/*--  文字:  d  --*/
/*--  宋体12;  此字体下对应的点阵为:宽x高=8x16   --*/
0x00,0x00,0x00,0x80,0x80,0x88,0xF8,0x00,0x00,0x0E,0x11,0x20,0x20,0x10,0x3F,0x20,

/*--  文字:  e  --*/
/*--  宋体12;  此字体下对应的点阵为:宽x高=8x16   --*/
0x00,0x00,0x80,0x80,0x80,0x80,0x00,0x00,0x00,0x1F,0x22,0x22,0x22,0x22,0x13,0x00,

/*--  文字:  f  --*/
/*--  宋体12;  此字体下对应的点阵为:宽x高=8x16   --*/
0x00,0x80,0x80,0xF0,0x88,0x88,0x88,0x18,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00,

/*--  文字:  g  --*/
/*--  宋体12;  此字体下对应的点阵为:宽x高=8x16   --*/
0x00,0x00,0x80,0x80,0x80,0x80,0x80,0x00,0x00,0x6B,0x94,0x94,0x94,0x93,0x60,0x00,

/*--  文字:  h  --*/
/*--  宋体12;  此字体下对应的点阵为:宽x高=8x16   --*/
0x08,0xF8,0x00,0x80,0x80,0x80,0x00,0x00,0x20,0x3F,0x21,0x00,0x00,0x20,0x3F,0x20,

/*--  文字:  i  --*/
/*--  宋体12;  此字体下对应的点阵为:宽x高=8x16   --*/
0x00,0x80,0x98,0x98,0x00,0x00,0x00,0x00,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00,

/*--  文字:  j  --*/
/*--  宋体12;  此字体下对应的点阵为:宽x高=8x16   --*/
0x00,0x00,0x00,0x80,0x98,0x98,0x00,0x00,0x00,0xC0,0x80,0x80,0x80,0x7F,0x00,0x00,

/*--  文字:  k  --*/
/*--  宋体12;  此字体下对应的点阵为:宽x高=8x16   --*/
0x08,0xF8,0x00,0x00,0x80,0x80,0x80,0x00,0x20,0x3F,0x24,0x02,0x2D,0x30,0x20,0x00,

/*--  文字:  l  --*/
/*--  宋体12;  此字体下对应的点阵为:宽x高=8x16   --*/
0x00,0x08,0x08,0xF8,0x00,0x00,0x00,0x00,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00,

/*--  文字:  m  --*/
/*--  宋体12;  此字体下对应的点阵为:宽x高=8x16   --*/
0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x00,0x20,0x3F,0x20,0x00,0x3F,0x20,0x00,0x3F,

/*--  文字:  n  --*/
/*--  宋体12;  此字体下对应的点阵为:宽x高=8x16   --*/
0x80,0x80,0x00,0x80,0x80,0x80,0x00,0x00,0x20,0x3F,0x21,0x00,0x00,0x20,0x3F,0x20,

/*--  文字:  o  --*/
/*--  宋体12;  此字体下对应的点阵为:宽x高=8x16   --*/
0x00,0x00,0x80,0x80,0x80,0x80,0x00,0x00,0x00,0x1F,0x20,0x20,0x20,0x20,0x1F,0x00,

/*--  文字:  p  --*/
/*--  宋体12;  此字体下对应的点阵为:宽x高=8x16   --*/
0x80,0x80,0x00,0x80,0x80,0x00,0x00,0x00,0x80,0xFF,0xA1,0x20,0x20,0x11,0x0E,0x00,

/*--  文字:  q  --*/
/*--  宋体12;  此字体下对应的点阵为:宽x高=8x16   --*/
0x00,0x00,0x00,0x80,0x80,0x80,0x80,0x00,0x00,0x0E,0x11,0x20,0x20,0xA0,0xFF,0x80,

/*--  文字:  r  --*/
/*--  宋体12;  此字体下对应的点阵为:宽x高=8x16   --*/
0x80,0x80,0x80,0x00,0x80,0x80,0x80,0x00,0x20,0x20,0x3F,0x21,0x20,0x00,0x01,0x00,

/*--  文字:  s  --*/
/*--  宋体12;  此字体下对应的点阵为:宽x高=8x16   --*/
0x00,0x00,0x80,0x80,0x80,0x80,0x80,0x00,0x00,0x33,0x24,0x24,0x24,0x24,0x19,0x00,

/*--  文字:  t  --*/
/*--  宋体12;  此字体下对应的点阵为:宽x高=8x16   --*/
0x00,0x80,0x80,0xE0,0x80,0x80,0x00,0x00,0x00,0x00,0x00,0x1F,0x20,0x20,0x00,0x00,

/*--  文字:  u  --*/
/*--  宋体12;  此字体下对应的点阵为:宽x高=8x16   --*/
0x80,0x80,0x00,0x00,0x00,0x80,0x80,0x00,0x00,0x1F,0x20,0x20,0x20,0x10,0x3F,0x20,

/*--  文字:  v  --*/
/*--  宋体12;  此字体下对应的点阵为:宽x高=8x16   --*/
0x80,0x80,0x80,0x00,0x00,0x80,0x80,0x80,0x00,0x01,0x0E,0x30,0x08,0x06,0x01,0x00,

/*--  文字:  w  --*/
/*--  宋体12;  此字体下对应的点阵为:宽x高=8x16   --*/
0x80,0x80,0x00,0x80,0x00,0x80,0x80,0x80,0x0F,0x30,0x0C,0x03,0x0C,0x30,0x0F,0x00,

/*--  文字:  x  --*/
/*--  宋体12;  此字体下对应的点阵为:宽x高=8x16   --*/
0x00,0x80,0x80,0x00,0x80,0x80,0x80,0x00,0x00,0x20,0x31,0x2E,0x0E,0x31,0x20,0x00,

/*--  文字:  y  --*/
/*--  宋体12;  此字体下对应的点阵为:宽x高=8x16   --*/
0x80,0x80,0x80,0x00,0x00,0x80,0x80,0x80,0x80,0x81,0x8E,0x70,0x18,0x06,0x01,0x00,

/*--  文字:  z  --*/
/*--  宋体12;  此字体下对应的点阵为:宽x高=8x16   --*/
0x00,0x80,0x80,0x80,0x80,0x80,0x80,0x00,0x00,0x21,0x30,0x2C,0x22,0x21,0x30,0x00,

/*--  文字:  {  --*/
/*--  宋体12;  此字体下对应的点阵为:宽x高=8x16   --*/
0x00,0x00,0x00,0x00,0x80,0x7C,0x02,0x02,0x00,0x00,0x00,0x00,0x00,0x3F,0x40,0x40,

/*--  文字:  |  --*/
/*--  宋体12;  此字体下对应的点阵为:宽x高=8x16   --*/
0x00,0x00,0x00,0x00,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0x00,0x00,0x00,

/*--  文字:  }  --*/
/*--  宋体12;  此字体下对应的点阵为:宽x高=8x16   --*/
0x00,0x02,0x02,0x7C,0x80,0x00,0x00,0x00,0x00,0x40,0x40,0x3F,0x00,0x00,0x00,0x00,

/*--  文字:  ~  --*/
/*--  宋体12;  此字体下对应的点阵为:宽x高=8x16   --*/
0x00,0x06,0x01,0x01,0x02,0x02,0x04,0x04,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
};

OLED_SPI.h

看着改吧…

#ifndef __OLED_SPI_H__
#define __OLED_SPI_H__
#include "msp430f149_init.h"
//-----------------------------------------------
#define SendComplete()    while(!(U0TCTL&TXEPT))
#define OLED_CS_0    P3OUT &= ~BIT0
#define OLED_CS_1    P3OUT |= BIT0
#define OLED_DC_0    P3OUT &= ~BIT2
#define OLED_DC_1    P3OUT |= BIT2
#define OLED_RES_0    P3OUT &= ~BIT4
#define OLED_RES_1    P3OUT |= BIT4
//-----------------------------------------------
void OLED_GPIO_init();
void OLED_init();
void OLED_clear();
void OLED_bmp();
void OLED_8_16_ASCII(u8 page,u8 lie,u8 amount,u8 *ascii);
void OLED_4_8_number(u8 page,u8 lie,u8 num);
#endif
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!