[導讀]oled.c文件內容如下:#include"oled.h"#include"lpc11xx.h"#include"w25q16.h"//OLED////[0]0123...127//[1]0123...127//[2]0123...127//[3]0123...127uint8_tOLED_GRAM[128][4];constunsignedcharmenu_op[3][16]={{
oled.c文件內容如下:
#include"oled.h"#include"lpc11xx.h"#include"w25q16.h"http://OLED////[0]0123...127//[1]0123...127//[2]0123...127//[3]0123...127uint8_tOLED_GRAM[128][4];constunsignedcharmenu_op[3][16]={{0x08,0x08,0x1C,0x1C,0x3E,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08},/*向上的箭頭*/{0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x3E,0x1C,0x1C,0x08,0x08},/*向下的箭頭*/{0x08,0x08,0x1C,0x1C,0x3E,0x08,0x08,0x08,0x08,0x08,0x08,0x3E,0x1C,0x1C,0x08,0x08},/*雙向的箭頭*/};voiddelay_ms(uint16_tms){uint16_ti,j;for(i=0;i<5000;i++)for(j=0;jDATA|=(1<<4);//DB7elseLPC_GPIO0->DATA&=~(1<<4);if((dat&0x40)==0x40)LPC_GPIO2->DATA|=(1<<1);//DB6elseLPC_GPIO2->DATA&=~(1<<1);if((dat&0x20)==0x20)LPC_GPIO2->DATA|=(1<<8);//DB5elseLPC_GPIO2->DATA&=~(1<<8);if((dat&0x10)==0x10)LPC_GPIO2->DATA|=(1<<7);//DB4elseLPC_GPIO2->DATA&=~(1<<7);if((dat&0x08)==0x08)LPC_GPIO2->DATA|=(1<<9);//DB3elseLPC_GPIO2->DATA&=~(1<<9);if((dat&0x04)==0x04)LPC_GPIO0->DATA|=(1<<7);//DB2elseLPC_GPIO0->DATA&=~(1<<7);if((dat&0x02)==0x02)LPC_GPIO3->DATA|=(1<<5);//DB1elseLPC_GPIO3->DATA&=~(1<<5);if((dat&0x01)==0x01)LPC_GPIO2->DATA|=(1<<5);//DB0elseLPC_GPIO2->DATA&=~(1<<5);}voidOLED_WR_Byte(uint8_tdat,uint8_tcmd){DATAOUT(dat);if(cmd==1)OLED_DC_H;elseOLED_DC_L;OLED_CS_L;OLED_WR_L;OLED_WR_H;OLED_CS_H;OLED_DC_H;}voidOLED_Clear(void){uint8_ti,n;for(i=0;i<4;i++)for(n=0;n<128;n++)OLED_GRAM[n][i]=0X00;OLED_Refresh_Gram();//}voidOLED_Init(void){LPC_GPIO2->DIR|=(1<<4);//OLED_RESETLPC_GPIO2->DATA|=(1<<4);LPC_GPIO1->DIR|=(1<<9);//OLED_CSLPC_GPIO1->DATA|=(1<<9);LPC_GPIO0->DIR|=(1<<3);//OLED_DCLPC_GPIO0->DATA|=(1<<3);LPC_GPIO3->DIR|=(1<<4);//OLED_RDLPC_GPIO3->DATA|=(1<<4);LPC_GPIO0->DIR|=(1<<5);//OLED_WRLPC_GPIO0->DATA|=(1<<5);LPC_GPIO0->DIR|=(1<<4);//DB7LPC_GPIO0->DATA|=(1<<4);LPC_GPIO2->DIR|=(1<<1);//DB6LPC_GPIO2->DATA|=(1<<1);LPC_GPIO2->DIR|=(1<<8);//DB5LPC_GPIO2->DATA|=(1<<8);LPC_GPIO2->DIR|=(1<<7);//DB4LPC_GPIO2->DATA|=(1<<7);LPC_GPIO2->DIR|=(1<<9);//DB3LPC_GPIO2->DATA|=(1<<9);LPC_GPIO0->DIR|=(1<<7);//DB2LPC_GPIO0->DATA|=(1<<7);LPC_GPIO3->DIR|=(1<<5);//DB1LPC_GPIO3->DATA|=(1<<5);LPC_GPIO2->DIR|=(1<<5);//DB0LPC_GPIO2->DATA|=(1<<5);OLED_RST_L;delay_ms(100);OLED_RST_H;OLED_WR_Byte(0xAE,OLED_CMD);//OLED_WR_Byte(0x00,OLED_CMD);//OLED_WR_Byte(0x10,OLED_CMD);//OLED_WR_Byte(0x40,OLED_CMD);//OLED_WR_Byte(0X2E,OLED_CMD);//OLED_WR_Byte(0x81,OLED_CMD);//OLED_WR_Byte(0X32,OLED_CMD);//OLED_WR_Byte(0x82,OLED_CMD);//OLED_WR_Byte(0x80,OLED_CMD);//OLED_WR_Byte(0xA1,OLED_CMD);//OLED_WR_Byte(0xA6,OLED_CMD);//OLED_WR_Byte(0xA8,OLED_CMD);//OLED_WR_Byte(0x3F,OLED_CMD);//OLED_WR_Byte(0xAD,OLED_CMD);//OLED_WR_Byte(0x8E,OLED_CMD);//OLED_WR_Byte(0xC8,OLED_CMD);//OLED_WR_Byte(0xD3,OLED_CMD);//OLED_WR_Byte(0x40,OLED_CMD);//OLED_WR_Byte(0xD5,OLED_CMD);//OLED_WR_Byte(0xf0,OLED_CMD);//OLED_WR_Byte(0xD8,OLED_CMD);//OLED_WR_Byte(0x05,OLED_CMD);//OLED_WR_Byte(0xD9,OLED_CMD);//OLED_WR_Byte(0xF1,OLED_CMD);//OLED_WR_Byte(0xDA,OLED_CMD);//OLED_WR_Byte(0x12,OLED_CMD);OLED_WR_Byte(0x91,OLED_CMD);OLED_WR_Byte(0x3F,OLED_CMD);OLED_WR_Byte(0x3F,OLED_CMD);OLED_WR_Byte(0x3F,OLED_CMD);OLED_WR_Byte(0x3F,OLED_CMD);OLED_WR_Byte(0xAF,OLED_CMD);OLED_Clear();}voidOLED_DrawPoint(uint8_tx,uint8_ty,uint8_tt){uint8_tpos,bx,temp=0;if(x>127||y>31)return;//pos=y/8;bx=y%8;temp=1< 0XFE||GBKH<0X81)return;GBKH-=0x81;GBKL-=0x40;offset=((uint32_t)192*GBKH+GBKL)*32;//得到字庫中的字節(jié)偏移量W25Q16_Read(dz_data,offset+0x100,32);return;}/**********************************************//*函數(shù)功能:顯示16*16點陣中文*//*入口參數(shù):x,y:起點坐標*//**hz:漢字*//*mode:1,正常2,反白*//**********************************************/voidOLED_Show_hz(uint8_tx,uint8_ty,uint8_t*hz,uint8_tmode){uint8_ti,j,temp,xtemp;uint8_tdz_data[32];xtemp=x;Get_GBK_DZK(hz,dz_data);for(i=0;i<32;i++){temp=dz_data[i];for(j=0;j<8;j++){if(temp&0x80)OLED_DrawPoint(x,y,mode);elseOLED_DrawPoint(x,y,!mode);temp<<=1;x++;if(x-xtemp>15){x=xtemp;y++;}}}//OLED_Refresh_Gram();return;}/**********************************************//*函數(shù)功能;從W25X16中提取點陣碼*//*入口參數(shù):code:ASCII*//*dz_data:存放點陣碼的數(shù)組*//**********************************************/voidGet_ASCII_DZK(uint8_tcode,uint8_t*buf){uint32_toffset;//點陣偏移量offset=code-0x20;//得到字庫中的字節(jié)偏移量W25Q16_Read(buf,offset*16+0x0E0000,16);return;}/**********************************************//*函數(shù)功能:顯示8*16點陣英文字符*//*入口參數(shù):x,y:起點坐標*//*num:字母或符號*//*注意:x,y的取值要在240到320范圍內*//**********************************************/voidOLED_ShowChar(uint8_tx,uint8_ty,uint8_tasc,uint8_tmode){uint8_ti,j,temp,xtemp;uint8_tasc_buf[16];xtemp=x;Get_ASCII_DZK(asc,asc_buf);for(i=0;i<16;i++){temp=asc_buf[i];for(j=0;j<8;j++){if(temp&0x80)OLED_DrawPoint(x,y,mode);elseOLED_DrawPoint(x,y,!mode);temp<<=1;x++;if(x-xtemp>7){x=xtemp;y++;}}}//OLED_Refresh_Gram();return;}/*********************************************//*函數(shù)功能:顯示字符串(中文和英文)*//*入口參數(shù):x,y:坐標*//**p:字符串*//*********************************************/voidOLED_ShowString(uint8_tx,uint8_ty,uint8_t*p,uint8_tmode){while(*p!='