/********************************************************************* * Flowcode Graphical LCD Component Code * * File: GFxLCD_Code.c * * (c) 2007 Matrix Multimedia Ltd. * http://www.matrixmultimedia.com * * Software License Agreement * * The software supplied herewith by Matrix Multimedia Ltd (the * “Company”) for its Flowcode graphical programming language is * intended and supplied to you, the Company’s customer, for use * solely and exclusively on the Company's products. The software * is owned by the Company, and is protected under applicable * copyright laws. All rights are reserved. Any use in violation * of the foregoing restrictions may subject the user to criminal * sanctions under applicable laws, as well as to civil liability * for the breach of the terms and conditions of this licence. * * THIS SOFTWARE IS PROVIDED IN AN “AS IS” CONDITION. NO WARRANTIES, * WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING, BUT NOT LIMITED * TO, IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE APPLY TO THIS SOFTWARE. THE COMPANY SHALL NOT, * IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL OR * CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER. * * Changelog: * * date | by | description * -------+----+----------------------------------------------------- * 240407 | ST | Created * 220108 | BR | Edited for GfxLCD * | | * | | * | | * * * ********************************************************************/ /********************************************************************* Return & Parameter types: void char short char* Pin directions: 0 = OUTPUT 2 = INPUT 3 = BIDIRECTIONAL Macro substitutions: %a = ?? %b = ?? %c = ?? %d = ?? %e = ?? %f = ?? %g = ?? %h = ?? %i = ?? %j = ?? ********************************************************************** [Settings] CLSID={4B174520-75AB-4B14-A0F7-2AA6C203F1DC} IsAnalogue=0 MultipleAllowed=0 Description=Graphical LCD Flowcode Component ********************************************************************** [Port] DesiredPort=0 PortMandatory=0 SamePortAsID=0 [Pins] Count=0 [PinPort] # PORTA = 0 # PORTB = 1 # PORTC = 2 # PORTD = 3 # PORTE = 4 [PinDesiredBit] [PinDirection] # DIR_INPUT = 2 # DIR_OUTPUT = 0 # DIR_BIDIRECTIONAL = 3 [PinMustUsePort] # boolean [SamePortAsPinX] # -1 = any pin # otherwise, the pin number [PinMustUsePin] # boolean [PinValue] # boolean (0 = off, 1 = on) ********************************************************************** [MacroNames] Count=7 1=GetDefines 2=Lcd_Init 3=Lcd_DrawBox 4=Lcd_Clear 5=Lcd_Print 6=Lcd_Plot 7=Lcd_DrawLine [MacroReturns] 1=void 2=void 3=void 4=void 5=void 6=void 7=void [MacroIsPrivate] 1=1 2=0 3=0 4=0 5=0 6=0 7=0 [MacroParameters_GetDefines] Count=0 [MacroParamTypes_GetDefines] [MacroParameters_Lcd_Init] Count=0 [MacroParamTypes_Lcd_Init] [MacroParameters_Lcd_DrawBox] Count=5 1=X1 2=Y1 3=X2 4=Y2 5=Colour [MacroParamTypes_Lcd_DrawBox] 1=char 2=char 3=char 4=char 5=char [MacroParameters_Lcd_Clear] Count=0 [MacroParamTypes_Lcd_Clear] [MacroParameters_Lcd_Print] Count=6 1=String 2=LCD_X 3=LCD_Y 4=Font 5=Fore_Colour 6=Back_Colour [MacroParamTypes_Lcd_Print] 1=char* 2=char 3=char 4=char 5=char 6=char [MacroParameters_Lcd_Plot] Count=3 1=X1 2=Y1 3=Colour [MacroParamTypes_Lcd_Plot] 1=char 2=char 3=char [MacroParameters_Lcd_DrawLine] Count=5 1=X1 2=Y1 3=X2 4=Y2 5=Colour [MacroParamTypes_Lcd_DrawLine] 1=char 2=char 3=char 4=char 5=char ********************************************************************/ /******************************************************************** * ADDITIONAL CODE ********************************************************************/ /*InitialisationCode_Start*/ /*InitialisationCode_End*/ /*InterruptCode_Start*/ /*InterruptCode_End*/ /******************************************************************** * FUNCTIONS ********************************************************************/ void GetDefines() { /*Macro_GetDefines_Start*/ } //Dummy end of function to allow defines to be added correctly //Common Defines #define MX_GFXLCD_PORT %a //portc I/O port #define MX_GFXLCD_TRIS %b //trisc I/O direction register #define MX_GFXLCD_RS %c //3 Reset #define MX_GFXLCD_CS %d //2 Chip Select #define MX_GFXLCD_SCLK %e //1 Serial Clock #define MX_GFXLCD_SDATA %f //0 Serial Data #define MX_CUSTOM_7 %g #define MX_CUSTOM_8 %h #define MX_CUSTOM_9 %i #define MX_CUSTOM_10 %j //These are defines for the Colour constants. //You can edit the values here or add new colouMX_GFXLCD_RS to the list. #define BLUE 0x03 #define YELLOW 0xFC #define RED 0xE0 #define GREEN 0x1C #define BLACK 0x00 #define WHITE 0xFF #define BRIGHTGREEN 0x3D #define DARKGREEN 0x14 #define DARKRED 0xA0 #define DARKBLUE 0x02 #define BRIGHTBLUE 0x1F #define ORANGE 0xF8 #define MX_GFXLCD_CMD 0 //A "0" tells the display: now a Command is following #define MX_GFXLCD_PARAM 1 //A "1" tells the display: now a Parameter is following //Internal Gfx LCD Functions void Lcd_sendbyte (char Command, char Lcdout); void Window (char X1, char Y1, char X2, char Y2); //Global Variables //Colour Data char DataInit[20] = {0x00,0x02,0x04,0x06,0x09,0x0B,0x0D,0x0F,0x00,0x02,0x04,0x06,0x09,0x0B,0x0D,0x0F,0x00,0x04,0x0B,0x0F}; //ASCII Pixel data rom char* ASCII1 = {0x00 , 0x00 , 0x00 , 0x00 , 0x00, // space // 32 - 43 0x00 , 0x06 , 0x5F , 0x06 , 0x00, // ! 0x07 , 0x03 , 0x00 , 0x07 , 0x03, // '' 0x24 , 0x7E , 0x24 , 0x7E , 0x24, // # 0x24 , 0x2B , 0x6A , 0x12 , 0x00, // $ 0x63 , 0x13 , 0x08 , 0x64 , 0x63, // % 0x36 , 0x49 , 0x56 , 0x20 , 0x50, // & 0x00 , 0x07 , 0x03 , 0x00 , 0x00, // ' 0x00 , 0x3E , 0x41 , 0x00 , 0x00, // ( 0x00 , 0x41 , 0x3E , 0x00 , 0x00, // ) 0x08 , 0x3E , 0x1C , 0x3E , 0x08, // * 0x08 , 0x08 , 0x3E , 0x08 , 0x08}; // + rom char* ASCII2 = {0x00 , 0xE0 , 0x60 , 0x00 , 0x00, // , // 44 - 55 0x08 , 0x08 , 0x08 , 0x08 , 0x08, // - 0x00 , 0x60 , 0x60 , 0x00 , 0x00, // . 0x20 , 0x10 , 0x08 , 0x04 , 0x02, // / 0x3E , 0x51 , 0x49 , 0x45 , 0x3E, // 0 0x00 , 0x42 , 0x7F , 0x40 , 0x00, // 1 0x62 , 0x51 , 0x49 , 0x49 , 0x46, // 2 0x22 , 0x49 , 0x49 , 0x49 , 0x36, // 3 0x18 , 0x14 , 0x12 , 0x7F , 0x10, // 4 0x2F , 0x49 , 0x49 , 0x49 , 0x31, // 5 0x3C , 0x4A , 0x49 , 0x49 , 0x30, // 6 0x01 , 0x71 , 0x09 , 0x05 , 0x03}; // 7 rom char* ASCII3 = {0x36 , 0x49 , 0x49 , 0x49 , 0x36, // 8 // 56 - 67 0x06 , 0x49 , 0x49 , 0x29 , 0x1E, // 9 0x00 , 0x6C , 0x6C , 0x00 , 0x00, // : 0x00 , 0xEC , 0x6C , 0x00 , 0x00, // ; 0x08 , 0x14 , 0x22 , 0x41 , 0x00, // < 0x24 , 0x24 , 0x24 , 0x24 , 0x24, // = 0x00 , 0x41 , 0x22 , 0x14 , 0x08, // > 0x02 , 0x01 , 0x59 , 0x09 , 0x06, // ? 0x3E , 0x41 , 0x5D , 0x55 , 0x1E, // @ 0x7E , 0x09 , 0x09 , 0x09 , 0x7E, // A 0x7F , 0x49 , 0x49 , 0x49 , 0x36, // B 0x3E , 0x41 , 0x41 , 0x41 , 0x22}; // C rom char* ASCII4 = {0x7F , 0x41 , 0x41 , 0x41 , 0x3E, // D // 68 - 79 0x7F , 0x49 , 0x49 , 0x49 , 0x41, // E 0x7F , 0x09 , 0x09 , 0x09 , 0x01, // F 0x3E , 0x41 , 0x49 , 0x49 , 0x7A, // G 0x7F , 0x08 , 0x08 , 0x08 , 0x7F, // H 0x00 , 0x41 , 0x7F , 0x41 , 0x00, // I 0x30 , 0x40 , 0x40 , 0x40 , 0x3F, // J 0x7F , 0x08 , 0x14 , 0x22 , 0x41, // K 0x7F , 0x40 , 0x40 , 0x40 , 0x40, // L 0x7F , 0x02 , 0x04 , 0x02 , 0x7F, // M 0x7F , 0x02 , 0x04 , 0x08 , 0x7F, // N 0x3E , 0x41 , 0x41 , 0x41 , 0x3E}; // O rom char* ASCII5 = {0x7F , 0x09 , 0x09 , 0x09 , 0x06, // P // 80 - 91 0x3E , 0x41 , 0x51 , 0x21 , 0x5E, // Q 0x7F , 0x09 , 0x09 , 0x19 , 0x66, // R 0x26 , 0x49 , 0x49 , 0x49 , 0x32, // S 0x01 , 0x01 , 0x7F , 0x01 , 0x01, // T 0x3F , 0x40 , 0x40 , 0x40 , 0x3F, // U 0x1F , 0x20 , 0x40 , 0x20 , 0x1F, // V 0x3F , 0x40 , 0x3C , 0x40 , 0x3F, // W 0x63 , 0x14 , 0x08 , 0x14 , 0x63, // X 0x07 , 0x08 , 0x70 , 0x08 , 0x07, // Y 0x71 , 0x49 , 0x45 , 0x43 , 0x00, // Z 0x00 , 0x7F , 0x41 , 0x41 , 0x00}; // [ rom char* ASCII6 = {0x02 , 0x04 , 0x08 , 0x10 , 0x20, // \ // 92 - 103 0x00 , 0x41 , 0x41 , 0x7F , 0x00, // ] 0x04 , 0x02 , 0x01 , 0x02 , 0x04, // ^ 0x80 , 0x80 , 0x80 , 0x80 , 0x80, // _ 0x00 , 0x03 , 0x07 , 0x00 , 0x00, // ` 0x20 , 0x54 , 0x54 , 0x54 , 0x78, // a 0x7F , 0x44 , 0x44 , 0x44 , 0x38, // b 0x38 , 0x44 , 0x44 , 0x44 , 0x28, // c 0x38 , 0x44 , 0x44 , 0x44 , 0x7F, // d 0x38 , 0x54 , 0x54 , 0x54 , 0x18, // e 0x08 , 0x7E , 0x09 , 0x09 , 0x00, // f 0x18 , 0xA4 , 0xA4 , 0xA4 , 0x7C}; // g rom char* ASCII7 = {0x7F , 0x04 , 0x04 , 0x78 , 0x00, // h // 104 - 115 0x00 , 0x00 , 0x7D , 0x00 , 0x00, // i 0x40 , 0x80 , 0x84 , 0x7D , 0x00, // j 0x7F , 0x10 , 0x28 , 0x44 , 0x00, // k 0x00 , 0x00 , 0x7F , 0x40 , 0x00, // l 0x7C , 0x04 , 0x18 , 0x04 , 0x78, // m 0x7C , 0x04 , 0x04 , 0x78 , 0x00, // n 0x38 , 0x44 , 0x44 , 0x44 , 0x38, // o 0xFC , 0x44 , 0x44 , 0x44 , 0x38, // p 0x38 , 0x44 , 0x44 , 0x44 , 0xFC, // q 0x44 , 0x78 , 0x44 , 0x04 , 0x08, // r 0x08 , 0x54 , 0x54 , 0x54 , 0x20}; // s rom char* ASCII8 = {0x04 , 0x3E , 0x44 , 0x24 , 0x00, // t // 116 - 126 0x3C , 0x40 , 0x20 , 0x7C , 0x00, // u 0x1C , 0x20 , 0x40 , 0x20 , 0x1C, // v 0x3C , 0x60 , 0x30 , 0x60 , 0x3C, // w 0x6C , 0x10 , 0x10 , 0x6C , 0x00, // x 0x9C , 0xA0 , 0x60 , 0x3C , 0x00, // y 0x64 , 0x54 , 0x54 , 0x4C , 0x00, // z 0x08 , 0x3E , 0x41 , 0x41 , 0x00, // { 0x00 , 0x00 , 0x7F , 0x00 , 0x00, // | 0x00 , 0x41 , 0x41 , 0x3E , 0x08, // } 0x02 , 0x01 , 0x02 , 0x01 , 0x00}; // ~ //Internal Implementations //------------------------------------------------------------------------------- //Send Commands or MX_GFXLCD_PARAMeter or data byte //------------------------------------------------------------------------------- void Lcd_sendbyte (char Command, char Lcdout) { char i; clear_bit(MX_GFXLCD_PORT, MX_GFXLCD_CS); //MX_GFXLCD_CS 0 start of sequence clear_bit(MX_GFXLCD_PORT, MX_GFXLCD_SCLK); //Clock 0 if (Command == MX_GFXLCD_CMD) { clear_bit(MX_GFXLCD_PORT, MX_GFXLCD_SDATA); //0 = MX_GFXLCD_CMD } else { set_bit(MX_GFXLCD_PORT, MX_GFXLCD_SDATA); //1 = MX_GFXLCD_PARAMeter } set_bit(MX_GFXLCD_PORT, MX_GFXLCD_SCLK); for (i=0;i<8;i++) { clear_bit(MX_GFXLCD_PORT, MX_GFXLCD_SCLK); //Clock 0 if (Lcdout & 0x80) set_bit(MX_GFXLCD_PORT, MX_GFXLCD_SDATA); //Output MSB else clear_bit(MX_GFXLCD_PORT, MX_GFXLCD_SDATA); set_bit(MX_GFXLCD_PORT, MX_GFXLCD_SCLK); //Clock 1 Lcdout = Lcdout << 1; //Shift Data to left } set_bit(MX_GFXLCD_PORT, MX_GFXLCD_CS); //MX_GFXLCD_CS to 1 at end of sequence } //------------------------------------------------------------------------------ //Open output Lcd_windows with coordinatex x1,y1 and x2,y2 //------------------------------------------------------------------------------ void Lcd_window (char X1, char Y1, char X2, char Y2) { Lcd_sendbyte(MX_GFXLCD_CMD, 0x2A); //Column adress Lcd_sendbyte(MX_GFXLCD_PARAM, X1); //X-Position upper left corner Lcd_sendbyte(MX_GFXLCD_PARAM, X2); //y-Position upper left corner Lcd_sendbyte(MX_GFXLCD_CMD, 0x2B); //Page adressing Lcd_sendbyte(MX_GFXLCD_PARAM, Y1); //x-Position of lower right corner Lcd_sendbyte(MX_GFXLCD_PARAM, Y2); //y-Position of lower right corner Lcd_sendbyte(MX_GFXLCD_CMD, 0x2C); } // Dummy function to close the defines section off void CUSTOM_Dummy_Function(); void CUSTOM_Dummy_Function() { /*Macro_GetDefines_End*/ } //------------------------------------------------------------------------------- //Initializing of the display //------------------------------------------------------------------------------- void Lcd_Init (void) { /*Macro_Lcd_Init_Start*/ char i; clear_bit(MX_GFXLCD_TRIS, MX_GFXLCD_RS); //Configure I/O clear_bit(MX_GFXLCD_TRIS, MX_GFXLCD_CS); clear_bit(MX_GFXLCD_TRIS, MX_GFXLCD_SDATA); clear_bit(MX_GFXLCD_TRIS, MX_GFXLCD_SCLK); clear_bit(MX_GFXLCD_PORT, MX_GFXLCD_RS); //Reset LCD delay_ms(10); //Always wait after a Reset set_bit(MX_GFXLCD_PORT, MX_GFXLCD_RS); //Startup LCD set_bit(MX_GFXLCD_PORT, MX_GFXLCD_CS); //Select LCD set_bit(MX_GFXLCD_PORT, MX_GFXLCD_SDATA); //Set Data Pin High set_bit(MX_GFXLCD_PORT, MX_GFXLCD_SCLK); //Set Clock Pin High Lcd_sendbyte(MX_GFXLCD_CMD, 0x01); delay_ms(10); //Wait after Reset Lcd_sendbyte(MX_GFXLCD_CMD, 0x11); //Sleep Out delay_ms(40); Lcd_sendbyte(MX_GFXLCD_CMD, 0x29); //Display On delay_ms(40); Lcd_sendbyte(MX_GFXLCD_CMD, 0x3A); //Interface Pixel Format.... Lcd_sendbyte(MX_GFXLCD_PARAM, 0x02); //....data format: 8 bit for each Pixel Lcd_sendbyte(MX_GFXLCD_CMD, 0x20); //No inveMX_GFXLCD_RSion, 0x21 would be inverted display (different coloMX_GFXLCD_RS!) Lcd_sendbyte(MX_GFXLCD_CMD, 0x2D); //RGB-Table for the 256 out of 4096 color mode for (i=0;i<20;i++) { Lcd_sendbyte(MX_GFXLCD_PARAM, DataInit[i]); //read predefined color table for 256 color mode } /*Macro_Lcd_Init_End*/ } //------------------------------------------------------------------------------ //Defines window area and fills with colour //------------------------------------------------------------------------------ void Lcd_DrawBox (char X1, char Y1, char X2, char Y2, char Colour) { /*Macro_Lcd_DrawBox_Start*/ char X,Y; short Pixel,Count; Lcd_window(X1,Y1,X2,Y2); //define window X = X2 - X1; X++; //# of X-Pixel Y = Y2 - Y1; Y++; //# of Y-Pixel Pixel = X * Y; //# of total pixel for (Count=0;Count 0) { height = 2; } while (height > 0) //If Height Doubled then send twice the amount of y pixels { for (k=0;k<5;k++) //For 5 ASCII bytes 0 - 4 { width = 1; if (Font == 2) { width = 2; } while (width > 0) //If Width Doubled then send twice the amount of x pixels { if (test_bit(temp[k],j)) { Lcd_sendbyte(MX_GFXLCD_PARAM, Fore_Colour); //Set pixel to foreground colour } else { Lcd_sendbyte(MX_GFXLCD_PARAM, Back_Colour); //Set pixel to background colour } width--; } } height--; } } } /*Macro_Lcd_Print_End*/ } //--------------------------------------------------------------------------- //Outputs one pixel onto the screen //--------------------------------------------------------------------------- void Lcd_Plot (char X1, char Y1, char Colour) { /*Macro_Lcd_Plot_Start*/ Lcd_window(X1,Y1,X1,Y1); //Creates output window of 1 pixel Lcd_sendbyte(MX_GFXLCD_PARAM, Colour); //set color of pixel /*Macro_Lcd_Plot_End*/ } //--------------------------------------------------------------------------- //Draws a line from one point to another //--------------------------------------------------------------------------- void Lcd_DrawLine (char X1, char Y1, char X2, char Y2, char Colour) { /*Macro_Lcd_DrawLine_Start*/ int C1, M1; signed int D1 = 0; signed int Pixelx = X2 - X1; //number of X-pixels; signed int Pixely = Y2 - Y1; //Number of Y-pixels signed char Xinc = 1; signed char Yinc = 1; if (Pixelx < 0) //If negative X direction { Xinc = -1; Pixelx = Pixelx * -1; } if (Pixely < 0) //If negative Y direction { Yinc = -1; Pixely = Pixely * -1; } if (Pixely <= Pixelx) { C1 = 2 * Pixelx; M1 = 2 * Pixely; while (X1 != X2) { Lcd_Plot(X1,Y1,Colour); //Plot line X1 = X1 + Xinc; D1 = D1 + M1; if (D1 > Pixelx) { Y1 = Y1 + Yinc; D1 = D1 - C1; } } } else { C1 = 2 * Pixely; M1 = 2 * Pixelx; while (Y1 != Y2) { Lcd_Plot(X1,Y1,Colour); //Plot Line Y1 = Y1 + Yinc; D1 = D1 + M1; if (D1 > Pixely) { X1 = X1 + Xinc; D1 = D1 - C1; } } Lcd_Plot(X1,Y1,Colour); } /*Macro_Lcd_DrawLine_End*/ }