///////////////////////////////////////////////////////////////////////////// //// i2c_graphic_primitive.C // PIC program to allow Slug to send primitive graphic // display commands to a 64 x 128 graphic display // // the PIC sends this string of data for pic_buf[] // pic_buf[0] contains command codes as below:- // x=0, y=0 is the top left corner // // 1 line(x1 y1 x2 y2 color(0/1)) // 2 rectangle (x1 y1 x2 y2 fill(0/1) color(0/1) // 3 bar(x1 y1 x2 y2 width color(0/1) - - - fails, why? // 4 circle(x y radius fill(0/1) color(0/1)) // 5 text to screen (x y ASCIIasDecimal size color(0/1)) -e.g. send 65 for A // 6 pixel (x y color(0/1)) // 7 wipe all screen to black or white (color(0/1)) ////////////////////////////////////////////////////////////////////////////// #include <16F877.h> #fuses HS,NOWDT,NOPROTECT,NOLVP #use delay(clock=20000000) #use i2c(SLAVE, SDA=PIN_C4, SCL=PIN_C3, address=0xA2, FORCE_HW) //A0 is 80 in Linux decimal, A2 is 81 (as seen in i2cdetect 0) #include #include #include BYTE state; // receive string of up to 127 bytes on the i2c line int8 pic_buf[10]; //the i2c data from the Slug go in here int i; //for counts char screen_text[1]; //real character then null character //===========================================================i2c interrupt routine #INT_SSP void ssp_interupt () { state = i2c_isr_state(); //i2c event caused by i2c master interrups the PIC //"state" sets if the master is requesting or sending data if(state < 0x80) //Master is sending data { if(state == 0) { } } for(i=0; i<=7; ++i) { if(state == (i+1)) // state increments from 1 as each data byte comes in { pic_buf[i] = i2c_read(); } } if(state == 0x80) //Master is requesting data from the PIC { i2c_write (10);//dummy response - i2cdetect fails without this -why !?!? } } //============================================================i2c end of interrupt //*****************************************************************************main void main() { char string_1[] = "Welcome!"; char string_2[] = "Waiting for i2c data"; enable_interrupts(INT_SSP); enable_interrupts(GLOBAL); glcd_init(ON); // Must initialize the LCD glcd_fillScreen(0); //screen all black glcd_text57(20, 16, string_1, 2, 1); glcd_text57(4, 45, string_2, 1, 1); delay_ms(20); for(;;) //repeat for ever { // ------------------------------------------------------------------------line if ((pic_buf[0]==1)) { glcd_line(pic_buf[1], pic_buf[2], pic_buf[3], pic_buf[4], pic_buf[5]); } // ----------------------------------------------------------------------rectangle if ((pic_buf[0]==2)) { glcd_rect(pic_buf[1], pic_buf[2], pic_buf[3], pic_buf[4], pic_buf[5], pic_buf[6]); } // -------------------------------------------------------------------bar (fails!!) if ((pic_buf[0]==3)) { glcd_bar(pic_buf[1], pic_buf[2], pic_buf[3], pic_buf[4], pic_buf[5], pic_buf[6]); } // --------------------------------------------------------------------------circle if ((pic_buf[0]==4)) { glcd_circle(pic_buf[1], pic_buf[2], pic_buf[3], pic_buf[4], pic_buf[5]); } // ------------------------------------------------------------------ text to screen if ((pic_buf[0]==5)) { sprintf(screen_text,"%c",pic_buf[3]); glcd_text57(pic_buf[1], pic_buf[2], screen_text, pic_buf[4], pic_buf[5]); } // ------------------------------------------------------------------------ pixel if ((pic_buf[0]==6)) { glcd_pixel(pic_buf[1], pic_buf[2], pic_buf[3]); } // --------------------------------------------------------------------wipe screen if ((pic_buf[0]==7)) { glcd_fillScreen(pic_buf[1]); } // else // { // pic_buf[0]=10 ; // } // flash the top left pixel to show program alive glcd_rect(0, 0, 0, 0, YES, ON); delay_ms(300); glcd_rect(0, 0, 0, 0, YES, OFF); delay_ms(300); } }