/********************************************************** * GLCD TEST Program: [GLCD2_PIC24HJ64.C] * Graphic LCD(Monochrome): SG12864A * * Condition: * 8MHz External X'tal Oscillator, 10x PLL (8MHzx10= 80MHz) * Fcy=80MHz/2=40MHz, Tcy=25ns * * CPU: PIC24HJ64GP206 * Original Program: Mr.Gokan (CPU;PIC24HJ12GP202) * Mod. N.Ishii 2012.3.7 ************************************************************/ #include #include "glcd_lib_pic24hj64.h" #include #include "imagedata.h" /// Set Configretion Bit (Ext CLK = 8MHz) _FBS(BSS_NO_FLASH & BWRP_WRPROTECT_OFF ) _FGS(GSS_OFF & GCP_OFF & GWRP_OFF ) _FOSCSEL(FNOSC_PRIPLL & IESO_ON) //_FOSC(FCKSM_CSECME & IOL1WAY_OFF & POSCMD_XT ) _FOSC(FCKSM_CSECME & OSCIOFNC_OFF & POSCMD_XT ) _FWDT(FWDTEN_OFF & WINDIS_OFF) //_FPOR(FPWRT_PWR32 & ALTI2C_OFF) _FPOR(FPWRT_PWR32) /* constant for 2D graphics */ #define X0 3 #define Y0 3 #define PI 3.141592654f #define NODES 20 #define SIDE 6 /* D2Graph Hight Variable */ int i = 0; /* Prototyping */ void D2Graph(int Hight); /************************************************ * Function Main: GLCD TEST ************************************************/ int main(void) { /* Initialize Clock */ CLKDIVbits.PLLPRE = 0; // PLLPRE=1/2 to 4MHz PLLFBDbits.PLLDIV = 40; // PLLDIV=1/40 to 160MHz CLKDIVbits.PLLPOST = 0; // PLLPOST=1/2 to 80MHz then 40MIPS /* Initialize Port */ AD1PCFGL = 0xFFF8; // AN0-2 are Analog AD1PCFGH = 0xFFFF; // OTHER Digital // Initialize GLCD Control Signal Level LCD_E = 0; LCD_CS1 = 1; LCD_CS2 = 1; LCD_RW = 1; LCD_DI = 1; TRISB = 0x00FF; // LCD_DataPort(RB8-RB15) is output, TSW_IN(RB3-RB5) is input TRISC = 0xFFFF; // TRG_MODE_SW, READY_SW(RC13, RC14) is input ODCD = 0x003E; // GAIN-A,GAIN-B,AC/DC-A,ATT-A,ATT-B(RD1-TD5) is open dorein out TRISD = 0xF0C0; // LCD_ControlPort(RD0, RD8-RD11) is output TRISF = 0xFFFF; // HOLD/RUN_SW, AC/DC_SW(RF4, RF5) is input TRISG = 0xFFFE; // TRG_LED(RG0) is output, VSW-1,2,4,8(RG6-RG9) is input CNPU1 = 0x0FE3; // RB3-5, RC13,14, RG6-9 is pull up CNPU2 = 0x0006; // RF4,5 is pull up LATGbits.LATG0 = 1; // Green LED OFF lcd_Init(); // Initialize GLCD /// MAIN LOOP while(1){ int j, SW, index; /* Input Switch */ SW = (~PORTB & 0x0038) >> 3; // Read Rotary DipSW /// switch(SW){ case 0: // All Clear TEST Delay1m(1000); lcd_Clear(0); Delay1m(1000); lcd_Clear(0xFF); break; case 1: // Drawing Pixel TEST lcd_Clear(0); for(i=0; i<64; i++){ // Draw a slanted line lcd_Pixel(i,i,1); // CS1 Side lcd_Pixel(64+i, i,1); // CS2 Side } Delay1m(3000); lcd_Clear(0xFF); // All Black for(i=0; i<64; i++){ // Draw a slanted line (Pull draw out white) lcd_Pixel(i,i,0); // add 120305 lcd_Pixel(64+i, i,0); } Delay1m(3000); break; case 2: // Indicate Character TEST lcd_Clear(0); for(j=0; j<8; j++){ // Indicate All ASCII Characters (16 Characters/Line) for(i=0; i<16; i++){ index = j*16+i+0x20; // Repeat/96 Characters lcd_Char(j, i, index); // Indicate Character } } Delay1m(3000); lcd_Clear(0); for(j=0; j<8; j++){ // Indicate All ASCII Characters (18 Characters/Line) for(i=0; i<18; i++){ index = j*18+i+0x50; lcd_Char1(j, i, index); // Indicate Character } } Delay1m(3000); break; case 3: // Drawing Image TEST lcd_Image(Header2); Delay1m(3000); lcd_Scroll(50); /* lcd_Image(Header3); Delay1m(3000); lcd_Scroll(100); */ // Change Image lcd_Image(My_PIC_Scope); Delay1m(3000); lcd_Scroll(100); break; case 4: // Indicate Strings Character TEST lcd_Clear(0); Delay1m(1000); lcd_Str(0, 0, "Hello World!!"); lcd_Str(2, 0, "Graphic LCD Test!"); Delay1m(3000); break; case 5: // Drawing Sstraight Line TEST lcd_Clear(0); Delay1m(1000); i = 0; for(j=0; j<32; j+=2){ // Indicate BOX lcd_Line(j,j, 127-j, j); // Gradually small box lcd_Line(j,j, j, 63 -j); lcd_Line(127-j,63-j, 127-j,j); lcd_Line(128-j,63-j, j,63-j); Delay1m(500); } break; case 6: // Drawing curve TEST lcd_Clear(0); Delay1m(1000); if(i>10) i=0; D2Graph(10*i++); Delay1m(1000); break; case 7: // Debug Case: Only CS1 Side Test lcd_Clear(0); lcd_Write(1, 0xB8, 1); // Set CS1 Side, Page0 lcd_Write(1, 0x40, 1); // Colum reset lcd_Write(1, 0x0F, 0); // Set Data 4dot Black + 4dot White lcd_Write(1, 0xC0, 1); // reset start line Delay1m(1000); lcd_Write(1, 0x40, 1); // Colum reset lcd_Write(1, 0xF0, 0); // Set Data 4dot White + 4dot Black lcd_Write(1, 0xC0, 1); // reset start line Delay1m(1000); break; default: break; } } } /********************************************* * Drawing two dimensions graph * z(x,y) = 1/(1+SQRT(x2+y2))*COS(SQRT(x2+y2)) * (-3*PI< x,y < 3*PI) ***********************************************/ void D2Graph(int Hight) { int i, j, px, py,x, y, z; float zf, xf, yf, sf; struct{ int x; int y; } edge[NODES], prev; lcd_Line(X0, 3, X0, 63); // z axis lcd_Line(X0-3, Y0, 123, Y0); // x axis lcd_Line(X0-2, Y0-2, X0+60, Y0+60); // y axis for(j=0; j