📄 glcddriver.c
字号:
#include<p18f4525.h>
#include <stdio.h>
#include <delays.h>
#define GLCD_WIDTH 128
//#define GLCD_RS PORTAbits.RA0 // Data or Instruction input
//#define GLCD_RW PORTAbits.RA1 // Read/Write
//#define GLCD_E PORTAbits.RA2 // Enable
//#define GLCD_CS1 PORTAbits.RA3 // Chip Selection 1
//#define GLCD_CS2 PORTAbits.RA5 // Chip Selection 2
//#define GLCD_RST PORTCbits.RC6 // Reset
#define GLCD_RW LATAbits.LATA0 // Data or Instruction input
#define GLCD_RS LATAbits.LATA1 // Read/Write
#define GLCD_E LATAbits.LATA2 // Enable
#define GLCD_CS1 LATAbits.LATA3 // Chip Selection 1
#define GLCD_CS2 LATAbits.LATA5 // Chip Selection 2
#define GLCD_RST PORTCbits.RC6 // Reset
#define GLCD_LEFT 1
#define GLCD_RIGHT 0
#define ON 1
#define OFF 0
unsigned static char current_position_X=0;
unsigned static char current_position_Y=0;
unsigned char colour=0;
//****************************************************************
// Function Definition
//****************************************************************
void glcd_WaitIfBusy(void);
void glcd_WaitIfReset(void);
void glcd_WriteCommand(unsigned char side,unsigned char Command);
void glcd_WriteData(unsigned int side,unsigned char Data);
char glcd_ReadData(unsigned char side);
void glcd_init(unsigned char mode);
void glcd_pixel(unsigned char x, unsigned char y, unsigned char color);
void glcd_fillScreen(unsigned char color);
void BlinkCurser(unsigned int x,unsigned int y);
void GoTo_XY(unsigned int x,unsigned int y,unsigned char colour1);
void PrintCharOnLCD(char data);
void DisplayOff();
void DisplayOn();
void PlotOutSideSquare();
void Delay();
void BitSet(unsigned char *Data,unsigned char bitpos);
void BitClear(unsigned char *Data,unsigned int bitpos);
unsigned char BitTest(unsigned char Data,unsigned int bitpos);
void ShowTitle();
void PrintStringOnLCD(char *Data);
//******************************************************************
//******************************************************************
/////////////////////////////////////////////////////////////////////////
unsigned char charsel,charreverse=0;
unsigned int charpos=0;
const rom char TABLE[672]= { 0x00,0x00,0x00,0x00,0x00,0x00,0x00, // 20 space ASCII table for Graphic LCD: 36 rows * 7 bytes= 252 bytes
0x00,0x00,0x00,0x5f,0x00,0x00,0x00, // 21 !
0x00,0x00,0x07,0x00,0x07,0x00,0x00, // 22 "
0x00,0x14,0x7f,0x14,0x7f,0x14,0x00, // 23 #
0x00,0x24,0x2a,0x7f,0x2a,0x12,0x00, // 24 $
0x00,0x23,0x13,0x08,0x64,0x62,0x00, // 25 %
0x00,0x36,0x49,0x55,0x22,0x50,0x00, // 26 &
0x00,0x00,0x05,0x03,0x00,0x00,0x00, // 27 '
0x00,0x00,0x1c,0x22,0x41,0x00,0x00, // 28 (
0x00,0x00,0x41,0x22,0x1c,0x00,0x00, // 29 )
0x00,0x14,0x08,0x3e,0x08,0x14,0x00, // 2a *
0x00,0x08,0x08,0x3e,0x08,0x08,0x00, // 2b +
0x00,0x00,0x50,0x30,0x00,0x00,0x00, // 2c ,
0x00,0x08,0x08,0x08,0x08,0x08,0x00, // 2d -
0x00,0x00,0x60,0x60,0x00,0x00,0x00, // 2e .
0x00,0x20,0x10,0x08,0x04,0x02,0x00, // 2f /
0x00,0x3e,0x51,0x49,0x45,0x3e,0x00, // 30 0
0x00,0x00,0x42,0x7f,0x40,0x00,0x00, // 31 1
0x00,0x42,0x61,0x51,0x49,0x46,0x00, // 32 2
0x00,0x21,0x41,0x45,0x4b,0x31,0x00, // 33 3
0x00,0x18,0x14,0x12,0x7f,0x10,0x00, // 34 4
0x00,0x27,0x45,0x45,0x45,0x39,0x00, // 35 5
0x00,0x3c,0x4a,0x49,0x49,0x30,0x00, // 36 6
0x00,0x01,0x71,0x09,0x05,0x03,0x00, // 37 7
0x00,0x36,0x49,0x49,0x49,0x36,0x00, // 38 8
0x00,0x06,0x49,0x49,0x29,0x1e,0x00, // 39 9
0x00,0x00,0x36,0x36,0x00,0x00,0x00, // 3a :
0x00,0x00,0x56,0x36,0x00,0x00,0x00, // 3b ;
0x00,0x08,0x14,0x22,0x41,0x00,0x00, // 3c <
0x00,0x14,0x14,0x14,0x14,0x14,0x00, // 3d =
0x00,0x00,0x41,0x22,0x14,0x08,0x00, // 3e >
0x00,0x02,0x01,0x51,0x09,0x06,0x00, // 3f ?
0x00,0x32,0x49,0x79,0x41,0x3e,0x00, // 40 @
0x00,0x7E,0x09,0x09,0x09,0x7E,0x00, // 41 A
0x00,0x7f,0x49,0x49,0x49,0x36,0x00, // 42 B
0x00,0x3e,0x41,0x41,0x41,0x22,0x00, // 43 C
0x00,0x7f,0x41,0x41,0x22,0x1c,0x00, // 44 D ASCII table for Graphic LCD: 36 rows * 7 bytes= 252 bytes
0x00,0x7f,0x49,0x49,0x49,0x41,0x00, // 45 E
0x00,0x7f,0x09,0x09,0x09,0x01,0x00, // 46 F
0x00,0x3e,0x41,0x49,0x49,0x7a,0x00, // 47 G
0x00,0x7f,0x08,0x08,0x08,0x7f,0x00, // 48 H
0x00,0x00,0x41,0x7f,0x41,0x00,0x00, // 49 I
0x00,0x20,0x40,0x41,0x3f,0x01,0x00, // 4a J
0x00,0x7f,0x08,0x14,0x22,0x41,0x00, // 4b K
0x00,0x7f,0x40,0x40,0x40,0x40,0x00, // 4c L
0x00,0x7f,0x02,0x0c,0x02,0x7f,0x00, // 4d M
0x00,0x7f,0x04,0x08,0x10,0x7f,0x00, // 4e N
0x00,0x3e,0x41,0x41,0x41,0x3e,0x00, // 4f O
0x00,0x7f,0x09,0x09,0x09,0x06,0x00, // 50 P
0x00,0x3e,0x41,0x51,0x21,0x5e,0x00, // 51 Q
0x00,0x7f,0x09,0x19,0x29,0x46,0x00, // 52 R
0x00,0x46,0x49,0x49,0x49,0x31,0x00, // 53 S
0x00,0x01,0x01,0x7f,0x01,0x01,0x00, // 54 T
0x00,0x3f,0x40,0x40,0x40,0x3f,0x00, // 55 U
0x00,0x1f,0x20,0x40,0x20,0x1f,0x00, // 56 V
0x00,0x3f,0x40,0x38,0x40,0x3f,0x00, // 57 W
0x00,0x63,0x14,0x08,0x14,0x63,0x00, // 58 X
0x00,0x07,0x08,0x70,0x08,0x07,0x00, // 59 Y
0x00,0x61,0x51,0x49,0x45,0x43,0x00, // 5a Z
0x00,0x00,0x7f,0x41,0x41,0x00,0x00, // 5b [
0x00,0x02,0x04,0x08,0x10,0x20,0x00, // 5c
0x00,0x00,0x41,0x41,0x7f,0x00,0x00, // 5d
0x00,0x04,0x02,0x01,0x02,0x04,0x00, // 5e
0x00,0x40,0x40,0x40,0x40,0x40,0x00, // 5f
0x00,0x00,0x01,0x02,0x04,0x00,0x00, // 60
0x00,0x20,0x54,0x54,0x54,0x78,0x00, // 61 a
0x00,0x7f,0x48,0x44,0x44,0x38,0x00, // 62 b
0x00,0x38,0x44,0x44,0x44,0x20,0x00, // 63 c
0x00,0x38,0x44,0x44,0x48,0x7f,0x00, // 64 d
0x00,0x38,0x54,0x54,0x54,0x18,0x00, // 65 e
0x00,0x08,0x7e,0x09,0x01,0x02,0x00, // 66 f
0x00,0x0c,0x52,0x52,0x52,0x3e,0x00, // 67 g
0x00,0x7f,0x08,0x04,0x04,0x78,0x00, // 68 h ASCII table for Graphic LCD:24 rows * 7 bytes= 252 bytes
0x00,0x00,0x44,0x7d,0x40,0x00,0x00, // 69 i
0x00,0x20,0x40,0x44,0x3d,0x00,0x00, // 6a j
0x00,0x7f,0x10,0x28,0x44,0x00,0x00, // 6b k
0x00,0x00,0x41,0x7f,0x40,0x00,0x00, // 6c l
0x00,0x7c,0x04,0x18,0x04,0x78,0x00, // 6d m
0x00,0x7c,0x08,0x04,0x04,0x78,0x00, // 6e n
0x00,0x38,0x44,0x44,0x44,0x38,0x00, // 6f o
0x00,0x7c,0x14,0x14,0x14,0x08,0x00, // 70 p
0x00,0x08,0x14,0x14,0x18,0x7c,0x00, // 71 q
0x00,0x7c,0x08,0x04,0x04,0x08,0x00, // 72 r
0x00,0x48,0x54,0x54,0x54,0x20,0x00, // 73 s
0x00,0x04,0x3f,0x44,0x40,0x20,0x00, // 74 t
0x00,0x3c,0x40,0x40,0x20,0x7c,0x00, // 75 u
0x00,0x1c,0x20,0x40,0x20,0x1c,0x00, // 76 v
0x00,0x3c,0x40,0x30,0x40,0x3c,0x00, // 77 w
0x00,0x44,0x28,0x10,0x28,0x44,0x00, // 78 x
0x00,0x0c,0x50,0x50,0x50,0x3c,0x00, // 79 y
0x00,0x44,0x64,0x54,0x4c,0x44,0x00, // 7a z
0x00,0x00,0x08,0x36,0x41,0x00,0x00, // 7b
0x00,0x00,0x00,0x7f,0x00,0x00,0x00, // 7c
0x00,0x00,0x41,0x36,0x08,0x00,0x00, // 7d
0x00,0x24,0x24,0x24,0x3C,0x18,0x00, // 7e
0x00,0x3C,0x24,0x24,0x24,0x240,0x00}; // 7f
//
const char checkOnBox[]={0xff,0x91,0xA1,0x91,0x89,0x85,0xff}; //enabled check box ascii table
const char checkOffBox[]={0xff,0x81,0x81,0x81,0x81,0x81,0xff};
// ------------------------------------------------------
// GLCD Picture name: untitled2.bmp
// GLCD Model: KS0108 128x64
// ------------------------------------------------------
const rom char Welcome[1024] = {
0, 0, 0,248,248,248,120, 56,152,200,224, 48, 56, 56, 56, 56,
56, 56, 56, 0, 0, 0,248,248,248, 0, 0,128,192,224,240,248,
120, 56, 24, 8, 0, 0,240,248,248, 56, 56, 56, 56, 56, 56, 56,
56, 56, 56, 0, 0,248,248,248, 0, 0, 0, 0, 0, 56, 56, 56,
56, 56,248,248,248, 56, 56, 56, 56, 56, 0,248,248,248, 56, 56,
56, 56, 56, 56, 56, 56,120,120,240,224,192, 0,240,248,248,120,
56, 56, 56, 56, 56, 56, 56,120,248,248,240, 0, 0,248,248,248,
240,224,192,128, 0, 0, 0, 0, 0, 0,248,248,248, 0, 0, 0,
0, 0, 0,251,241,224,202,155, 59,123,251,128,128,155,155,155,
155,155,155, 0, 0, 0,255,255,255, 14, 15, 15, 15, 15, 15, 14,
30,254,252,248, 0, 0,255,255,255,142,142,142,142,142,142,142,
142,142,142, 0, 0,255,255,255,128,128,128,128,128,128,128,128,
128, 0,255,255,255, 0, 0, 0, 0, 0, 0,255,255,255, 4, 4,
12, 28, 60,124,252,252,236,206,135, 3, 1, 0,255,255,255,192,
128,128,128,128,128,128,128,192,255,255,255, 0, 0,255,255,255,
1, 3, 7, 15, 31, 62,124,248,240,224,255,255,255, 0, 0, 0,
0, 0, 0, 3, 3, 3, 3, 3, 3, 2, 0, 1, 3, 3, 3, 3,
3, 3, 3, 0, 0, 0, 3, 3, 3, 0, 0, 0, 0, 0, 0, 0,
0, 3, 3, 3, 0, 0, 1, 3, 3, 3, 3, 3, 3, 3, 3, 3,
3, 3, 3, 0, 0, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
3, 0, 3, 3, 3, 0, 0, 0, 0, 0, 0, 3, 3, 3, 0, 0,
0, 0, 0, 0, 0, 1, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 1, 0, 0, 3, 3, 3,
0, 0, 0, 0, 0, 0, 0, 0, 1, 3, 3, 3, 3, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
16,240,240, 16, 0, 16,240,240, 16, 0, 0, 16,240,240, 16, 16,
16,240,224, 0, 0, 0,224,240,144,144, 16, 48,112,192, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 31, 63, 32, 32, 32, 63, 31, 0, 0, 0, 32, 63, 63, 33, 1,
1, 1, 0, 0, 0, 0, 12, 57, 49, 33, 35, 35, 62, 30, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 32,224,224,224,192, 0, 0, 0,192,224,224,224,
32, 0, 0, 0, 0, 0,224,224,224, 0, 0, 0, 0, 0, 32,224,
224,224,192, 0, 32,224,224, 32, 0, 0, 0, 0,224,224,224, 0,
0, 0, 0, 0, 0,192, 64, 32, 32, 32, 96,224,128, 0, 0, 32,
224,224, 32, 32, 32, 96,224,128, 0, 0, 0, 32,224,224,224,192,
0, 0, 0,192,224,224,224, 32, 0, 0, 32,224,224, 32, 32, 32,
96,224,128, 0, 0, 0, 32,224,224,224,192, 0, 32,224,224, 32,
0,128,224, 96, 32,224,224, 32, 96,224,128, 0, 0, 0, 0, 0,
0, 0, 0, 0, 64,127,127, 65, 7, 63,120, 63, 7, 64,127,127,
64, 0, 0, 64,120,127, 79, 8, 79,127,120, 64, 0, 0, 64,127,
127, 64, 3, 15, 60,127,127, 0, 0, 64,120,127, 79, 8, 79,127,
120, 64, 0, 0, 15, 63, 48, 64, 64, 64, 68,125,125, 4, 0, 64,
127,127, 66, 66, 71, 96,120, 24, 0, 0, 0, 64,127,127, 65, 7,
63,120, 63, 7, 64,127,127, 64, 0, 0, 64,127,127, 66, 66, 71,
96,120, 24, 0, 0, 0, 64,127,127, 64, 3, 15, 60,127,127, 0,
0, 0, 0, 0, 64,127,127, 64, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
};
//disaled check box ascii table
//----------------------------------------------------------------------------------------------
// Name: glcd_WaitIfBusy(void)
// Purpose: check and wait till busy flag low
//
// Inputs: None
// Date: 8/12/2006
//----------------------------------------------------------------------------------------------
void glcd_WaitIfBusy(void)
{
TRISBbits.TRISB7=1; //set the d port as input
GLCD_RW = 1; // Staus Read mode
GLCD_RS = 0;
do
{
GLCD_E = 0;
GLCD_E = 1; //Enable cycle to read data
Delay();
GLCD_E = 0;
} while (PORTBbits.RB7); //busy pin check
}
//----------------------------------------------------------------------------------------------
// Name: glcd_WaitIfReset(void)
// Purpose: check and wait till reset flag low
//
// Inputs: None
// Date: 8/12/2006
//----------------------------------------------------------------------------------------------
void glcd_WaitIfReset(void)
{
TRISBbits.TRISB4=1; // set d port as input
GLCD_RW = 1; // status read mode
GLCD_RS = 0;
do
{
GLCD_E = 0;
GLCD_E = 1; //enable cycle to read data
Delay();
GLCD_E = 0;
} while (PORTBbits.RB4); //check reset status
}
//----------------------------------------------------------------------------------------------
// Name: glcd_WriteCommand(unsigned char Command)
// Purpose: write the command to the GLCD
//
// Inputs: dispaly side,instruction /command
// Date: 8/12/2006
//----------------------------------------------------------------------------------------------
void glcd_WriteCommand(unsigned char side,unsigned char Command)
{
unsigned int tempcmd=0;
unsigned char *temp;
temp=(unsigned char*)&tempcmd;
*temp=Command;
if(side)
{
GLCD_CS1=1; // for left side display setting
GLCD_CS2=0;
}
else
{
GLCD_CS2=1; //for right side dispaly setting
GLCD_CS1=0;
}
glcd_WaitIfBusy(); //check the lcd busy
TRISBbits.TRISB0=0;
TRISBbits.TRISB1=0;
TRISBbits.TRISB2=0;
TRISBbits.TRISB3=0;
TRISBbits.TRISB4=0;
TRISBbits.TRISB5=0;
TRISBbits.TRISB6=0;
TRISBbits.TRISB7=0;
GLCD_E = 0;
GLCD_RW =0; // setting for instructin write
GLCD_RS =0;
PORTB=tempcmd; //send command to port d
GLCD_E = 1; // enable write operation
Delay();
GLCD_E = 0;
}
//----------------------------------------------------------------------------------------------
// Name: glcd_WriteData(unsigned char Data)
// Purpose: write the Display Data to the GLCD
//
// Inputs: dispaly side, data
// Date: 8/12/2006
//----------------------------------------------------------------------------------------------
void glcd_WriteData(unsigned int side,unsigned char Data)
{
unsigned int tempdata=0;
unsigned char *temp;
temp=(unsigned char*)&tempdata;
*temp=Data;
if(side)
{
GLCD_CS1=1; //for left side dispay
GLCD_CS2=0;
}
else
{
GLCD_CS2=1; //for right side dispaly
GLCD_CS1=0;
}
glcd_WaitIfBusy(); //check lcd busy
TRISBbits.TRISB0=0;
TRISBbits.TRISB1=0;
TRISBbits.TRISB2=0;
TRISBbits.TRISB3=0;
TRISBbits.TRISB4=0;
TRISBbits.TRISB5=0;
TRISBbits.TRISB6=0;
TRISBbits.TRISB7=0; //port d as output
GLCD_E = 0;
GLCD_RW = 0; // setting for write data
GLCD_RS = 1;
PORTB=tempdata; //send data to port d
GLCD_E = 1; //enable cycle to write
Delay();
GLCD_E = 0;
}
//----------------------------------------------------------------------------------------------
// Name: glcd_ReadData(void)
// Purpose: read the Display Data from the GLCD
//
// Inputs: Dispay side
// Output: read data
// Date: 8/12/2006
//----------------------------------------------------------------------------------------------
char glcd_ReadData(unsigned char side)
{
char data;
unsigned int tempdata=0;
unsigned char *temp;
if(side)
{
GLCD_CS2=0; // left side display
GLCD_CS1=1;
}
else
{
GLCD_CS1=0; //right side dispaly
GLCD_CS2=1;
}
glcd_WaitIfBusy(); // check lcd busy
TRISBbits.TRISB0=1;
TRISBbits.TRISB1=1;
TRISBbits.TRISB2=1;
TRISBbits.TRISB3=1;
TRISBbits.TRISB4=1;
TRISBbits.TRISB5=1;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -