///////////////////////////////////////////////////////////////////////////// //// i2c_graphicLCD_2.C derived from EX_GLCD.C // PIC program to display data point in an area of any width // data given to master program PIC_i2c_send_data_to_plot_ram comes here // first 8 bytes stored in pic_buf[60] are commands // pic_buf[0] = PIC display starting point on x axis // pic_buf[1] = number of data points sent to be displayed // pic_buf[2] = 1 - wipe this data area before plot // pic_buf[3] = 1 - we WILL plot some data points (0 - just switch lines later) // pic_buf[4] = 1 - wipe whole screen // pic_buf[5] = 0 - free // pic_buf[6] = 0 - free // pic_buf[7] = 0 - free // // then this program receives data from a file in the ramdisk folder // from a single data point to a string of 50 ////////////////////////////////////////////////////////////////////////////// #include <16F877.h> #device ADC=16 #fuses HS,NOWDT,NOPROTECT,NOLVP #use delay(clock=20000000) //#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7) - for later #use i2c(SLAVE, SDA=PIN_C4, SCL=PIN_C3, address=0xA2, FORCE_HW) //0xA1 in address is the same as A0 in Linux decimal (it is 80)!!! - step in 2s //I2C by Hardware,i2c address (0xA2 is dec 81)is the first byte from the master #include #include #include //#define GP3 PIN_B3 -for later //#define GP4 PIN_B6 //#define GP5 PIN_B7 BYTE incoming, state; // receive string of up to 127 bytes on the i2c line int8 pic_buf[60]; //can't be much bigger int8 i;//for a count int8 k;//for a count //====================================================================i2c 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<=60; ++i) { if(state == (i+1)) // state increments from 1 as each data byte comes in { incoming = i2c_read(); pic_buf[i] = incoming; } } if(state == 0x80) //Master is requesting data from the PIC { i2c_write (10);//dummy response - i2cdetect fails without this -why !?!? } } //============================================================i2c end of interrupt void displayVoltage(int plot) //old code adapted to show commands { char voltage[9]; // sprintf(voltage, "%f", (float)plot); // Converts plot to text sprintf(voltage, "%d", (int)plot); // Converts plot to text voltage[4] = '\0'; // Limit shown digits to 3 glcd_rect(106, 0, 131, 7, YES, OFF); // Clear the old voltage glcd_text57(106, 0, voltage, 1, ON); // Write the new voltage } //--------------------------------------------------------------------------main void main() { int8 plot = 0; enable_interrupts(INT_SSP); enable_interrupts(GLOBAL); k = 0;// scan the command numbers on the screen glcd_init(ON); // Must initialize the LCD for(;;) { if (pic_buf[4]==1)//clear screen { glcd_fillScreen(OFF); } pic_buf[4]=0;// only clear screen once per command session plot = pic_buf[k] ; displayVoltage(plot); // Display the reading if (pic_buf[2]==1)//wipe local { glcd_rect((pic_buf[0]), 63, (pic_buf[0]+ pic_buf[1] - 1), 0, YES, OFF) ; } pic_buf[2]=0;// only wipe once per command session if (pic_buf[3]==1)//plot the pic_buf[1] points { for (i=0; i