本帖最后由 MDebug 于 2016-11-29 13:32 编辑
接下来是WiFi,OLED。
首先将电脑连接上WiFi(WiFi名:cangjingtun,密码:1234567890),然后在网页输入WiFi模块设置好IP:192.168.1.1,初始用户名密码都为admin,然后即可进入WiFi模块的设置。此设置是为了安全考虑,可以自己设定WiFi密码,防止其他用户非法访问。手机连接上WiFi后,同样可以使用此方法进行设置。
- #include "relay.h"
- //初始化P013和P016为输出口.并使能这两个口的时钟
- //RELAY IO初始化
- void Relay_Init(void)
- {
-
- Chip_GPIO_Init(LPC_GPIO_PORT);
- Chip_GPIO_PinSetDIR(LPC_GPIO_PORT, 0, 13, true); //ÉèÖÃ0.20½Å·½ÏòΪÊäÈë
- Chip_GPIO_PinSetDIR(LPC_GPIO_PORT, 0, 16, true); //ÉèÖÃ0.21½Å·½ÏòΪ³ö
- }
- /***********************************华丽的分割线**********************************/
- #include "wifi.h"
- #include "relay.h"
- #include "led.h"
- unsigned int Send_WiFi_Data=0;
- unsigned int Uart2_Rx=0;
- u16 USART_RX_BUF[USART2_REC_LEN]; //接收缓冲,最大USART_REC_LEN个字节.
- /***********************************华丽的分割线**********************************/
- void UART_SendData(u8 *Data)//wifi_data
- {
- int i=0;
- for(i=0;i<8;i++)
- {
- USART_SendMsg(USART,Data[i]);
-
- }
- }
- /***********************************华丽的分割线**********************************/
- void USART_IRQH(void)
- {
-
- if( (USART_RX_BUF[7]==0x59) || (USART_RX_BUF[7]==0x5F))
- {
- RELAY0 = 1;
- RELAY1 = 1;
-
- }
- if( (USART_RX_BUF[7]==0x58) || (USART_RX_BUF[7]==0x5B))
- {
- RELAY0 = 0;
- RELAY1 = 0;
- }
-
- }
-
复制代码 OLED:
- #include "oled.h"
- const unsigned char F6x8[][6] =
- {
- { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, // sp
- { 0x00, 0x00, 0x00, 0x2f, 0x00, 0x00 }, // !
- { 0x00, 0x00, 0x07, 0x00, 0x07, 0x00 }, // "
- { 0x00, 0x14, 0x7f, 0x14, 0x7f, 0x14 }, // #
- { 0x00, 0x24, 0x2a, 0x7f, 0x2a, 0x12 }, // $
- { 0x00, 0x62, 0x64, 0x08, 0x13, 0x23 }, // %
- { 0x00, 0x36, 0x49, 0x55, 0x22, 0x50 }, // &
- { 0x00, 0x00, 0x05, 0x03, 0x00, 0x00 }, // '
- { 0x00, 0x00, 0x1c, 0x22, 0x41, 0x00 }, // (
- { 0x00, 0x00, 0x41, 0x22, 0x1c, 0x00 }, // )
- { 0x00, 0x14, 0x08, 0x3E, 0x08, 0x14 }, // *
- { 0x00, 0x08, 0x08, 0x3E, 0x08, 0x08 }, // +
- { 0x00, 0x00, 0x00, 0xA0, 0x60, 0x00 }, // ,
- { 0x00, 0x08, 0x08, 0x08, 0x08, 0x08 }, // -
- { 0x00, 0x00, 0x60, 0x60, 0x00, 0x00 }, // .
- { 0x00, 0x20, 0x10, 0x08, 0x04, 0x02 }, // /
- { 0x00, 0x3E, 0x51, 0x49, 0x45, 0x3E }, // 0
- { 0x00, 0x00, 0x42, 0x7F, 0x40, 0x00 }, // 1
- { 0x00, 0x42, 0x61, 0x51, 0x49, 0x46 }, // 2
- { 0x00, 0x21, 0x41, 0x45, 0x4B, 0x31 }, // 3
- { 0x00, 0x18, 0x14, 0x12, 0x7F, 0x10 }, // 4
- { 0x00, 0x27, 0x45, 0x45, 0x45, 0x39 }, // 5
- { 0x00, 0x3C, 0x4A, 0x49, 0x49, 0x30 }, // 6
- { 0x00, 0x01, 0x71, 0x09, 0x05, 0x03 }, // 7
- { 0x00, 0x36, 0x49, 0x49, 0x49, 0x36 }, // 8
- { 0x00, 0x06, 0x49, 0x49, 0x29, 0x1E }, // 9
- { 0x00, 0x00, 0x36, 0x36, 0x00, 0x00 }, // :
- { 0x00, 0x00, 0x56, 0x36, 0x00, 0x00 }, // ;
- { 0x00, 0x08, 0x14, 0x22, 0x41, 0x00 }, // <
- { 0x00, 0x14, 0x14, 0x14, 0x14, 0x14 }, // =
- { 0x00, 0x00, 0x41, 0x22, 0x14, 0x08 }, // >
- { 0x00, 0x02, 0x01, 0x51, 0x09, 0x06 }, // ?
- { 0x00, 0x32, 0x49, 0x59, 0x51, 0x3E }, // @
- { 0x00, 0x7C, 0x12, 0x11, 0x12, 0x7C }, // A
- { 0x00, 0x7F, 0x49, 0x49, 0x49, 0x36 }, // B
- { 0x00, 0x3E, 0x41, 0x41, 0x41, 0x22 }, // C
- { 0x00, 0x7F, 0x41, 0x41, 0x22, 0x1C }, // D
- { 0x00, 0x7F, 0x49, 0x49, 0x49, 0x41 }, // E
- { 0x00, 0x7F, 0x09, 0x09, 0x09, 0x01 }, // F
- { 0x00, 0x3E, 0x41, 0x49, 0x49, 0x7A }, // G
- { 0x00, 0x7F, 0x08, 0x08, 0x08, 0x7F }, // H
- { 0x00, 0x00, 0x41, 0x7F, 0x41, 0x00 }, // I
- { 0x00, 0x20, 0x40, 0x41, 0x3F, 0x01 }, // J
- { 0x00, 0x7F, 0x08, 0x14, 0x22, 0x41 }, // K
- { 0x00, 0x7F, 0x40, 0x40, 0x40, 0x40 }, // L
- { 0x00, 0x7F, 0x02, 0x0C, 0x02, 0x7F }, // M
- { 0x00, 0x7F, 0x04, 0x08, 0x10, 0x7F }, // N
- { 0x00, 0x3E, 0x41, 0x41, 0x41, 0x3E }, // O
- { 0x00, 0x7F, 0x09, 0x09, 0x09, 0x06 }, // P
- { 0x00, 0x3E, 0x41, 0x51, 0x21, 0x5E }, // Q
- { 0x00, 0x7F, 0x09, 0x19, 0x29, 0x46 }, // R
- { 0x00, 0x46, 0x49, 0x49, 0x49, 0x31 }, // S
- { 0x00, 0x01, 0x01, 0x7F, 0x01, 0x01 }, // T
- { 0x00, 0x3F, 0x40, 0x40, 0x40, 0x3F }, // U
- { 0x00, 0x1F, 0x20, 0x40, 0x20, 0x1F }, // V
- { 0x00, 0x3F, 0x40, 0x38, 0x40, 0x3F }, // W
- { 0x00, 0x63, 0x14, 0x08, 0x14, 0x63 }, // X
- { 0x00, 0x07, 0x08, 0x70, 0x08, 0x07 }, // Y
- { 0x00, 0x61, 0x51, 0x49, 0x45, 0x43 }, // Z
- { 0x00, 0x00, 0x7F, 0x41, 0x41, 0x00 }, // [
- { 0x00, 0x55, 0x2A, 0x55, 0x2A, 0x55 }, // 55
- { 0x00, 0x00, 0x41, 0x41, 0x7F, 0x00 }, // ]
- { 0x00, 0x04, 0x02, 0x01, 0x02, 0x04 }, // ^
- { 0x00, 0x40, 0x40, 0x40, 0x40, 0x40 }, // _
- { 0x00, 0x00, 0x01, 0x02, 0x04, 0x00 }, // '
- { 0x00, 0x20, 0x54, 0x54, 0x54, 0x78 }, // a
- { 0x00, 0x7F, 0x48, 0x44, 0x44, 0x38 }, // b
- { 0x00, 0x38, 0x44, 0x44, 0x44, 0x20 }, // c
- { 0x00, 0x38, 0x44, 0x44, 0x48, 0x7F }, // d
- { 0x00, 0x38, 0x54, 0x54, 0x54, 0x18 }, // e
- { 0x00, 0x08, 0x7E, 0x09, 0x01, 0x02 }, // f
- { 0x00, 0x18, 0xA4, 0xA4, 0xA4, 0x7C }, // g
- { 0x00, 0x7F, 0x08, 0x04, 0x04, 0x78 }, // h
- { 0x00, 0x00, 0x44, 0x7D, 0x40, 0x00 }, // i
- { 0x00, 0x40, 0x80, 0x84, 0x7D, 0x00 }, // j
- { 0x00, 0x7F, 0x10, 0x28, 0x44, 0x00 }, // k
- { 0x00, 0x00, 0x41, 0x7F, 0x40, 0x00 }, // l
- { 0x00, 0x7C, 0x04, 0x18, 0x04, 0x78 }, // m
- { 0x00, 0x7C, 0x08, 0x04, 0x04, 0x78 }, // n
- { 0x00, 0x38, 0x44, 0x44, 0x44, 0x38 }, // o
- { 0x00, 0xFC, 0x24, 0x24, 0x24, 0x18 }, // p
- { 0x00, 0x18, 0x24, 0x24, 0x18, 0xFC }, // q
- { 0x00, 0x7C, 0x08, 0x04, 0x04, 0x08 }, // r
- { 0x00, 0x48, 0x54, 0x54, 0x54, 0x20 }, // s
- { 0x00, 0x04, 0x3F, 0x44, 0x40, 0x20 }, // t
- { 0x00, 0x3C, 0x40, 0x40, 0x20, 0x7C }, // u
- { 0x00, 0x1C, 0x20, 0x40, 0x20, 0x1C }, // v
- { 0x00, 0x3C, 0x40, 0x30, 0x40, 0x3C }, // w
- { 0x00, 0x44, 0x28, 0x10, 0x28, 0x44 }, // x
- { 0x00, 0x1C, 0xA0, 0xA0, 0xA0, 0x7C }, // y
- { 0x00, 0x44, 0x64, 0x54, 0x4C, 0x44 }, // z
- { 0x14, 0x14, 0x14, 0x14, 0x14, 0x14 } // horiz lines
- };
- const unsigned char F14x16[] = {
- 0x10,0x60,0x02,0x8C,0x00,0x04,0x0C,0x94,0xA5,0x46,0xA4,0x94,0x0C,0x04,0x04,0x04,
- 0x7E,0x01,0x00,0x81,0x61,0x1E,0x00,0x00,0x00,0xFE,0x01,0x01,/*"¼Ã",0*/
- 0x04,0xE4,0x24,0x24,0x64,0xA4,0x24,0x3F,0x24,0xA4,0x64,0x24,0x24,0xE4,0x00,0xFF,
- 0x00,0x08,0x09,0x09,0x09,0x7F,0x09,0x09,0x09,0x48,0x80,0x7F,/*"ÄÏ",1*/
- 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0xFF,0x20,0x20,0x20,0x20,0x20,0x20,0x80,0x80,
- 0x40,0x20,0x10,0x0C,0x03,0x00,0x03,0x0C,0x10,0x20,0x40,0x80,/*"´ó",2*/
- 0x40,0x30,0x11,0x96,0x90,0x90,0x91,0x96,0x90,0x90,0x98,0x14,0x13,0x50,0x04,0x04,
- 0x04,0x04,0x04,0x44,0x84,0x7E,0x06,0x05,0x04,0x04,0x04,0x04,/*"ѧ",3*/
- 0x10,0x0C,0x04,0x84,0x14,0x64,0x05,0x06,0xF4,0x04,0x04,0x04,0x04,0x14,0x04,0x84,
- 0x84,0x44,0x47,0x24,0x14,0x0C,0x07,0x0C,0x14,0x24,0x44,0x84,/*"ʵ",4*/
- 0x02,0xFA,0x82,0x82,0xFE,0x80,0x40,0x20,0x50,0x4C,0x43,0x4C,0x50,0x20,0x08,0x18,
- 0x48,0x84,0x44,0x3F,0x40,0x44,0x58,0x41,0x4E,0x60,0x58,0x47,/*"Ñé",5*/
- 0x10,0x0C,0x24,0x24,0xA4,0x64,0x25,0x26,0x24,0x24,0xA4,0x24,0x24,0x14,0x40,0x40,
- 0x48,0x49,0x49,0x49,0x49,0x7F,0x49,0x49,0x49,0x4B,0x48,0x40,/*"ÊÒ",6*/
- };
- const unsigned char F16x16[] = {
- 0x00,0x00,0x00,0x10,0x10,0x10,0x10,0xF0,0xF8,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x20,0x20,0x20,0x20,0x3F,0x3F,0x20,0x20,0x20,0x20,0x00,0x00,0x00,/*"1",0*/
- 0x00,0x00,0x60,0x50,0x10,0x08,0x08,0x08,0x08,0x08,0x08,0x98,0xF0,0x70,0x00,0x00,
- 0x00,0x00,0x20,0x30,0x28,0x28,0x24,0x24,0x22,0x22,0x21,0x20,0x30,0x18,0x00,0x00,/*"2",1*/
- 0x00,0x00,0xC0,0xE0,0x30,0x10,0x08,0x08,0x08,0x08,0x08,0x18,0x30,0xE0,0xC0,0x00,
- 0x00,0x00,0x07,0x0F,0x18,0x10,0x20,0x20,0x20,0x20,0x20,0x10,0x18,0x0F,0x07,0x00,/*"0",2*/
- 0x00,0xE0,0xF0,0x10,0x08,0x08,0x08,0x08,0x08,0x08,0x18,0x10,0xF0,0xC0,0x00,0x00,
- 0x00,0x00,0x11,0x33,0x22,0x22,0x22,0x22,0x22,0x32,0x11,0x1D,0x0F,0x03,0x00,0x00,/*"9",3*/
- 0x00,0x00,0x00,0x08,0x08,0x08,0x08,0xF8,0xF8,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x20,0x20,0x20,0x20,0x3F,0x3F,0x20,0x20,0x20,0x20,0x00,0x00,0x00,/*"l",4*/
- 0x00,0x00,0x00,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x00,0x00,0x00,0x00,0x00,
- 0x00,0x18,0x3D,0x25,0x24,0x22,0x22,0x22,0x22,0x12,0x3F,0x3F,0x20,0x20,0x00,0x00,/*"a",5*/
- 0x00,0x08,0x08,0xF8,0xFC,0x00,0x00,0x80,0x80,0x80,0x80,0x80,0x80,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x3F,0x1F,0x11,0x21,0x20,0x20,0x20,0x20,0x20,0x11,0x1F,0x0E,0x00,/*"b",6*/
- 0x00,0x00,0xF8,0x88,0x88,0x88,0x88,0xFF,0x88,0x88,0x88,0x88,0xF8,0x00,0x00,0x00,
- 0x00,0x00,0x1F,0x08,0x08,0x08,0x08,0x7F,0x88,0x88,0x88,0x88,0x9F,0x80,0xF0,0x00,/*"?",0*/
- 0x80,0x82,0x82,0x82,0x82,0x82,0x82,0xE2,0xA2,0x92,0x8A,0x86,0x82,0x80,0x80,0x00,
- 0x00,0x00,0x00,0x00,0x00,0x40,0x80,0x7F,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,/*"?",1*/
- 0x24,0x24,0xA4,0xFE,0x23,0x22,0x40,0x30,0x0F,0x08,0xC8,0x08,0x08,0x28,0x18,0x00,
- 0x08,0x06,0x01,0xFF,0x01,0x02,0x10,0x0C,0x43,0x80,0x7F,0x00,0x01,0x06,0x18,0x00,/*"?",2*/
- 0x10,0x10,0x14,0xD4,0x54,0x54,0x54,0xFC,0x52,0x52,0x52,0xD3,0x12,0x10,0x10,0x00,
- 0x40,0x40,0x50,0x57,0x55,0x55,0x55,0x7F,0x55,0x55,0x55,0x57,0x50,0x40,0x40,0x00,/*"?",3*/
- 0x20,0x20,0x20,0xBE,0xAA,0xAA,0xAA,0xAA,0xAA,0xAA,0xAA,0xBE,0x20,0x20,0x20,0x00,
- 0x00,0x80,0x80,0xAF,0xAA,0xAA,0xAA,0xFF,0xAA,0xAA,0xAA,0xAF,0x80,0x80,0x00,0x00,/*"?",4*/
- };
- const unsigned char F8X16[]=
- {
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,// 0
- 0x00,0x00,0x00,0xF8,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x33,0x30,0x00,0x00,0x00,//!1
- 0x00,0x10,0x0C,0x06,0x10,0x0C,0x06,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,//"2
- 0x40,0xC0,0x78,0x40,0xC0,0x78,0x40,0x00,0x04,0x3F,0x04,0x04,0x3F,0x04,0x04,0x00,//#3
- 0x00,0x70,0x88,0xFC,0x08,0x30,0x00,0x00,0x00,0x18,0x20,0xFF,0x21,0x1E,0x00,0x00,//$4
- 0xF0,0x08,0xF0,0x00,0xE0,0x18,0x00,0x00,0x00,0x21,0x1C,0x03,0x1E,0x21,0x1E,0x00,//%5
- 0x00,0xF0,0x08,0x88,0x70,0x00,0x00,0x00,0x1E,0x21,0x23,0x24,0x19,0x27,0x21,0x10,//&6
- 0x10,0x16,0x0E,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,//'7
- 0x00,0x00,0x00,0xE0,0x18,0x04,0x02,0x00,0x00,0x00,0x00,0x07,0x18,0x20,0x40,0x00,//(8
- 0x00,0x02,0x04,0x18,0xE0,0x00,0x00,0x00,0x00,0x40,0x20,0x18,0x07,0x00,0x00,0x00,//)9
- 0x40,0x40,0x80,0xF0,0x80,0x40,0x40,0x00,0x02,0x02,0x01,0x0F,0x01,0x02,0x02,0x00,//*10
- 0x00,0x00,0x00,0xF0,0x00,0x00,0x00,0x00,0x01,0x01,0x01,0x1F,0x01,0x01,0x01,0x00,//+11
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0xB0,0x70,0x00,0x00,0x00,0x00,0x00,//,12
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x01,0x01,0x01,0x01,0x01,0x01,//-13
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x30,0x30,0x00,0x00,0x00,0x00,0x00,//.14
- 0x00,0x00,0x00,0x00,0x80,0x60,0x18,0x04,0x00,0x60,0x18,0x06,0x01,0x00,0x00,0x00,///15
- 0x00,0xE0,0x10,0x08,0x08,0x10,0xE0,0x00,0x00,0x0F,0x10,0x20,0x20,0x10,0x0F,0x00,//016
- 0x00,0x10,0x10,0xF8,0x00,0x00,0x00,0x00,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00,//117
- 0x00,0x70,0x08,0x08,0x08,0x88,0x70,0x00,0x00,0x30,0x28,0x24,0x22,0x21,0x30,0x00,//218
- 0x00,0x30,0x08,0x88,0x88,0x48,0x30,0x00,0x00,0x18,0x20,0x20,0x20,0x11,0x0E,0x00,//319
- 0x00,0x00,0xC0,0x20,0x10,0xF8,0x00,0x00,0x00,0x07,0x04,0x24,0x24,0x3F,0x24,0x00,//420
- 0x00,0xF8,0x08,0x88,0x88,0x08,0x08,0x00,0x00,0x19,0x21,0x20,0x20,0x11,0x0E,0x00,//521
- 0x00,0xE0,0x10,0x88,0x88,0x18,0x00,0x00,0x00,0x0F,0x11,0x20,0x20,0x11,0x0E,0x00,//622
- 0x00,0x38,0x08,0x08,0xC8,0x38,0x08,0x00,0x00,0x00,0x00,0x3F,0x00,0x00,0x00,0x00,//723
- 0x00,0x70,0x88,0x08,0x08,0x88,0x70,0x00,0x00,0x1C,0x22,0x21,0x21,0x22,0x1C,0x00,//824
- 0x00,0xE0,0x10,0x08,0x08,0x10,0xE0,0x00,0x00,0x00,0x31,0x22,0x22,0x11,0x0F,0x00,//925
- 0x00,0x00,0x00,0xC0,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x30,0x30,0x00,0x00,0x00,//:26
- 0x00,0x00,0x00,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0x60,0x00,0x00,0x00,0x00,//;27
- 0x00,0x00,0x80,0x40,0x20,0x10,0x08,0x00,0x00,0x01,0x02,0x04,0x08,0x10,0x20,0x00,//<28
- 0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x00,0x04,0x04,0x04,0x04,0x04,0x04,0x04,0x00,//=29
- 0x00,0x08,0x10,0x20,0x40,0x80,0x00,0x00,0x00,0x20,0x10,0x08,0x04,0x02,0x01,0x00,//>30
- 0x00,0x70,0x48,0x08,0x08,0x08,0xF0,0x00,0x00,0x00,0x00,0x30,0x36,0x01,0x00,0x00,//?31
- 0xC0,0x30,0xC8,0x28,0xE8,0x10,0xE0,0x00,0x07,0x18,0x27,0x24,0x23,0x14,0x0B,0x00,//@32
- 0x00,0x00,0xC0,0x38,0xE0,0x00,0x00,0x00,0x20,0x3C,0x23,0x02,0x02,0x27,0x38,0x20,//A33
- 0x08,0xF8,0x88,0x88,0x88,0x70,0x00,0x00,0x20,0x3F,0x20,0x20,0x20,0x11,0x0E,0x00,//B34
- 0xC0,0x30,0x08,0x08,0x08,0x08,0x38,0x00,0x07,0x18,0x20,0x20,0x20,0x10,0x08,0x00,//C35
- 0x08,0xF8,0x08,0x08,0x08,0x10,0xE0,0x00,0x20,0x3F,0x20,0x20,0x20,0x10,0x0F,0x00,//D36
- 0x08,0xF8,0x88,0x88,0xE8,0x08,0x10,0x00,0x20,0x3F,0x20,0x20,0x23,0x20,0x18,0x00,//E37
- 0x08,0xF8,0x88,0x88,0xE8,0x08,0x10,0x00,0x20,0x3F,0x20,0x00,0x03,0x00,0x00,0x00,//F38
- 0xC0,0x30,0x08,0x08,0x08,0x38,0x00,0x00,0x07,0x18,0x20,0x20,0x22,0x1E,0x02,0x00,//G39
- 0x08,0xF8,0x08,0x00,0x00,0x08,0xF8,0x08,0x20,0x3F,0x21,0x01,0x01,0x21,0x3F,0x20,//H40
- 0x00,0x08,0x08,0xF8,0x08,0x08,0x00,0x00,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00,//I41
- 0x00,0x00,0x08,0x08,0xF8,0x08,0x08,0x00,0xC0,0x80,0x80,0x80,0x7F,0x00,0x00,0x00,//J42
- 0x08,0xF8,0x88,0xC0,0x28,0x18,0x08,0x00,0x20,0x3F,0x20,0x01,0x26,0x38,0x20,0x00,//K43
- 0x08,0xF8,0x08,0x00,0x00,0x00,0x00,0x00,0x20,0x3F,0x20,0x20,0x20,0x20,0x30,0x00,//L44
- 0x08,0xF8,0xF8,0x00,0xF8,0xF8,0x08,0x00,0x20,0x3F,0x00,0x3F,0x00,0x3F,0x20,0x00,//M45
- 0x08,0xF8,0x30,0xC0,0x00,0x08,0xF8,0x08,0x20,0x3F,0x20,0x00,0x07,0x18,0x3F,0x00,//N46
- 0xE0,0x10,0x08,0x08,0x08,0x10,0xE0,0x00,0x0F,0x10,0x20,0x20,0x20,0x10,0x0F,0x00,//O47
- 0x08,0xF8,0x08,0x08,0x08,0x08,0xF0,0x00,0x20,0x3F,0x21,0x01,0x01,0x01,0x00,0x00,//P48
- 0xE0,0x10,0x08,0x08,0x08,0x10,0xE0,0x00,0x0F,0x18,0x24,0x24,0x38,0x50,0x4F,0x00,//Q49
- 0x08,0xF8,0x88,0x88,0x88,0x88,0x70,0x00,0x20,0x3F,0x20,0x00,0x03,0x0C,0x30,0x20,//R50
- 0x00,0x70,0x88,0x08,0x08,0x08,0x38,0x00,0x00,0x38,0x20,0x21,0x21,0x22,0x1C,0x00,//S51
- 0x18,0x08,0x08,0xF8,0x08,0x08,0x18,0x00,0x00,0x00,0x20,0x3F,0x20,0x00,0x00,0x00,//T52
- 0x08,0xF8,0x08,0x00,0x00,0x08,0xF8,0x08,0x00,0x1F,0x20,0x20,0x20,0x20,0x1F,0x00,//U53
- 0x08,0x78,0x88,0x00,0x00,0xC8,0x38,0x08,0x00,0x00,0x07,0x38,0x0E,0x01,0x00,0x00,//V54
- 0xF8,0x08,0x00,0xF8,0x00,0x08,0xF8,0x00,0x03,0x3C,0x07,0x00,0x07,0x3C,0x03,0x00,//W55
- 0x08,0x18,0x68,0x80,0x80,0x68,0x18,0x08,0x20,0x30,0x2C,0x03,0x03,0x2C,0x30,0x20,//X56
- 0x08,0x38,0xC8,0x00,0xC8,0x38,0x08,0x00,0x00,0x00,0x20,0x3F,0x20,0x00,0x00,0x00,//Y57
- 0x10,0x08,0x08,0x08,0xC8,0x38,0x08,0x00,0x20,0x38,0x26,0x21,0x20,0x20,0x18,0x00,//Z58
- 0x00,0x00,0x00,0xFE,0x02,0x02,0x02,0x00,0x00,0x00,0x00,0x7F,0x40,0x40,0x40,0x00,//[59
- 0x00,0x0C,0x30,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x06,0x38,0xC0,0x00,//\60
- 0x00,0x02,0x02,0x02,0xFE,0x00,0x00,0x00,0x00,0x40,0x40,0x40,0x7F,0x00,0x00,0x00,//]61
- 0x00,0x00,0x04,0x02,0x02,0x02,0x04,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,//^62
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,//_63
- 0x00,0x02,0x02,0x04,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,//`64
- 0x00,0x00,0x80,0x80,0x80,0x80,0x00,0x00,0x00,0x19,0x24,0x22,0x22,0x22,0x3F,0x20,//a65
- 0x08,0xF8,0x00,0x80,0x80,0x00,0x00,0x00,0x00,0x3F,0x11,0x20,0x20,0x11,0x0E,0x00,//b66
- 0x00,0x00,0x00,0x80,0x80,0x80,0x00,0x00,0x00,0x0E,0x11,0x20,0x20,0x20,0x11,0x00,//c67
- 0x00,0x00,0x00,0x80,0x80,0x88,0xF8,0x00,0x00,0x0E,0x11,0x20,0x20,0x10,0x3F,0x20,//d68
- 0x00,0x00,0x80,0x80,0x80,0x80,0x00,0x00,0x00,0x1F,0x22,0x22,0x22,0x22,0x13,0x00,//e69
- 0x00,0x80,0x80,0xF0,0x88,0x88,0x88,0x18,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00,//f70
- 0x00,0x00,0x80,0x80,0x80,0x80,0x80,0x00,0x00,0x6B,0x94,0x94,0x94,0x93,0x60,0x00,//g71
- 0x08,0xF8,0x00,0x80,0x80,0x80,0x00,0x00,0x20,0x3F,0x21,0x00,0x00,0x20,0x3F,0x20,//h72
- 0x00,0x80,0x98,0x98,0x00,0x00,0x00,0x00,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00,//i73
- 0x00,0x00,0x00,0x80,0x98,0x98,0x00,0x00,0x00,0xC0,0x80,0x80,0x80,0x7F,0x00,0x00,//j74
- 0x08,0xF8,0x00,0x00,0x80,0x80,0x80,0x00,0x20,0x3F,0x24,0x02,0x2D,0x30,0x20,0x00,//k75
- 0x00,0x08,0x08,0xF8,0x00,0x00,0x00,0x00,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00,//l76
- 0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x00,0x20,0x3F,0x20,0x00,0x3F,0x20,0x00,0x3F,//m77
- 0x80,0x80,0x00,0x80,0x80,0x80,0x00,0x00,0x20,0x3F,0x21,0x00,0x00,0x20,0x3F,0x20,//n78
- 0x00,0x00,0x80,0x80,0x80,0x80,0x00,0x00,0x00,0x1F,0x20,0x20,0x20,0x20,0x1F,0x00,//o79
- 0x80,0x80,0x00,0x80,0x80,0x00,0x00,0x00,0x80,0xFF,0xA1,0x20,0x20,0x11,0x0E,0x00,//p80
- 0x00,0x00,0x00,0x80,0x80,0x80,0x80,0x00,0x00,0x0E,0x11,0x20,0x20,0xA0,0xFF,0x80,//q81
- 0x80,0x80,0x80,0x00,0x80,0x80,0x80,0x00,0x20,0x20,0x3F,0x21,0x20,0x00,0x01,0x00,//r82
- 0x00,0x00,0x80,0x80,0x80,0x80,0x80,0x00,0x00,0x33,0x24,0x24,0x24,0x24,0x19,0x00,//s83
- 0x00,0x80,0x80,0xE0,0x80,0x80,0x00,0x00,0x00,0x00,0x00,0x1F,0x20,0x20,0x00,0x00,//t84
- 0x80,0x80,0x00,0x00,0x00,0x80,0x80,0x00,0x00,0x1F,0x20,0x20,0x20,0x10,0x3F,0x20,//u85
- 0x80,0x80,0x80,0x00,0x00,0x80,0x80,0x80,0x00,0x01,0x0E,0x30,0x08,0x06,0x01,0x00,//v86
- 0x80,0x80,0x00,0x80,0x00,0x80,0x80,0x80,0x0F,0x30,0x0C,0x03,0x0C,0x30,0x0F,0x00,//w87
- 0x00,0x80,0x80,0x00,0x80,0x80,0x80,0x00,0x00,0x20,0x31,0x2E,0x0E,0x31,0x20,0x00,//x88
- 0x80,0x80,0x80,0x00,0x00,0x80,0x80,0x80,0x80,0x81,0x8E,0x70,0x18,0x06,0x01,0x00,//y89
- 0x00,0x80,0x80,0x80,0x80,0x80,0x80,0x00,0x00,0x21,0x30,0x2C,0x22,0x21,0x30,0x00,//z90
- 0x00,0x00,0x00,0x00,0x80,0x7C,0x02,0x02,0x00,0x00,0x00,0x00,0x00,0x3F,0x40,0x40,//{91
- 0x00,0x00,0x00,0x00,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0x00,0x00,0x00,//|92
- 0x00,0x02,0x02,0x7C,0x80,0x00,0x00,0x00,0x00,0x40,0x40,0x3F,0x00,0x00,0x00,0x00,//}93
- 0x00,0x06,0x01,0x01,0x02,0x02,0x04,0x04,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,//~94
- };
- /*写指令到LCD模块*/
- void transfer_command_lcd(int data1)
- {
- char i;
- lcd_rs(0);;;
- lcd_cs1(0);
- for(i=0;i<8;i++)
- {lcd_sclk(0);;;
-
- if(data1&0x80) {lcd_sid(1);;;}
- else {lcd_sid(0);;;}
- lcd_sclk(1);
- __nop();;;
- // lcd_sclk(0);;;
- data1<<=1;
- }
- lcd_rs(1);;;
- lcd_cs1(1);
- }
- /*写数据到LCD模块*/
- void transfer_data_lcd(int data1)
- {
- char i;
- lcd_rs(1);;;
- lcd_cs1(0);
- for(i=0;i<8;i++)
- {
- lcd_sclk(0);;;
- if(data1&0x80) {lcd_sid(1);;;}
- else {lcd_sid(0);;;}
- lcd_sclk(1);;;
- __nop();;;
- //lcd_sclk(0);;;
- data1<<=1;
- }lcd_rs(1);;;
- lcd_cs1(1);
- }
- /*延时*/
- void delay(int n_ms)
- {
- int j,k;
- for(j=0;j<n_ms;j++)
- for(k=0;k<5500;k++);
- }
- #if 0
- void waitkey()
- {
- repeat:
- if (P2&0x01) goto repeat;
- else delay(6);
- if (P2&0x01) goto repeat;
- else
- delay(40);;
- }
- #endif
- /*LCD模块初始化*/
- void initial_lcd()
- {
-
- delay(400);
- GBZK_GPIO_Config();
- lcd_cs1(0);
- Rom_CS(1);
-
- transfer_command_lcd(0xAE); //display off
- transfer_command_lcd(0x20); //Set Memory Addressing Mode
- transfer_command_lcd(0x10); //00,Horizontal Addressing Mode;01,Vertical Addressing Mode;10,Page Addressing Mode (RESET);11,Invalid
- transfer_command_lcd(0xb0); //Set Page Start Address for Page Addressing Mode,0-7
- transfer_command_lcd(0xc8); //Set COM Output Scan Direction
- transfer_command_lcd(0x00);//---set low column address
- transfer_command_lcd(0x10);//---set high column address
- transfer_command_lcd(0x40);//--set start line address
- transfer_command_lcd(0x81);//--set contrast control register
- transfer_command_lcd(0xFF);
- transfer_command_lcd(0xa1);//--set segment re-map 0 to 127
- transfer_command_lcd(0xa6);//--set normal display
- transfer_command_lcd(0xa8);//--set multiplex ratio(1 to 64)
- transfer_command_lcd(0x3F);//
- transfer_command_lcd(0xa4);//0xa4,Output follows RAM content;0xa5,Output ignores RAM content
- transfer_command_lcd(0xd3);//-set display offset
- transfer_command_lcd(0x00);//-not offset
- transfer_command_lcd(0xd5);//--set display clock divide ratio/oscillator frequency
- transfer_command_lcd(0xf0);//--set divide ratio
- transfer_command_lcd(0xd9);//--set pre-charge period
- transfer_command_lcd(0x22); //
- transfer_command_lcd(0xda);//--set com pins hardware configuration
- transfer_command_lcd(0x12);
- transfer_command_lcd(0xdb);//--set vcomh
- transfer_command_lcd(0x20);//0x20,0.77xVcc
- transfer_command_lcd(0x8d);//--set DC-DC enable
- transfer_command_lcd(0x14);//
- transfer_command_lcd(0xaf);//--turn on oled panel
- lcd_cs1(1);
- }
- void lcd_address(uchar page,uchar column)
- {
- transfer_command_lcd(0xb0 + column); /*设置页地址*/
- transfer_command_lcd(((page & 0xf0) >> 4) | 0x10); /*设置列地址的高4位*/
- transfer_command_lcd((page & 0x0f) | 0x00); /*设置列地址的低4位*/
- }
- /*全屏清屏*/
- void clear_screen()
- {
- unsigned char i,j;
- lcd_cs1(0);
- Rom_CS(1);
- for(i=0;i<8;i++)
- {
- transfer_command_lcd(0xb0+i);
- transfer_command_lcd(0x00);
- transfer_command_lcd(0x10);
- for(j=0;j<132;j++)
- {
- transfer_data_lcd(0x00);
- }
- }
- lcd_cs1(1);
- }
- /*显示128x64点阵图像*/
- void display_128x64(const uchar *dp)
- {
- uint i,j;
- lcd_cs1(0);
- for(j=0;j<8;j++)
- {
- lcd_address(0,j);
- for (i=0;i<128;i++)
- {
- transfer_data_lcd(*dp); /*写数据到LCD,每写完一个8位的数据后列地址自动加1*/
- dp++;
- }
- }
- lcd_cs1(1);
- }
- /*显示16x16点阵图像、汉字、生僻字或16x16点阵的其他图标*/
- void display_graphic_16x16(uint page,uint column,const uchar *dp)
- {
- uint i,j;
- lcd_cs1(0);
- Rom_CS(1);
- for(j=2;j>0;j--)
- {
- lcd_address(column,page);
- for (i=0;i<16;i++)
- {
- transfer_data_lcd(*dp); /*写数据到LCD,每写完一个8位的数据后列地址自动加1*/
- dp++;
- }
- page++;
- }
- lcd_cs1(1);
- }
- /*显示8x16点阵图像、ASCII, 或8x16点阵的自造字符、其他图标*/
- void display_graphic_8x16(uint page,uchar column,uchar *dp)
- {
- uint i,j;
- lcd_cs1(0);
- for(j=2;j>0;j--)
- {
- lcd_address(column,page);
- for (i=0;i<8;i++)
- {
- transfer_data_lcd(*dp); /*写数据到LCD,每写完一个8位的数据后列地址自动加1*/
- dp++;
- }
- page++;
- }
- lcd_cs1(1);
- }
- /*显示5*7点阵图像、ASCII, 或5x7点阵的自造字符、其他图标*/
- void display_graphic_5x7(uint page,uchar column,uchar *dp)
- {
- uint col_cnt;
- uchar page_address;
- uchar column_address_L,column_address_H;
- page_address = 0xb0+page-1;
-
- lcd_cs1(0);
-
- column_address_L =(column&0x0f)-1;
- column_address_H =((column>>4)&0x0f)+0x10;
-
- transfer_command_lcd(page_address); /*Set Page Address*/
- transfer_command_lcd(column_address_H); /*Set MSB of column Address*/
- transfer_command_lcd(column_address_L); /*Set LSB of column Address*/
-
- for (col_cnt=0;col_cnt<6;col_cnt++)
- {
- transfer_data_lcd(*dp);
- dp++;
- }
- lcd_cs1(1);
- }
- /****送指令到晶联讯字库IC***/
- void send_command_to_ROM( uchar datu )
- {
- uchar i;
- for(i=0;i<8;i++ )
- {
- if(datu&0x80)
- {lcd_sid(1);;;__nop();}
- else
- {lcd_sid(0);;; __nop(); }
- datu = datu<<1;
- lcd_sclk(0);;;__nop();
- lcd_sclk(1);;;__nop();
- }
- }
- /****从晶联讯字库IC中取汉字或字符数据(1个字节)***/
- static uchar get_data_from_ROM( )
- {
-
- uchar i;
- uchar ret_data=0;
- lcd_sclk(1);;; __nop();
- GBZK_ROMOUTSET();
- for(i=0;i<8;i++)
- {
- Rom_OUT(1);;; __nop();
- lcd_sclk(0);;;__nop();
- ret_data=ret_data<<1;
- if( ROM_OUT )
- {ret_data=ret_data+1;;;__nop();}
- else
- {ret_data=ret_data+0;;;__nop(); }
- lcd_sclk(1);
- }
- GBZK_ROMOUTRESET();
- return(ret_data);
- }
- /*从相关地址(addrHigh:地址高字节,addrMid:地址中字节,addrLow:地址低字节)中连续读出DataLen个字节的数据到 pBuff的地址*/
- /*连续读取*/
- void get_n_bytes_data_from_ROM(uchar addrHigh,uchar addrMid,uchar addrLow,uchar *pBuff,uchar DataLen )
- {
- uchar i;
- Rom_CS(0);
- lcd_cs1(1);
- lcd_sclk(0);
- send_command_to_ROM(0x03);
- send_command_to_ROM(addrHigh);
- send_command_to_ROM(addrMid);
- send_command_to_ROM(addrLow);
- for(i = 0; i < DataLen; i++ )
- *(pBuff+i) =get_data_from_ROM();
- Rom_CS(1);
- }
- /******************************************************************/
- //x,y,text
- ulong fontaddr=0;
- void display_GB2312_string(uchar y,uchar x,uchar *text)
- {
- uchar i= 0;
- uchar addrHigh,addrMid,addrLow ;
- uchar fontbuf[32];
- while((text[i]>0x00))
- {
- if(((text[i]>=0xb0) &&(text[i]<=0xf7))&&(text[i+1]>=0xa1))
- {
- /*国标简体(GB2312)汉字在晶联讯字库IC中的地址由以下公式来计算:*/
- /*Address = ((MSB - 0xB0) * 94 + (LSB - 0xA1)+ 846)*32+ BaseAdd;BaseAdd=0*/
- /*由于担心8位单片机有乘法溢出问题,所以分三部取地址*/
- fontaddr = (text[i]- 0xb0)*94;
- fontaddr += (text[i+1]-0xa1)+846;
- fontaddr = (ulong)(fontaddr*32);
-
- addrHigh = (fontaddr&0xff0000)>>16; /*地址的高8位,共24位*/
- addrMid = (fontaddr&0xff00)>>8; /*地址的中8位,共24位*/
- addrLow = fontaddr&0xff; /*地址的低8位,共24位*/
- get_n_bytes_data_from_ROM(addrHigh,addrMid,addrLow,fontbuf,32 );/*取32个字节的数据,存到"fontbuf[32]"*/
- display_graphic_16x16(y,x,fontbuf);/*显示汉字到LCD上,y为页地址,x为列地址,fontbuf[]为数据*/
- i+=2;
- x+=16;
- }
- else if(((text[i]>=0xa1) &&(text[i]<=0xa3))&&(text[i+1]>=0xa1))
- {
- /*国标简体(GB2312)15x16点的字符在晶联讯字库IC中的地址由以下公式来计算:*/
- /*Address = ((MSB - 0xa1) * 94 + (LSB - 0xA1))*32+ BaseAdd;BaseAdd=0*/
- /*由于担心8位单片机有乘法溢出问题,所以分三部取地址*/
- fontaddr = (text[i]- 0xa1)*94;
- fontaddr += (text[i+1]-0xa1);
- fontaddr = (ulong)(fontaddr*32);
-
- addrHigh = (fontaddr&0xff0000)>>16; /*地址的高8位,共24位*/
- addrMid = (fontaddr&0xff00)>>8; /*地址的中8位,共24位*/
- addrLow = fontaddr&0xff; /*地址的低8位,共24位*/
- get_n_bytes_data_from_ROM(addrHigh,addrMid,addrLow,fontbuf,32 );/*取32个字节的数据,存到"fontbuf[32]"*/
- display_graphic_16x16(y,x,fontbuf);/*显示汉字到LCD上,y为页地址,x为列地址,fontbuf[]为数据*/
- i+=2;
- x+=16;
- }
- else if((text[i]>=0x20) &&(text[i]<=0x7e))
- {
- unsigned char fontbuf[16];
- fontaddr = (text[i]- 0x20);
- fontaddr = (unsigned long)(fontaddr*16);
- fontaddr = (unsigned long)(fontaddr+0x3cf80);
- addrHigh = (fontaddr&0xff0000)>>16;
- addrMid = (fontaddr&0xff00)>>8;
- addrLow = fontaddr&0xff;
- get_n_bytes_data_from_ROM(addrHigh,addrMid,addrLow,fontbuf,16 );/*取16个字节的数据,存到"fontbuf[32]"*/
-
- display_graphic_8x16(y,x,fontbuf);/*显示8x16的ASCII字到LCD上,y为页地址,x为列地址,fontbuf[]为数据*/
- i+=1;
- x+=8;
- }
- else
- i++;
- }
-
- }
- void display_string_5x7(uchar y,uchar x,uchar *text)
- {
- unsigned char i= 0;
- unsigned char addrHigh,addrMid,addrLow ;
- while((text[i]>0x00))
- {
- if((text[i]>=0x20) &&(text[i]<=0x7e))
- {
- unsigned char fontbuf[8];
- fontaddr = (text[i]- 0x20);
- fontaddr = (unsigned long)(fontaddr*8);
- fontaddr = (unsigned long)(fontaddr+0x3bfc0);
- addrHigh = (fontaddr&0xff0000)>>16;
- addrMid = (fontaddr&0xff00)>>8;
- addrLow = fontaddr&0xff;
- get_n_bytes_data_from_ROM(addrHigh,addrMid,addrLow,fontbuf,8);/*取8个字节的数据,存到"fontbuf[32]"*/
-
- display_graphic_5x7(y,x,fontbuf);/*显示5x7的ASCII字到LCD上,y为页地址,x为列地址,fontbuf[]为数据*/
- i+=1;
- x+=6;
- }
- else
- i++;
- }
-
- }
- /*显示5*7点阵图像、num, 或5x7点阵的自造字符、其他图标*/
- void display_graphic_num_5x7(u8 page,u8 column,u8 *dp)
- {
- u8 col_cnt;
- u8 page_address;
- u8 column_address_L,column_address_H;
- page_address = 0xb0+page-1;
-
- lcd_cs1(0);
-
- column_address_L =(column&0x0f)-1;
- column_address_H =((column>>4)&0x0f)+0x10;
-
- transfer_command_lcd(page_address); /*Set Page Address*/
- transfer_command_lcd(column_address_H); /*Set MSB of column Address*/
- transfer_command_lcd(column_address_L); /*Set LSB of column Address*/
-
- for (col_cnt=0;col_cnt<6;col_cnt++)
- {
- transfer_data_lcd(*dp);
- dp++;
- }
- lcd_cs1(1);
- }
- void display_string_small(u8 y,u8 x,u8 *text)
- {
- u8 i= 0;
- u8 addrHigh,addrMid,addrLow ;
- while((text[i]>0x00))
- {
- if((text[i]>=0x20)&&(text[i]<=0x7e))
- {
- u8 fontbuf[8];
- fontaddr = (text[i]- 0x20);
- fontaddr = (unsigned long)(fontaddr*8);
- fontaddr = (unsigned long)(fontaddr+0x3bfc0);
- addrHigh = (fontaddr&0xff0000)>>16;
- addrMid = (fontaddr&0xff00)>>8;
- addrLow = fontaddr&0xff;
- get_n_bytes_data_from_ROM(addrHigh,addrMid,addrLow,fontbuf,8);/*取8个字节的数据,存到"fontbuf[32]"*/
- display_graphic_num_5x7(y,x,fontbuf);/*显示5x7的num到LCD上,y为页地址,x为列地址,fontbuf[]为数据*/
- i+=1;
- x+=6;
- }
- else i++;
- }
- }
复制代码 下一篇上传APP和主函数代码
山东交通学院
|