//This program powers the POV Wireless Display (By Fernando Zigunov, 2017). //Variables //Timer variables char Prev_IR_State=0; char Pixel_Column_Time=111; //183 char Pixel_Column_Count=0; //Timer control const char Desired_Pixel_Column_Count=150; char Last_Pixel_Column_Count=150; int diff; float newTimeDelta; float Kp=0.25; int timeNow; //Make the image rotate char frameDelay = 0; char frameDelayCounter=0; //Constant arrays forming the images char ImgToShow=0; //--------------------WORLD-------------------- const char WORLDD[]={0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x38,0x3C,0x34,0x30,0x30,0x30,0x30,0x30,0x32,0x3A,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x37,0x37,0x3B,0x1F,0x1F,0x1F,0x0B,0x03,0x03,0x03,0x06,0x04,0x04,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x20,0x20,0x20,0x20,0x30,0x30,0x30,0x30,0x20,0x00,0x02,0x06,0x06,0x06,0x2F,0x37,0x3F,0x2F,0x3F,0x0F,0x07,0x07,0x37,0x06,0x27,0x27,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3E,0x3E,0x3C,0x3C,0x38,0x38,0x38,0x30,0x30,0x30,0x30,0x30,0x38,0x38,0x38,0x38,0x30,0x30,0x00,0x00,0x00,0x00,0x20}; const char WORLDC[]={0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x10,0x00,0x00,0x00,0x00,0x30,0x30,0x30,0x3C,0x3C,0x3E,0x3E,0x3E,0x3F,0x3E,0x3F,0x3F,0x3F,0x3F,0x3F,0x3E,0x3E,0x3E,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3E,0x3E,0x3E,0x3E,0x3E,0x3E,0x3F,0x3F,0x1F,0x1F,0x3F,0x3F,0x3F,0x1F,0x1E,0x1F,0x17,0x17,0x37,0x27,0x27,0x27,0x07,0x07,0x0F,0x0F,0x0F,0x0F,0x0F,0x2F,0x2F,0x3F,0x3F,0x3F,0x07,0x03,0x03,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x20,0x30,0x38,0x3C,0x38,0x38,0x39,0x38,0x38,0x3C,0x3F,0x3F,0x3F,0x3E,0x3C,0x3C,0x3C,0x38,0x38,0x30,0x30,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}; const char WORLDB[]={0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x01,0x01,0x01,0x00,0x02,0x00,0x00,0x00,0x00,0x22,0x00,0x06,0x06,0x02,0x0E,0x3C,0x33,0x26,0x34,0x20,0x00,0x00,0x00,0x00,0x00,0x00,0x28,0x30,0x30,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x38,0x2C,0x3C,0x3C,0x1E,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3E,0x3C,0x38,0x38,0x38,0x38,0x38,0x38,0x38,0x38,0x38,0x30,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x01,0x01,0x01,0x03,0x07,0x07,0x07,0x07,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x03,0x00,0x10,0x10,0x20,0x20,0x20,0x20,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}; const char WORLDA[]={0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x07,0x03,0x07,0x0F,0x1F,0x0F,0x0F,0x1F,0x3F,0x1F,0x0F,0x0F,0x1F,0x07,0x07,0x07,0x02,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0C,0x0C,0x00,0x10,0x30,0x38,0x3E,0x3E,0x3F,0x3F,0x3F,0x3F,0x3F,0x3E,0x38,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x30,0x38,0x3C,0x3C,0x3E,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x30,0x30,0x20,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}; //--------------------ARROW-------------------- const char ARROWD[]={0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x01,0x01,0x03,0x03,0x03,0x07,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x01,0x03,0x03,0x03,0x07,0x03,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x01,0x01,0x03,0x03,0x03,0x07,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}; const char ARROWC[]={0x00,0x03,0x03,0x03,0x07,0x07,0x0F,0x0F,0x0F,0x1F,0x1F,0x1F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x1F,0x1F,0x1F,0x1F,0x1F,0x1F,0x1F,0x1F,0x1F,0x1F,0x1F,0x1F,0x1F,0x1F,0x1F,0x1F,0x1F,0x1F,0x1F,0x1F,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03,0x03,0x07,0x07,0x07,0x0F,0x0F,0x0F,0x1F,0x1F,0x1F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x1F,0x1F,0x1F,0x1F,0x1F,0x1F,0x1F,0x1F,0x1F,0x1F,0x1F,0x1F,0x1F,0x1F,0x1F,0x1F,0x1F,0x1F,0x1F,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03,0x03,0x03,0x07,0x07,0x0F,0x0F,0x0F,0x1F,0x1F,0x1F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x1F,0x1F,0x1F,0x1F,0x1F,0x1F,0x1F,0x1F,0x1F,0x1F,0x1F,0x1F,0x1F,0x1F,0x1F,0x1F,0x1F,0x1F,0x1F,0x1F,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}; const char ARROWB[]={0x00,0x00,0x00,0x00,0x20,0x20,0x20,0x30,0x30,0x30,0x38,0x38,0x3C,0x3C,0x3C,0x3E,0x3E,0x3E,0x3F,0x3F,0x3F,0x3F,0x38,0x38,0x38,0x38,0x38,0x38,0x38,0x38,0x38,0x38,0x38,0x38,0x38,0x38,0x38,0x38,0x38,0x38,0x38,0x38,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x20,0x20,0x30,0x30,0x30,0x38,0x38,0x3C,0x3C,0x3C,0x3E,0x3E,0x3E,0x3F,0x3F,0x3F,0x3F,0x3F,0x38,0x38,0x38,0x38,0x38,0x38,0x38,0x38,0x38,0x38,0x38,0x38,0x38,0x38,0x38,0x38,0x38,0x38,0x38,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x20,0x20,0x30,0x30,0x30,0x38,0x38,0x3C,0x3C,0x3C,0x3E,0x3E,0x3E,0x3F,0x3F,0x3F,0x3F,0x38,0x38,0x38,0x38,0x38,0x38,0x38,0x38,0x38,0x38,0x38,0x38,0x38,0x38,0x38,0x38,0x38,0x38,0x38,0x38,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}; const char ARROWA[]={0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}; void main() { TRISA=0b00000000; //Outputs 0-5 (first 6 bits) are used only. TRISB=0b00000000; TRISC=0b00000000; TRISD=0b00000000; TRISE=0b00000011; //PortE is input ADCON0=0b00000000;// No analog ADCON1=0b00001110;// No analog OPTION_REG=0b00000010; //Sets the timer prescaler INTCON=0b10100000; PORTA=0b00000000; PORTB=0b00000000; PORTC=0b00000000; PORTD=0b00000000; while (1) { //control loop if (!(Last_Pixel_Column_Count==Desired_Pixel_Column_Count)) { //Needs to update the timer diff = Desired_Pixel_Column_Count-Last_Pixel_Column_Count; timeNow=255-Pixel_Column_Time; newTimeDelta = (double) timeNow * ((double) diff/ (double) Desired_Pixel_Column_Count); newTimeDelta = newTimeDelta * Kp; //That's gonna be the delta applied if (abs(newTimeDelta)>1) { Pixel_Column_Time += newTimeDelta; if (Pixel_Column_Time > 250) { Pixel_Column_Time=250 ; } } } delay_ms(300); } } void interrupt(){ if (Prev_IR_State==0 && PORTE.RE0==1) { //Complete turn = 1 frame Last_Pixel_Column_Count=Pixel_Column_Count; //Stores for control purposes Pixel_Column_Count=0; //Resets the column count } if (ImgToShow==0) { PORTA=WORLDA[Pixel_Column_Count]; PORTB=WORLDB[Pixel_Column_Count]; PORTC=WORLDC[Pixel_Column_Count]; PORTD=WORLDD[Pixel_Column_Count]; } /*else if(ImgToShow==1) { PORTA=ARROWA[Pixel_Column_Count]; PORTB=ARROWB[Pixel_Column_Count]; PORTC=ARROWC[Pixel_Column_Count]; PORTD=ARROWD[Pixel_Column_Count]; } */ Prev_IR_State=PORTE.RE0; //Updates the state of the IR detector INTCON.T0IF=0; //Timer didn't overflow TMR0=Pixel_Column_Time; //Sets the timer Pixel_Column_Count++; //Updates the pixel column count }