//============================================================================= // MAIN //============================================================================= void main() { //------------------------------------------------------- // setup PIC 18F8527 for SmartGLCD pins CMCON = 0x07; // turn off comparators (make all pins digital) ADCON0 = 0b00000001; // ADC module on ADCON1 = 0b00001101; // AN0,AN1 are adc inputs, 0v-5v range ADCON2 = 0b00110010; // ADC result left justified (0-255 range) LATA = 0b00000000; TRISA = 0b00000011; // RA0,RA1 analog inputs (TP) LATC = 0b00000110; // LEDs off at start TRISC = 0b00000000; // C1, C2 backlight LED LATG = 0b00000001; // LED off at start TRISG = 0b00000000; // G0 backlight LED LATJ = 0b01000000; // RJ6=FS (1=font6 0=font8), RJ5=MD TRISJ = 0b00000000; // GLCD control port BacklightRed = 1; // control the GLCD backlight leds; 0=on, 1=off BacklightGreen = 0; // green ON BacklightBlue = 1; T1CON = 0b10110001; // TMR1 on 16bit, 1:8 prescaler, used for time testing //------------------------------------------------------- // Initialize T6963C GLCD T6963C_init(240, 128, 6); // init for MikroC PRO version //T6963C_init(240, 128, 6, &PORTH, &PORTJ, 2, 1, 0, 4); // init for MikroC version T6963C_graphics(1); // graphics mode = on T6963C_text(1); // text mode = on (now both are on) T6963C_cursor(0); // cursor = off Delay_mS(300); //------------------------------------------------------- // draw stuff on GLCD. //------------------------------------------------------- // do a time test of the MikroE horiz line, this draws a line // across the screen and times it in exact uS. T6963C_Write_Text("Line drawn with MikroE Line() function", 0, 0, T6963C_ROM_MODE_OR); TMR1H=0; TMR1L=0; // clear TMR1 here T6963C_line(0,16,239,16,T6963C_WHITE); // Draw a MikroE line etime = TMR1L; // read TMR1 here etime += (TMR1H << 8); WordToStr(etime,txt); // get the time as text T6963C_Write_Text("Time: uS", 0, 4, T6963C_ROM_MODE_OR); // display time in uS T6963C_Write_Text(txt, 6, 4, T6963C_ROM_MODE_OR); // display time in uS //------------------------------------------------------- // now do a time test using my line bytes system, this is a "best case" // where all it does is draw bytes (each byte is 6 black pixels) // across the screen to make a horizontal line. This is horrible code but // it is about as fast as this GLCD can ever get, which is the test. T6963C_Write_Text("Line drawn with my functions", 0, 10, T6963C_ROM_MODE_OR); TMR1H=0; TMR1L=0; // clear TMR1 here // set first graphic byte to write to (each pixel row across is 40 bytes) // y = 40*8*textline = 40*8*12 = 0x0F00 // this should be put in a function later! RomanSG_Set_Address(address) RSG_byte = 0x00; // low address in graphic ram RomanSG_Send_Data(); RSG_byte = 0x0F; // hi address in graphic ram RomanSG_Send_Data(); RSG_byte = 0x24; // command to set ram address pointer RomanSG_Send_Command(); // now loop and draw 40 bytes into graphic ram for(i=0; i<40; i++) { RSG_byte = 0x3F; // 0b00111111 (6 black pixels to write to graphic ram) RomanSG_Send_Data(); RSG_byte = 0xC0; // command to write byte to graphic ram and increment ram pointer RomanSG_Send_Command(); } etime = TMR1L; // read TMR1 here etime += (TMR1H << 8); WordToStr(etime,txt); // get the time as text T6963C_Write_Text("Time: uS", 0, 14, T6963C_ROM_MODE_OR); // display time in uS T6963C_Write_Text(txt, 6, 14, T6963C_ROM_MODE_OR); //------------------------------------------------------- // delay between test pages Delay_mS(3000); // clear the screen T6963C_grFill(0); // erase graphics T6963C_txtFill(0); // erase text //------------------------------------------------------- // do a time test of the MikroE vertical line T6963C_Write_Text("Vert line with MikroE Line() function", 0, 0, T6963C_ROM_MODE_OR); TMR1H=0; TMR1L=0; // clear TMR1 here T6963C_line(29,0,29,127,T6963C_WHITE); // Draw a MikroE line etime = TMR1L; // read TMR1 here etime += (TMR1H << 8); WordToStr(etime,txt); // get the time as text T6963C_Write_Text("Time: uS", 0, 4, T6963C_ROM_MODE_OR); // display time in uS T6963C_Write_Text(txt, 6, 4, T6963C_ROM_MODE_OR); // display time in uS //------------------------------------------------------- // and test manual writing of a vertical line by drawing to graphcis ram... T6963C_Write_Text("Vert line with my functions", 0, 10, T6963C_ROM_MODE_OR); TMR1H=0; TMR1L=0; // clear TMR1 here add_lo = 31; add_hi = 0; // now loop and draw 120 vertical pixels, top down for(i=0; i<128; i++) { // set graphics ram address for this byte RSG_byte = add_lo; // low address in graphic ram RomanSG_Send_Data(); RSG_byte = add_hi; // hi address in graphic ram RomanSG_Send_Data(); RSG_byte = 0x24; // command to set ram address pointer RomanSG_Send_Command(); // and make a single black pixel bit in that byte (bit 3 011) RSG_byte = 0b11111011; // command to set a pixel; 1111 colour ppp RomanSG_Send_Command(); /* T6963C_writeData(add_lo); // MikroC command functions were twice as slow T6963C_writeData(add_hi); T6963C_writeCommand(0x24); T6963C_writeCommand(0b11111011); */ // manually calc the address of the next byte below, is +=40 bytes. // manually handle the 16bit address for speed (messy!) if(add_lo >= (256-40)) add_hi ++; add_lo += 40; // is a 16bit +=40 } etime = TMR1L; // read TMR1 here etime += (TMR1H << 8); WordToStr(etime,txt); // get the time as text T6963C_Write_Text("Time: uS", 0, 14, T6963C_ROM_MODE_OR); // display time in uS T6963C_Write_Text(txt, 6, 14, T6963C_ROM_MODE_OR); //------------------------------------------------------- while(1) { // just loop and do nothing } }
void main() { ANCON0 = 0; ANCON1 = 0; ANCON2 = 0; ANCON0.B0 = 1; // Configure RA0 pin as analog ANCON0.B1 = 1; // Configure RA1 pin as analog TRISA.B0 = 1; // Set RA0 pin as input TRISA.B1 = 1; // Set RA1 pin as input ADC_Init(); T6963C_ctrlce_Direction = 0; T6963C_ctrlce = 0; // Enable T6963C T6963C_ctrlmd_Direction = 0; T6963C_ctrlmd = 0; // Column number select T6963C_ctrlfs_Direction = 0; T6963C_ctrlfs = 0; // Wide Font BacklightRed_Direction = 0; // Set backlight signals as outputs BacklightGreen_Direction = 0; BacklightBlue_Direction = 0; BacklightRed = 0; // Turn on Red component of back light BacklightGreen = 0; // Turn on Green component of back light BacklightBlue = 0; // Turn on Blue component of back light // Initialize T6963C T6963C_init(240, 128, 8); T6963C_graphics(1); T6963C_text(1); T6963C_cursor(0); TP_Init(240, 128, 0, 1); // Initialize touch panel TP_Set_ADC_Threshold(500); // Set touch panel ADC threshold T6963C_graphics(1); T6963C_text(1); T6963C_panelFill(0); T6963C_write_text("CALIBRATION", 8, 6, 1); Delay_ms(2000); T6963C_panelFill(0); Calibrate(); T6963C_panelFill(0); T6963C_write_text("WRITE ON SCREEN", 7, 6, 1) ; Delay_ms(1000); T6963C_panelFill(0); //Draw menus: T6963C_box(0,0,42,7,T6963C_WHITE); T6963C_write_text(clear_msg,0,0,0); T6963C_box(200,0,240,7,T6963C_WHITE); T6963C_write_text(erase_msg,25,0,0); T6963C_box(57,0,65,7,T6963C_WHITE); T6963C_write_char('R',7,0,0); T6963C_box(73,0,81,7,T6963C_WHITE); T6963C_write_char('G',9,0,0); T6963C_box(89,0,97,7,T6963C_WHITE); T6963C_write_char('B',11,0,0); T6963C_box(105,0,145,7,T6963C_WHITE); T6963C_write_text("Light",13,0,0); write_erase = 1; while (1) { if (TP_Press_Detect()) { // get coordinates if (TP_Get_Coordinates(&x_coord240, &y_coord128) == 0){ // If clear is pressed if ((x_coord240 < 32) && (y_coord128 < 8)) { T6963C_panelFill(0); // Draw menus: T6963C_box(0,0,42,7,T6963C_WHITE); T6963C_write_text(clear_msg,0,0,0); T6963C_box(200,0,240,7,T6963C_WHITE); if (write_erase) T6963C_write_text(erase_msg,25,0,0); else T6963C_write_text(write_msg,25,0,0); T6963C_box(57,0,65,7,T6963C_WHITE); T6963C_write_char('R',7,0,0); T6963C_box(73,0,81,7,T6963C_WHITE); T6963C_write_char('G',9,0,0); T6963C_box(89,0,97,7,T6963C_WHITE); T6963C_write_char('B',11,0,0); T6963C_box(105,0,145,7,T6963C_WHITE); T6963C_write_text("Light",13,0,0); } // If write/erase is pressed: if ((x_coord240 > 201) && (y_coord128 < 8)) { if (write_erase) { write_erase = 0; T6963C_write_text(write_msg,25,0,0); Delay_ms(200); } else { write_erase = 1; T6963C_write_text(erase_msg,25,0,0); Delay_ms(200); } } // If R button is pressed: if ((x_coord240 >= 57) && (x_coord240 <= 65) && (y_coord128 <= 7)) { PORTC.F2 = !PORTC.F2; // Red Delay_ms(100); } // If G button is pressed: if ((x_coord240 >= 73) && (x_coord240 <= 81) && (y_coord128 <= 7)) { PORTC.F1 = !PORTC.F1; // Green Delay_ms(100); } // If B button is pressed: if ((x_coord240 >= 89) && (x_coord240 <= 97) && (y_coord128 <= 7)) { PORTG.F0 = !PORTG.F0; // Blue Delay_ms(100); } // If backlight button is pressed: if ((x_coord240 >= 105) && (x_coord240 <= 146) && (y_coord128 <= 7)) { PORTC.F2 = !PORTC.F2; // Red PORTC.F1 = !PORTC.F1; // Green PORTG.F0 = !PORTG.F0; // Blue Delay_ms(100); } // Draw on the screen if (y_coord128 > 8) { if (write_erase) T6963C_dot(x_coord240, y_coord128, T6963C_WHITE); else T6963C_dot(x_coord240, y_coord128, T6963C_BLACK); } } } } }