由浅入深,蓝牙4.0/BLE协议栈开发攻略大全(1)
; // 等待睡眠时钟切换到外部32K晶振
CLKCONCMD = (CLKCONCMD & 0x80) ; // 使用32M晶振作为主时钟
while ( (CLKCONSTA & ~0x80) != 0 ); // 等待主时钟切换到32M晶振
SLEEPCMD |= 0x04; // 关闭未使用的晶振
}
按照上述方式配置后,我们就可以工作在外部的32M晶振上了,配置好系统时钟和SPI后,剩下的工作只需要按照液晶屏的说明书发送相应的指令就可以将液晶屏驱动起来了,具体的驱动代码详见下一堂课程。这里使用的是ASCII的点阵表,所以只能显示英文,如果需要显示中文,就需要中文字库的支持了。
LCD12864的驱动程序:
P0.1 - LCD_MODE
P1.2 - LCD_CS
//spi
P1.5 - CLK
P1.6 - MOSI
/* LCD lines */
#define LCD12864_MAX_LINE 64
#define LCD12864_MAX_ROW 128
#define HAL_LCD_FONT_LINES 8
#define HAL_LCD_FONT_ROWS 6
/* LCD Max Chars and Buffer */
#define HAL_LCD_MAX_LINES (LCD12864_MAX_LINE/HAL_LCD_FONT_LINES) // 6*8点阵最大行数
#define HAL_LCD_MAX_CHARS (LCD12864_MAX_ROW/HAL_LCD_FONT_ROWS) // 6*8点阵最大列数
/* LCD Control lines */
#define HAL_LCD_RS_PORT 0
#define HAL_LCD_RS_PIN 1
#define HAL_LCD_CS_PORT 1
#define HAL_LCD_CS_PIN 2
/* LCD SPI lines */
#define HAL_LCD_CLK_PORT 1
#define HAL_LCD_CLK_PIN 5
#define HAL_LCD_MOSI_PORT 1
#define HAL_LCD_MOSI_PIN 6
// 12864 命令
#define LCD_CMD_DISPLAY_ON 0xAF
#define LCD_CMD_DISPLAY_OFF 0xAE
#define LCD_CMD_BEGIN_LINE 0x40
#define LCD_CMD_PAGE_LINE 0xB0
#define LCD_CMD_ROW_HIG 0x10
#define LCD_CMD_ROW_LOW 0x00
#define LCD_CMD_READ_STATE 0x00
#define LCD_CMD_ROW_ADDR_NORMAL 0xA0 // 从左到右
#define LCD_CMD_ROW_ADDR_REVERSE 0xA1 // 从右到左
#define LCD_CMD_DISPLAY_NORMAL 0xA6
#define LCD_CMD_DISPLAY_REVERSE 0xA7
#define LCD_CMD_DISPLAY_POINT_ALL 0xA5
#define LCD_CMD_DISPLAY_POINT_NORMAL 0xA4
#define LCD_CMD_BIAS_SET 0xA2 // 0XA2:BIAS=1/9 (常用) 0XA3:BIAS=1/7
#define LCD_CMD_SOFT_RESET 0xE2
#define LCD_CMD_LINE_NORMAL 0xC0 // 从上到下
#define LCD_CMD_LINE_REVERSE 0xC8 // 从下到上
#define LCD_CMD_POWER_ONE 0x2C
#define LCD_CMD_POWER_TWO 0x2E
#define LCD_CMD_POWER_THREE 0x2F
#define LCD_CMD_CONTRAST_ONE_LEVEL 0x22 // 0x20-0x27
#define LCD_CMD_CONTRAST_TWO_CMD 0x81 // 0x00-0x3F
#define LCD_CMD_STATIC_PICTURE_ON 0xAD
/* SPI interface control */
#define LCD_SPI_BEGIN() HAL_CONFIG_IO_OUTPUT(HAL_LCD_CS_PORT, HAL_LCD_CS_PIN, 0); /* chip select */
#define LCD_SPI_END() \
{ \
asm("NOP"); \
asm("NOP"); \
asm("NOP"); \
asm("NOP"); \
HAL_CONFIG_IO_OUTPUT(HAL_LCD_CS_PORT, HAL_LCD_CS_PIN, 1); /* chip select */ \
}
/* clear the received and transmit byte status, write tx data to buffer, wait till transmit done */
#define LCD_SPI_TX(x) { U1CSR &= ~(BV(2) | BV(1)); U1DBUF = x; while( !(U1CSR & BV(1)) ); }
/* Control macros */
#define LCD_DO_WRITE() HAL_CONFIG_IO_OUTPUT(HAL_LCD_RS_PORT, HAL_LCD_RS_PIN, 1);
#define LCD_DO_CONTROL() HAL_CONFIG_IO_OUTPUT(HAL_LCD_RS_PORT, HAL_LCD_RS_PIN, 0);
/*全体ASCII 列表:5x7点阵库*/
const static uint8 aucAsciiTable5x7[][5]={
0x00,0x00,0x00,0x00,0x00,//space
0x00,0x00,0x4f,0x00,0x00,//!
0x00,0x07,0x00,0x07,0x00,//"
0x14,0x7f,0x14,0x7f,0x14,//#
0x24,0x2a,0x7f,0x2a,0x12,//$
0x23,0x13,0x08,0x64,0x62,//%
0x36,0x49,0x55,0x22,0x50,//&
0x00,0x05,0x07,0x00,0x00,//]
0x00,0x1c,0x22,0x41,0x00,//(
0x00,0x41,0x22,0x1c,0x00,//)
0x14,0x08,0x3e,0x08,0x14,//*
0x08,0x08,0x3e,0x08,0x08,//+
0x00,0x50,0x30,0x00,0x00,//,
0x08,0x08,0x08,0x08,0x08,//-
0x00,0x60,0x60,0x00,0x00,//。
0x20,0x10,0x08,0x04,0x02,///
0
- 主流蓝牙BLE控制芯片详解(3):创杰 IS1685S(07-18)
- 苹果光环加持,蓝牙Beacon技术成室内定位应用最大黑马(08-02)
- 主流蓝牙BLE控制芯片详解(4):Nordic nRF51822(07-20)
- 蓝牙BLE之室内定位iBeacon应用测验(08-02)
- 由浅入深,蓝牙4.0/BLE协议栈开发攻略大全(5)(08-02)
- 由浅入深,蓝牙4.0/BLE协议栈开发攻略大全(2)(07-18)