#include"OLED.h"/*宽8像素,高16像素*/constuint8_t OLED_F8x16[][16]={0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,// 00x00,0x00,0x00,0xF8,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x33,0x30,0x00,0x00,0x00,// ! 10x00,0x16,0x0E,0x00,0x16,0x0E,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,// " 20x40,0xC0,0x78,0x40,0xC0,0x78,0x40,0x00,0x04,0x3F,0x04,0x04,0x3F,0x04,0x04,0x00,// # 30x00,0x70,0x88,0xFC,0x08,0x30,0x00,0x00,0x00,0x18,0x20,0xFF,0x21,0x1E,0x00,0x00,// $ 40xF0,0x08,0xF0,0x00,0xE0,0x18,0x00,0x00,0x00,0x21,0x1C,0x03,0x1E,0x21,0x1E,0x00,// % 50x00,0xF0,0x08,0x88,0x70,0x00,0x00,0x00,0x1E,0x21,0x23,0x24,0x19,0x27,0x21,0x10,// & 60x00,0x00,0x00,0x16,0x0E,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,// ' 70x00,0x00,0x00,0xE0,0x18,0x04,0x02,0x00,0x00,0x00,0x00,0x07,0x18,0x20,0x40,0x00,// ( 80x00,0x02,0x04,0x18,0xE0,0x00,0x00,0x00,0x00,0x40,0x20,0x18,0x07,0x00,0x00,0x00,// ) 90x40,0x40,0x80,0xF0,0x80,0x40,0x40,0x00,0x02,0x02,0x01,0x0F,0x01,0x02,0x02,0x00,// * 100x00,0x00,0x00,0xF0,0x00,0x00,0x00,0x00,0x01,0x01,0x01,0x1F,0x01,0x01,0x01,0x00,// + 110x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xB0,0x70,0x00,0x00,0x00,0x00,0x00,// , 120x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x01,0x01,0x01,0x01,0x01,0x01,// - 130x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x30,0x30,0x00,0x00,0x00,0x00,0x00,// . 140x00,0x00,0x00,0x00,0x80,0x60,0x18,0x04,0x00,0x60,0x18,0x06,0x01,0x00,0x00,0x00,// / 150x00,0xE0,0x10,0x08,0x08,0x10,0xE0,0x00,0x00,0x0F,0x10,0x20,0x20,0x10,0x0F,0x00,// 0 160x00,0x10,0x10,0xF8,0x00,0x00,0x00,0x00,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00,// 1 170x00,0x70,0x08,0x08,0x08,0x88,0x70,0x00,0x00,0x30,0x28,0x24,0x22,0x21,0x30,0x00,// 2 180x00,0x30,0x08,0x88,0x88,0x48,0x30,0x00,0x00,0x18,0x20,0x20,0x20,0x11,0x0E,0x00,// 3 190x00,0x00,0xC0,0x20,0x10,0xF8,0x00,0x00,0x00,0x07,0x04,0x24,0x24,0x3F,0x24,0x00,// 4 200x00,0xF8,0x08,0x88,0x88,0x08,0x08,0x00,0x00,0x19,0x21,0x20,0x20,0x11,0x0E,0x00,// 5 210x00,0xE0,0x10,0x88,0x88,0x18,0x00,0x00,0x00,0x0F,0x11,0x20,0x20,0x11,0x0E,0x00,// 6 220x00,0x38,0x08,0x08,0xC8,0x38,0x08,0x00,0x00,0x00,0x00,0x3F,0x00,0x00,0x00,0x00,// 7 230x00,0x70,0x88,0x08,0x08,0x88,0x70,0x00,0x00,0x1C,0x22,0x21,0x21,0x22,0x1C,0x00,// 8 240x00,0xE0,0x10,0x08,0x08,0x10,0xE0,0x00,0x00,0x00,0x31,0x22,0x22,0x11,0x0F,0x00,// 9 250x00,0x00,0x00,0xC0,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x30,0x30,0x00,0x00,0x00,// : 260x00,0x00,0x00,0xC0,0xC0,0x00,0x00,0x00,0x00,0x00,0x80,0xB0,0x70,0x00,0x00,0x00,// ; 270x00,0x00,0x80,0x40,0x20,0x10,0x08,0x00,0x00,0x01,0x02,0x04,0x08,0x10,0x20,0x00,// < 280x40,0x40,0x40,0x40,0x40,0x40,0x40,0x00,0x04,0x04,0x04,0x04,0x04,0x04,0x04,0x00,// = 290x00,0x08,0x10,0x20,0x40,0x80,0x00,0x00,0x00,0x20,0x10,0x08,0x04,0x02,0x01,0x00,// > 300x00,0x70,0x48,0x08,0x08,0x08,0xF0,0x00,0x00,0x00,0x00,0x30,0x36,0x01,0x00,0x00,// ? 310xC0,0x30,0xC8,0x28,0xE8,0x10,0xE0,0x00,0x07,0x18,0x27,0x24,0x23,0x14,0x0B,0x00,// @ 320x00,0x00,0xC0,0x38,0xE0,0x00,0x00,0x00,0x20,0x3C,0x23,0x02,0x02,0x27,0x38,0x20,// A 330x08,0xF8,0x88,0x88,0x88,0x70,0x00,0x00,0x20,0x3F,0x20,0x20,0x20,0x11,0x0E,0x00,// B 340xC0,0x30,0x08,0x08,0x08,0x08,0x38,0x00,0x07,0x18,0x20,0x20,0x20,0x10,0x08,0x00,// C 350x08,0xF8,0x08,0x08,0x08,0x10,0xE0,0x00,0x20,0x3F,0x20,0x20,0x20,0x10,0x0F,0x00,// D 360x08,0xF8,0x88,0x88,0xE8,0x08,0x10,0x00,0x20,0x3F,0x20,0x20,0x23,0x20,0x18,0x00,// E 370x08,0xF8,0x88,0x88,0xE8,0x08,0x10,0x00,0x20,0x3F,0x20,0x00,0x03,0x00,0x00,0x00,// F 380xC0,0x30,0x08,0x08,0x08,0x38,0x00,0x00,0x07,0x18,0x20,0x20,0x22,0x1E,0x02,0x00,// G 390x08,0xF8,0x08,0x00,0x00,0x08,0xF8,0x08,0x20,0x3F,0x21,0x01,0x01,0x21,0x3F,0x20,// H 400x00,0x08,0x08,0xF8,0x08,0x08,0x00,0x00,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00,// I 410x00,0x00,0x08,0x08,0xF8,0x08,0x08,0x00,0xC0,0x80,0x80,0x80,0x7F,0x00,0x00,0x00,// J 420x08,0xF8,0x88,0xC0,0x28,0x18,0x08,0x00,0x20,0x3F,0x20,0x01,0x26,0x38,0x20,0x00,// K 430x08,0xF8,0x08,0x00,0x00,0x00,0x00,0x00,0x20,0x3F,0x20,0x20,0x20,0x20,0x30,0x00,// L 440x08,0xF8,0xF8,0x00,0xF8,0xF8,0x08,0x00,0x20,0x3F,0x00,0x3F,0x00,0x3F,0x20,0x00,// M 450x08,0xF8,0x30,0xC0,0x00,0x08,0xF8,0x08,0x20,0x3F,0x20,0x00,0x07,0x18,0x3F,0x00,// N 460xE0,0x10,0x08,0x08,0x08,0x10,0xE0,0x00,0x0F,0x10,0x20,0x20,0x20,0x10,0x0F,0x00,// O 470x08,0xF8,0x08,0x08,0x08,0x08,0xF0,0x00,0x20,0x3F,0x21,0x01,0x01,0x01,0x00,0x00,// P 480xE0,0x10,0x08,0x08,0x08,0x10,0xE0,0x00,0x0F,0x18,0x24,0x24,0x38,0x50,0x4F,0x00,// Q 490x08,0xF8,0x88,0x88,0x88,0x88,0x70,0x00,0x20,0x3F,0x20,0x00,0x03,0x0C,0x30,0x20,// R 500x00,0x70,0x88,0x08,0x08,0x08,0x38,0x00,0x00,0x38,0x20,0x21,0x21,0x22,0x1C,0x00,// S 510x18,0x08,0x08,0xF8,0x08,0x08,0x18,0x00,0x00,0x00,0x20,0x3F,0x20,0x00,0x00,0x00,// T 520x08,0xF8,0x08,0x00,0x00,0x08,0xF8,0x08,0x00,0x1F,0x20,0x20,0x20,0x20,0x1F,0x00,// U 530x08,0x78,0x88,0x00,0x00,0xC8,0x38,0x08,0x00,0x00,0x07,0x38,0x0E,0x01,0x00,0x00,// V 540xF8,0x08,0x00,0xF8,0x00,0x08,0xF8,0x00,0x03,0x3C,0x07,0x00,0x07,0x3C,0x03,0x00,// W 550x08,0x18,0x68,0x80,0x80,0x68,0x18,0x08,0x20,0x30,0x2C,0x03,0x03,0x2C,0x30,0x20,// X 560x08,0x38,0xC8,0x00,0xC8,0x38,0x08,0x00,0x00,0x00,0x20,0x3F,0x20,0x00,0x00,0x00,// Y 570x10,0x08,0x08,0x08,0xC8,0x38,0x08,0x00,0x20,0x38,0x26,0x21,0x20,0x20,0x18,0x00,// Z 580x00,0x00,0x00,0xFE,0x02,0x02,0x02,0x00,0x00,0x00,0x00,0x7F,0x40,0x40,0x40,0x00,// [ 590x00,0x0C,0x30,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x06,0x38,0xC0,0x00,// \ 600x00,0x02,0x02,0x02,0xFE,0x00,0x00,0x00,0x00,0x40,0x40,0x40,0x7F,0x00,0x00,0x00,// ] 610x00,0x20,0x10,0x08,0x04,0x08,0x10,0x20,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,// ^ 620x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,// _ 630x00,0x02,0x04,0x08,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,// ` 640x00,0x00,0x80,0x80,0x80,0x80,0x00,0x00,0x00,0x19,0x24,0x22,0x22,0x22,0x3F,0x20,// a 650x08,0xF8,0x00,0x80,0x80,0x00,0x00,0x00,0x00,0x3F,0x11,0x20,0x20,0x11,0x0E,0x00,// b 660x00,0x00,0x00,0x80,0x80,0x80,0x00,0x00,0x00,0x0E,0x11,0x20,0x20,0x20,0x11,0x00,// c 670x00,0x00,0x00,0x80,0x80,0x88,0xF8,0x00,0x00,0x0E,0x11,0x20,0x20,0x10,0x3F,0x20,// d 680x00,0x00,0x80,0x80,0x80,0x80,0x00,0x00,0x00,0x1F,0x22,0x22,0x22,0x22,0x13,0x00,// e 690x00,0x80,0x80,0xF0,0x88,0x88,0x88,0x18,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00,// f 700x00,0x00,0x80,0x80,0x80,0x80,0x80,0x00,0x00,0x6B,0x94,0x94,0x94,0x93,0x60,0x00,// g 710x08,0xF8,0x00,0x80,0x80,0x80,0x00,0x00,0x20,0x3F,0x21,0x00,0x00,0x20,0x3F,0x20,// h 720x00,0x80,0x98,0x98,0x00,0x00,0x00,0x00,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00,// i 730x00,0x00,0x00,0x80,0x98,0x98,0x00,0x00,0x00,0xC0,0x80,0x80,0x80,0x7F,0x00,0x00,// j 740x08,0xF8,0x00,0x00,0x80,0x80,0x80,0x00,0x20,0x3F,0x24,0x02,0x2D,0x30,0x20,0x00,// k 750x00,0x08,0x08,0xF8,0x00,0x00,0x00,0x00,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00,// l 760x80,0x80,0x80,0x80,0x80,0x80,0x80,0x00,0x20,0x3F,0x20,0x00,0x3F,0x20,0x00,0x3F,// m 770x00,0x80,0x80,0x00,0x80,0x80,0x00,0x00,0x00,0x20,0x3F,0x21,0x00,0x20,0x3F,0x20,// n 780x00,0x00,0x80,0x80,0x80,0x80,0x00,0x00,0x00,0x1F,0x20,0x20,0x20,0x20,0x1F,0x00,// o 790x80,0x80,0x00,0x80,0x80,0x00,0x00,0x00,0x80,0xFF,0xA1,0x20,0x20,0x11,0x0E,0x00,// p 800x00,0x00,0x00,0x80,0x80,0x80,0x80,0x00,0x00,0x0E,0x11,0x20,0x20,0xA0,0xFF,0x80,// q 810x80,0x80,0x80,0x00,0x80,0x80,0x80,0x00,0x20,0x20,0x3F,0x21,0x20,0x00,0x01,0x00,// r 820x00,0x00,0x80,0x80,0x80,0x80,0x80,0x00,0x00,0x33,0x24,0x24,0x24,0x24,0x19,0x00,// s 830x00,0x80,0x80,0xE0,0x80,0x80,0x00,0x00,0x00,0x00,0x00,0x1F,0x20,0x20,0x00,0x00,// t 840x80,0x80,0x00,0x00,0x00,0x80,0x80,0x00,0x00,0x1F,0x20,0x20,0x20,0x10,0x3F,0x20,// u 850x80,0x80,0x80,0x00,0x00,0x80,0x80,0x80,0x00,0x01,0x0E,0x30,0x08,0x06,0x01,0x00,// v 860x80,0x80,0x00,0x80,0x00,0x80,0x80,0x80,0x0F,0x30,0x0C,0x03,0x0C,0x30,0x0F,0x00,// w 870x00,0x80,0x80,0x00,0x80,0x80,0x80,0x00,0x00,0x20,0x31,0x2E,0x0E,0x31,0x20,0x00,// x 880x80,0x80,0x80,0x00,0x00,0x80,0x80,0x80,0x80,0x81,0x8E,0x70,0x18,0x06,0x01,0x00,// y 890x00,0x80,0x80,0x80,0x80,0x80,0x80,0x00,0x00,0x21,0x30,0x2C,0x22,0x21,0x30,0x00,// z 900x00,0x00,0x00,0x00,0x80,0x7C,0x02,0x02,0x00,0x00,0x00,0x00,0x00,0x3F,0x40,0x40,// { 910x00,0x00,0x00,0x00,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0x00,0x00,0x00,// | 920x00,0x02,0x02,0x7C,0x80,0x00,0x00,0x00,0x00,0x40,0x40,0x3F,0x00,0x00,0x00,0x00,// } 930x00,0x80,0x40,0x40,0x80,0x00,0x00,0x80,0x00,0x00,0x00,0x00,0x00,0x01,0x01,0x00,// ~ 94};/*宽6像素,高8像素*/constuint8_t OLED_F6x8[][6]={0x00,0x00,0x00,0x00,0x00,0x00,// 00x00,0x00,0x00,0x2F,0x00,0x00,// ! 10x00,0x00,0x07,0x00,0x07,0x00,// " 20x00,0x14,0x7F,0x14,0x7F,0x14,// # 30x00,0x24,0x2A,0x7F,0x2A,0x12,// $ 40x00,0x23,0x13,0x08,0x64,0x62,// % 50x00,0x36,0x49,0x55,0x22,0x50,// & 60x00,0x00,0x00,0x07,0x00,0x00,// ' 70x00,0x00,0x1C,0x22,0x41,0x00,// ( 80x00,0x00,0x41,0x22,0x1C,0x00,// ) 90x00,0x14,0x08,0x3E,0x08,0x14,// * 100x00,0x08,0x08,0x3E,0x08,0x08,// + 110x00,0x00,0x00,0xA0,0x60,0x00,// , 120x00,0x08,0x08,0x08,0x08,0x08,// - 130x00,0x00,0x60,0x60,0x00,0x00,// . 140x00,0x20,0x10,0x08,0x04,0x02,// / 150x00,0x3E,0x51,0x49,0x45,0x3E,// 0 160x00,0x00,0x42,0x7F,0x40,0x00,// 1 170x00,0x42,0x61,0x51,0x49,0x46,// 2 180x00,0x21,0x41,0x45,0x4B,0x31,// 3 190x00,0x18,0x14,0x12,0x7F,0x10,// 4 200x00,0x27,0x45,0x45,0x45,0x39,// 5 210x00,0x3C,0x4A,0x49,0x49,0x30,// 6 220x00,0x01,0x71,0x09,0x05,0x03,// 7 230x00,0x36,0x49,0x49,0x49,0x36,// 8 240x00,0x06,0x49,0x49,0x29,0x1E,// 9 250x00,0x00,0x36,0x36,0x00,0x00,// : 260x00,0x00,0x56,0x36,0x00,0x00,// ; 270x00,0x08,0x14,0x22,0x41,0x00,// < 280x00,0x14,0x14,0x14,0x14,0x14,// = 290x00,0x00,0x41,0x22,0x14,0x08,// > 300x00,0x02,0x01,0x51,0x09,0x06,// ? 310x00,0x3E,0x49,0x55,0x59,0x2E,// @ 320x00,0x7C,0x12,0x11,0x12,0x7C,// A 330x00,0x7F,0x49,0x49,0x49,0x36,// B 340x00,0x3E,0x41,0x41,0x41,0x22,// C 350x00,0x7F,0x41,0x41,0x22,0x1C,// D 360x00,0x7F,0x49,0x49,0x49,0x41,// E 370x00,0x7F,0x09,0x09,0x09,0x01,// F 380x00,0x3E,0x41,0x49,0x49,0x7A,// G 390x00,0x7F,0x08,0x08,0x08,0x7F,// H 400x00,0x00,0x41,0x7F,0x41,0x00,// I 410x00,0x20,0x40,0x41,0x3F,0x01,// J 420x00,0x7F,0x08,0x14,0x22,0x41,// K 430x00,0x7F,0x40,0x40,0x40,0x40,// L 440x00,0x7F,0x02,0x0C,0x02,0x7F,// M 450x00,0x7F,0x04,0x08,0x10,0x7F,// N 460x00,0x3E,0x41,0x41,0x41,0x3E,// O 470x00,0x7F,0x09,0x09,0x09,0x06,// P 480x00,0x3E,0x41,0x51,0x21,0x5E,// Q 490x00,0x7F,0x09,0x19,0x29,0x46,// R 500x00,0x46,0x49,0x49,0x49,0x31,// S 510x00,0x01,0x01,0x7F,0x01,0x01,// T 520x00,0x3F,0x40,0x40,0x40,0x3F,// U 530x00,0x1F,0x20,0x40,0x20,0x1F,// V 540x00,0x3F,0x40,0x38,0x40,0x3F,// W 550x00,0x63,0x14,0x08,0x14,0x63,// X 560x00,0x07,0x08,0x70,0x08,0x07,// Y 570x00,0x61,0x51,0x49,0x45,0x43,// Z 580x00,0x00,0x7F,0x41,0x41,0x00,// [ 590x00,0x02,0x04,0x08,0x10,0x20,// \ 600x00,0x00,0x41,0x41,0x7F,0x00,// ] 610x00,0x04,0x02,0x01,0x02,0x04,// ^ 620x00,0x40,0x40,0x40,0x40,0x40,// _ 630x00,0x00,0x01,0x02,0x04,0x00,// ` 640x00,0x20,0x54,0x54,0x54,0x78,// a 650x00,0x7F,0x48,0x44,0x44,0x38,// b 660x00,0x38,0x44,0x44,0x44,0x20,// c 670x00,0x38,0x44,0x44,0x48,0x7F,// d 680x00,0x38,0x54,0x54,0x54,0x18,// e 690x00,0x08,0x7E,0x09,0x01,0x02,// f 700x00,0x18,0xA4,0xA4,0xA4,0x7C,// g 710x00,0x7F,0x08,0x04,0x04,0x78,// h 720x00,0x00,0x44,0x7D,0x40,0x00,// i 730x00,0x40,0x80,0x84,0x7D,0x00,// j 740x00,0x7F,0x10,0x28,0x44,0x00,// k 750x00,0x00,0x41,0x7F,0x40,0x00,// l 760x00,0x7C,0x04,0x18,0x04,0x78,// m 770x00,0x7C,0x08,0x04,0x04,0x78,// n 780x00,0x38,0x44,0x44,0x44,0x38,// o 790x00,0xFC,0x24,0x24,0x24,0x18,// p 800x00,0x18,0x24,0x24,0x18,0xFC,// q 810x00,0x7C,0x08,0x04,0x04,0x08,// r 820x00,0x48,0x54,0x54,0x54,0x20,// s 830x00,0x04,0x3F,0x44,0x40,0x20,// t 840x00,0x3C,0x40,0x40,0x20,0x7C,// u 850x00,0x1C,0x20,0x40,0x20,0x1C,// v 860x00,0x3C,0x40,0x30,0x40,0x3C,// w 870x00,0x44,0x28,0x10,0x28,0x44,// x 880x00,0x1C,0xA0,0xA0,0xA0,0x7C,// y 890x00,0x44,0x64,0x54,0x4C,0x44,// z 900x00,0x00,0x08,0x7F,0x41,0x00,// { 910x00,0x00,0x00,0x7F,0x00,0x00,// | 920x00,0x00,0x41,0x7F,0x08,0x00,// } 930x00,0x08,0x04,0x08,0x10,0x08,// ~ 94};/*********************ASCII字模数据*/uint8_t commandinterfection[]={0xAE,0XD5,0X80,0XA8,0X3F,0XD3,0X00,0X40,0XA1,0XC8,0XDA,0X12,0X81,0XCF,0XD9,0XF1,0XDB,0X30,0XA4,0XA6,0X8D,0X14,0XAF};//定义初始化命令uint8_t OLED_DisplayBuf[8][128];//定义显存数组,8行128列voidOLED_Inite(void){OLED_SendSeveralcommand(commandinterfection,sizeof(commandinterfection)/sizeof(commandinterfection[0]));}voidOLED_SendSeveralcommand(uint8_t*i,uint8_t length){MyI2C_Strat();MYI2C_SendByte(0X78);//发送地址位,地址位最后一位决定为读模式还是写模式MYI2C_ReceiveACK();MYI2C_SendByte(0x00);//开启写命令模式MYI2C_ReceiveACK();//每写完一位都必须有一位应答接收位for(int j=0;j<length;j++){MYI2C_SendByte(*i);MYI2C_ReceiveACK();
i++;}MyI2C_Finish();}voidOLED_Sendsinglecommand(uint8_t i){MyI2C_Strat();MYI2C_SendByte(0X78);MYI2C_ReceiveACK();MYI2C_SendByte(0x00);//开启写命令模式MYI2C_ReceiveACK();//每写完一位都必须有一位应答接收位MYI2C_SendByte(i);MYI2C_ReceiveACK();MyI2C_Finish();}voidOLED_SendsingleByte(uint8_t i){MyI2C_Strat();MYI2C_SendByte(0X78);MYI2C_ReceiveACK();MYI2C_SendByte(0x40);//开启写命令模式MYI2C_ReceiveACK();//每写完一位都必须有一位应答接收位MYI2C_SendByte(i);MYI2C_ReceiveACK();MyI2C_Finish();}voidOLED_SendByte(uint8_t*i,uint8_t length){MyI2C_Strat();MYI2C_SendByte(0X78);//发送地址位,地址位最后一位决定为读模式还是写模式MYI2C_ReceiveACK();MYI2C_SendByte(0x40);//开启写命令模式MYI2C_ReceiveACK();//每写完一位都必须有一位应答接收位for(int j=0;j<length;j++){MYI2C_SendByte(*i);MYI2C_ReceiveACK();
i++;}MyI2C_Finish();}voidOLED_Set_Cursor(uint8_t x,uint8_t y){OLED_Sendsinglecommand((0x0F& x )|0x00);OLED_Sendsinglecommand((0XF0& x )>>4|0X10);OLED_Sendsinglecommand(0XB0|y);}voidOLED_Clear(void){for(int j=0;j<8;j++){OLED_Set_Cursor(0,j);for(int i=0;i<128;i++){
OLED_DisplayBuf[j][i]=0x00;//j为行,i为列}}}voidOLED_Update(void){for(uint8_t i=0;i<8;i++){OLED_Set_Cursor(0,i);OLED_SendByte(OLED_DisplayBuf[i],128);}}voidOLED_ShowChar(uint8_t x,uint8_t y,char Char,uint8_t width){if(width==6){OLED_ShowImage(x,y,width,8,OLED_F6x8[Char-' ']);}elseif(width==8){OLED_ShowImage(x,y,width,16,OLED_F8x16[Char-' ']);}}voidOLED_ShowString(uint8_t x,uint8_t y,char* String,uint8_t Width){uint8_t i;for(uint8_t i =0;String[i]!='\0'; i++){OLED_ShowChar(x,y+i*Width,String[i],Width);}}voidOLED_ShowImage(uint8_t x,uint8_t y,uint8_t width,uint8_t Height,constuint8_t* Image)//例如要在2,3,4页中跨页显示一个宽度为8,高度为15的图像{uint8_t i;uint8_t j;for(j=0;j<(Height-1)/8+1;j++){for(i=0;i<width;i++){
OLED_DisplayBuf[x/8+j][y+i]|=(Image[i+j*width]<<(x%8));
OLED_DisplayBuf[x/8+1+j][y+i]|=Image[i+j*width]>>(8-x%8);}}}voidOLED_ClearPoint(uint8_t x,uint8_t y){
OLED_DisplayBuf[x/8][y]&=~(0x01<<(x%8));//由于OLED为低位在前,因此取余后是多少就是第几位}voidOLED_Light_Point(uint8_t x,uint8_t y){
OLED_DisplayBuf[x/8][y]|=(0x01<<(x%8));//由于OLED为低位在前,因此取余后是多少就是第几位}voidOLED_ClearArea(uint8_t x,uint8_t y,uint8_t width,uint8_t Height){for(uint8_t j=0;j<width;j++){for(uint8_t i=0;i<Height;i++){OLED_ClearPoint(x+i,y+j);}}}voidOLED_DrawWave(uint8_t* Collection,uint8_t length){uint8_t i;uint8_t XPoint,YPoint;uint8_t X_LastPoint,Y_LastPoint;
XPoint=Collection[0];
YPoint=0;for(i=0;i<length;i++){
X_LastPoint=XPoint;
Y_LastPoint=YPoint;
XPoint=Collection[i];
YPoint=i;OLED_Drawline(X_LastPoint,Y_LastPoint,XPoint,YPoint);OLED_Update();}}voidOLED_Drawline(int8_t x0,int8_t y0,int8_t x1,int8_t y1){float k;if(x0==x1){if(y1>=y0){for(uint8_t i=0;i<(y1-y0);i++){OLED_Light_Point(x0,y0+i);}}elseif(y1<y0){for(uint8_t i=0;i<(y0-y1);i++){OLED_Light_Point(x0,y0-i);}}return;}//单独对直线进行判断
k=(float)(y1-y0)/(x1-x0);if(fabs(k)<=1.0){for(uint8_t i=0;i<abs(x1-x0);i++){if(x1>x0)OLED_Light_Point(x0+i,y0+i*k);elseif(x1<x0)OLED_Light_Point(x0-i,y0+i*(-k));}}elseif(fabs(k)>=1.0){
k=(float)(x1-x0)/(y1-y0);for(uint8_t i=0;i<abs(y1-y0);i++){if(y1>y0)OLED_Light_Point(x0+i*k,y0+i);elseif(y1<y0)OLED_Light_Point(x0+i*(-k),y0-i);}}}voidOLED_Printf(int16_t X,int16_t Y,uint8_t FontSize,char*format,...){char String[256];//定义字符数组
va_list arg;//定义可变参数列表数据类型的变量argva_start(arg, format);//从format开始,接收参数列表到arg变量vsprintf(String, format, arg);//使用vsprintf打印格式化字符串和参数列表到字符数组中va_end(arg);//结束变量argOLED_ShowString(X, Y, String, FontSize);//OLED显示字符数组(字符串)}//操作函数画一个长75,宽15的进度条,进度条和count的值对应voidOLED_ShowFram(uint8_t x,uint8_t y,uint16_t count){uint8_t Long=75;uint8_t width=15;OLED_Drawline(x,y,x+width,y);OLED_Drawline(x,y,x,y+Long);OLED_Drawline(x+width,y,x+width,y+Long);OLED_Drawline(x,y+Long,x+width,y+Long);if(count<=Long)OLED_FullArea(x,y,count,width);elseOLED_FullArea(x,y,Long,width);}