Stap 2: Code
#include ”core.h”//pcDuino contains Core header file
#include ”ls.h”//Containing images to be displayed #define STATUS_PIN 9//Define electronic paper 's state pin #define CS_PIN 10//Define electronic paper 's chip select pin #define MISO_PIN 11//Master input and slave output pin #define MOSI_PIN 12//Master output and slave input pin #define SCK_PIN 13//Defined clock pin #define FRAME_END_LEN 11//Define the refresh frequency (I used 11, it's free to modify) unsigned char SoftSpiTransfer(unsigned char data)//Simulating SPI timing { unsigned char cnt; unsigned char rst; rst = 0; for(cnt = 0;cnt < 8 ;cnt ++) { rst <<= 1; if(data & 0×80) digitalWrite(MOSI_PIN,HIGH); else digitalWrite(MOSI_PIN,LOW); digitalWrite(SCK_PIN,HIGH); digitalWrite(SCK_PIN,LOW); rst |= digitalRead(MISO_PIN); data <<= 1; } return rst; } void ClearScring(void)//Clear function { bool DeviceStatus;//Defined a quantity of state DeviceStatus = digitalRead(STATUS_PIN); digitalWrite(CS_PIN,LOW); SoftSpiTransfer(3); while(digitalRead(STATUS_PIN) == DeviceStatus) { asm(“nop”);//Embedded a delay assembler instruction, the same below } digitalWrite(CS_PIN,HIGH); } void SetImageWide(unsigned int wide)//Image width setting function { bool DeviceStatus; DeviceStatus = digitalRead(STATUS_PIN); digitalWrite(CS_PIN,LOW); SoftSpiTransfer(1); while(digitalRead(STATUS_PIN) == DeviceStatus) { asm(“nop”); } DeviceStatus = !DeviceStatus; SoftSpiTransfer(wide >> 8); while(digitalRead(STATUS_PIN) == DeviceStatus) { asm(“nop”); } DeviceStatus = !DeviceStatus; SoftSpiTransfer(wide & 0xff); while(digitalRead(STATUS_PIN) == DeviceStatus) { asm(“nop”); } digitalWrite(CS_PIN,HIGH); } void SetImageHigh(unsigned int high)//Image Height setting function { bool DeviceStatus; DeviceStatus = digitalRead(STATUS_PIN); digitalWrite(CS_PIN,LOW); SoftSpiTransfer(2); while(digitalRead(STATUS_PIN) == DeviceStatus) { asm(“nop”); } DeviceStatus = !DeviceStatus; SoftSpiTransfer(high >> 8); while(digitalRead(STATUS_PIN) == DeviceStatus) { asm(“nop”); } DeviceStatus = !DeviceStatus; SoftSpiTransfer(high & 0xff); while(digitalRead(STATUS_PIN) == DeviceStatus) { asm(“nop”); } digitalWrite(CS_PIN,HIGH); } void SendImage(const unsigned char * pic)//Function of displays pictures { bool DeviceStatus; unsigned char data; unsigned char cnt0; unsigned int cnt1; unsigned long time; DeviceStatus = digitalRead(STATUS_PIN); digitalWrite(CS_PIN,LOW); SoftSpiTransfer(4); while(digitalRead(STATUS_PIN) == DeviceStatus) { asm(“nop”); } DeviceStatus = !DeviceStatus; for(cnt0 = 0;cnt0 < FRAME_END_LEN; cnt0 ++) { Serial.println(“New Line”); for(cnt1 = 0; cnt1 < 120000; cnt1 ++) { data = gImage[cnt1]; SoftSpiTransfer(data); time = 0; while(digitalRead(STATUS_PIN) == DeviceStatus) { asm(“nop”); time ++; if(time > 1000000) { Serial.println(“Error”);//When timeout serial prompt an error digitalWrite(CS_PIN,HIGH); return; } } DeviceStatus = !DeviceStatus; } } digitalWrite(CS_PIN,HIGH); } void setup() { Serial.begin(9600); pinMode(STATUS_PIN, INPUT); pinMode(CS_PIN, OUTPUT); pinMode(MOSI_PIN, OUTPUT); pinMode(MISO_PIN, INPUT); pinMode(SCK_PIN, OUTPUT); digitalWrite(CS_PIN,HIGH); digitalWrite(STATUS_PIN,HIGH); digitalWrite(SCK_PIN,LOW); } void loop() { char cmd; if(Serial.available())//If serial port received a data { cmd = Serial.parseInt(); switch(cmd) { case 1: SetImageWide(600); Serial.println(“Set Image Wide Complete !”); break; case 2: SetImageHigh(800); Serial.println(“Set Image High Complete !”); break; case 3: Serial.println(“Start Clear Scring !”); ClearScring(); Serial.println(“Clear Scring Complete !”); break; case 4: Serial.println(“Start Send Image Data!”); SendImage(gImage); Serial.println(“Send Image Data Complete !”); break; default: Serial.println(“Unknow instruction !”); break; } } }