//============================== //读取三个屏中其中一个的存储区数据; //============================== unsigned char ReadData(unsigned char chipselect) { unsigned char backdat=0; if(chipselect=='L') while(ReadBusy('L')); //read busy,if busy stay here; if(chipselect=='M') while(ReadBusy('M')); if(chipselect=='R') while(ReadBusy('R')); DataDir=0x00; ComBus |= EN; ComBus &= ~EN; _delay_us(10); ComBus |= RW; ComBus |= RS; if(chipselect=='L') ComBus &= ~ChipCS1; if(chipselect=='M') ComBus &= ~ChipCS2; if(chipselect=='R') ComBus &= ~ChipCS3; ComBus |= EN; _delay_us(20); backdat = DataPin; ComBus &= ~EN; ComBus |= (ChipCS1|ChipCS2|ChipCS3); return(backdat); }
//=========================================== //选择向三个屏中一个写入数据; //=========================================== void WriteData(const unsigned char dat,unsigned char chipselect) { if(chipselect=='L') while(ReadBusy('L')); //read busy,if busy stay here; if(chipselect=='M') while(ReadBusy('M')); if(chipselect=='R') while(ReadBusy('R')); DataDir=0xff; ComBus |= EN; ComBus &= ~EN; _delay_us(10); ComBus &= ~RW; ComBus |= RS; if(chipselect=='L') ComBus &= ~ChipCS1; if(chipselect=='M') ComBus &= ~ChipCS2; if(chipselect=='R') ComBus &= ~ChipCS3; DataBus = dat; ComBus |= EN; _delay_us(20); //delay ComBus &= ~EN; ComBus |= (ChipCS1|ChipCS2|ChipCS3); }
/********************************************* 功能:写显示buffer 参数: XSize x方向数量 128点方向,调整为8的整数倍 YSize y方向数量 Dispbuff 显示数据保存位置。 要求数据的排列方式必须正确 *********************************************/ static void EPD_W21_WriteDispRam(unsigned char XSize, unsigned int YSize, unsigned char *Dispbuff) { int i = 0, j = 0; if (XSize % 8 != 0) { XSize = XSize + (8 - XSize % 8); } XSize = XSize / 8; //while(isEPD_W21_BUSY == 1); //wait ReadBusy(); EPD_W21_CS_0; EPD_W21_DC_0; //command write SPI_Write(0x24); EPD_W21_DC_1; //data write for (i = 0; i < YSize; i++) { for (j = 0; j < XSize; j++) { SPI_Write(*Dispbuff); Dispbuff++; } } EPD_W21_CS_1; }
/*-------------------------------------------------------*/ static void EPD_W21_WriteCMD_p1(unsigned char command, unsigned char para) { //while(isEPD_W21_BUSY == 1); // wait ReadBusy(); EPD_W21_CS_0; EPD_W21_DC_0; // command write SPI_Write(command); EPD_W21_DC_1; // command write SPI_Write(para); EPD_W21_CS_1; }