⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 oled.c

📁 来宝160X128全彩OLED(1.8INCH)操作源码
💻 C
字号:
#include "Board.h"
int FrontColor[4];
int BackColor[4];
void InitOLEDIO()
{
  ShutDownOLED17V();
  AT91C_BASE_PIOB->PIO_PPUDR=PIN_OLEDCS+PIN_OLEDWR+PIN_OLEDRESET+PIN_OLEDDC+PIN_OLEDRD+0xff+0x1f00;
  AT91C_BASE_PIOB->PIO_PER=PIN_OLEDCS+PIN_OLEDWR+PIN_OLEDRESET+PIN_OLEDDC+PIN_OLEDRD+0xff+0x1f00;
  AT91C_BASE_PIOB->PIO_OWDR=PIN_OLEDCS+PIN_OLEDWR+PIN_OLEDRESET+PIN_OLEDDC+PIN_OLEDRD+0x1f00;
  AT91C_BASE_PIOB->PIO_OWER=0xff;
  AT91C_BASE_PIOB->PIO_ODSR=0xff;
  AT91C_BASE_PIOB->PIO_SODR=PIN_OLEDCS+PIN_OLEDWR+PIN_OLEDDC+PIN_OLEDRD+0x1f00;
  AT91C_BASE_PIOB->PIO_CODR=PIN_OLEDRESET;
  AT91C_BASE_PIOB->PIO_OER=PIN_OLEDCS+PIN_OLEDWR+PIN_OLEDRESET+PIN_OLEDDC+PIN_OLEDRD+0xff;
  AT91C_BASE_PIOB->PIO_ODR=0x1f00;
  RTTdelayms(10);
  AT91C_BASE_PIOB->PIO_SODR=PIN_OLEDRESET;
}

void OLEDSetColor(int r,int g,int b,int backr,int backg,int backb)
{
  FrontColor[0]=r>>2;FrontColor[1]=g>>2;FrontColor[2]=b>>2;
  BackColor[0]=backr>>2;BackColor[1]=backg>>2;BackColor[2]=backb>>2;
}

void OLEDDrawLine(int x1,int y1,int x2,int y2,int r,int g,int b)
{
  uint32 ui32;
  //OLEDCsLow();
  WriteOLEDCmd(0x21);
  WriteOLEDData(x1);WriteOLEDData(y1);
  WriteOLEDData(x2);WriteOLEDData(y2);
  WriteOLEDData(r>>2);WriteOLEDData(g>>2);WriteOLEDData(b>>2);
  //OLEDCsHigh();
  //ui32=(uint32)((x2-x1)+(y2-y1))*3;
 //if(ui32>65535)ui32=65535;
  //delay1_6us(ui32);
}

void WriteOLEDCmd(int cmd)
{
  AT91C_BASE_PIOB->PIO_CODR=PIN_OLEDDC;
  AT91C_BASE_PIOB->PIO_ODSR=cmd<<0;
  delay1_6us(12);
  AT91C_BASE_PIOB->PIO_CODR=PIN_OLEDWR;
  delay1_6us(12);
  AT91C_BASE_PIOB->PIO_SODR=PIN_OLEDWR;
}
//--
void WriteOLEDData(int data)
{
  int ui16;
  AT91C_BASE_PIOB->PIO_SODR=PIN_OLEDDC;
  AT91C_BASE_PIOB->PIO_ODSR=data<<0;
  ui16=AT91C_BASE_TC2->TC_CV;for(;;){if((AT91C_BASE_TC2->TC_CV-ui16)>2)break;};
  AT91C_BASE_PIOB->PIO_CODR=PIN_OLEDWR;
  ui16=AT91C_BASE_TC2->TC_CV;for(;;){if((AT91C_BASE_TC2->TC_CV-ui16)>2)break;};
  AT91C_BASE_PIOB->PIO_SODR=PIN_OLEDWR;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -