/************************************************************************************************
;* This program interfaces to a 128 x 64 dot matrix LCD module *
;* using the Toshiba T6963C control chip *
;* *
;************************************************************************************************
;* tested with a Varitron 128X64 Display 6x8 FONT 30 character's on line *
;* *
;* Date : 11-02-2002 *
;* *
;* AJ van Gelder (PA3GDB) *
;* *
;* *
;* modified : 22-02-2003 *
;* was original used for a UHF/VHF spektrummonitor c.q spektrumanalyzer *
;* and is modified for multipropose *
;* *
;************************************************************************************************
;* *
;* INCLUDE LCD873.H *
;* *
;************************************************************************************************/
#include "LCD873.h"
#ifdef old_C2C
char input_pin_port_b(char pinNumber)
{
char testValue = 0x01;
char i[8] =
{
00000001b,
00000010b,
00000100b,
00001000b,
00010000b,
00100000b,
01000000b,
10000000b
};
pinNumber = pinNumber & 00000111b;
pinNumber = i[pinNumber];
asm movfw PORTB ;
asm movwf _testValue_input_pin_port_b;
testValue = i[0];
if( (testValue & pinNumber) > 0)
{
return 0x01;
}
return 0x00;
}
//==============================================================================================//
char input_pin_port_c(char pinNumber)
{
char testValue = 0x01;
char i[8] =
{
00000001b,
00000010b,
00000100b,
00001000b,
00010000b,
00100000b,
01000000b,
10000000b
};
pinNumber = pinNumber & 00000111b;
pinNumber = i[pinNumber];
asm movfw PORTC ;
asm movwf _testValue_input_pin_port_c;
testValue = i[0];
if( (testValue & pinNumber) > 0)
{
return 0x01;
}
return 0x00;
}
//==============================================================================================//
char input_pin_port_a(char pinNumber)
{
char testValue = 0x01;
char i[8] =
{
00000001b,
00000010b,
00000100b,
00001000b,
00010000b,
00100000b,
01000000b,
10000000b
};
pinNumber = pinNumber & 00000111b;
pinNumber = i[pinNumber];
asm movfw PORTA ;
asm movwf _testValue_input_pin_port_a;
testValue = i[0];
if( (testValue & pinNumber) > 0)
{
return 0x01;
}
return 0x00;
}
#endif
//////////////////////////////////////////////////////////////////////////////////////////////////
// AutoSend - Sends a byte to the LCD //
// data1 in DATABUFA //
// assumes that the autowrite command has been sent //
//////////////////////////////////////////////////////////////////////////////////////////////////
#ifdef portA_LCDcontrol
void lcd_AutoSend(void)
{
lcd_AutoStatusCheck(); // Wait for LCD to be ready
nop(); // sets CE, C/D & WR, clears RD, Data lines O/Ps
output_port_b(DATABUFA);
nop();
output_low_port_a(LCD_C_D);
nop();
output_high_port_a(LCD_RD);
nop();
output_low_port_a(LCD_WR);
nop();
output_low_port_a(LCD_CE);
nop();
output_high_port_a(LCD_CE);
}
//////////////////////////////////////////////////////////////////////////////////////////////////
// This routine checks the auto busy flags, returns when not busy //
// //
// this routine assumes data lines set to O/P //
//////////////////////////////////////////////////////////////////////////////////////////////////
void lcd_AutoStatusCheck(void)
{
nop();
output_low_port_a(LCD_CE);
nop();
set_tris_b(0xFF);
nop();
output_high_port_a(LCD_C_D); // Set LCD to status read
nop();
output_low_port_a(LCD_RD);
nop();
output_high_port_a(LCD_WR);
nop();
output_low_port_a(LCD_CE);
TESTLCDSTATUS:
asm nop;
if(!(input_pin_port_b(2)) && !(input_pin_port_b(3)))
{
goto TESTLCDSTATUS;// goto AutoStatusCheck;
}
output_high_port_a(LCD_CE);
nop();
set_tris_b(0x00);
nop();
}
//////////////////////////////////////////////////////////////////////////////////////////////////
// SEND_2DATA_CMD - Sends 2 byte of data and command to LCD //
// command in COMMANDBUF, data1 in DATABUFA, data2 in DATABUFB //
//////////////////////////////////////////////////////////////////////////////////////////////////
void lcd_Send2DataCMD(void)
{
lcd_BusyCheck(); // Wait for LCD to be ready
nop(); // sets CE, C/D & WR, clears RD, Data lines O/Ps
output_port_b(DATABUFB);
nop();
output_low_port_a(LCD_C_D);
nop();
output_high_port_a(LCD_RD);
nop();
output_low_port_a(LCD_CE);
nop();
output_low_port_a(LCD_WR);
nop();
output_high_port_a(LCD_WR);
nop();
output_high_port_a(LCD_CE); // busy_check will set CE high again
nop();
lcd_Send1DataCMD();
nop();
}
//////////////////////////////////////////////////////////////////////////////////////////////////
// SEND_1DATA_CMD - Sends 1 byte of data and command to LCD //
// command in COMMANDBUF, data in DATABUFA //
//////////////////////////////////////////////////////////////////////////////////////////////////
void lcd_Send1DataCMD(void)
{
lcd_BusyCheck(); // Wait for LCD to be ready
nop(); // sets CE, C/D & WR, clears RD, Data lines O/Ps
output_port_b(DATABUFA);
nop();
output_low_port_a(LCD_C_D);
nop();
output_high_port_a(LCD_RD);
nop();
output_low_port_a(LCD_CE);
nop();
output_low_port_a(LCD_WR);
nop(); // busy check call long enough
output_high_port_a(LCD_WR);
nop();
output_high_port_a(LCD_CE); // busy_check will set CE high again
nop();
lcd_SendCMD();
nop();
}
//////////////////////////////////////////////////////////////////////////////////////////////////
// This routine checks the busy flags, returns when not busy //
// //
// this routine assumes data lines set to O/P //
//////////////////////////////////////////////////////////////////////////////////////////////////
void lcd_BusyCheck(void)
{
nop();
output_high_port_a(LCD_CE);
nop();
set_tris_b(0xFF);
nop();
output_high_port_a(LCD_C_D); // Set LCD to status read
nop();
output_high_port_a(LCD_WR);
nop();
output_low_port_a(LCD_CE); // Enable
nop();
output_low_port_a(LCD_RD);
TESTLCDBUSY:
if(!(input_pin_port_b(0)) && !(input_pin_port_b(1)))
{
goto TESTLCDBUSY; // goto BusyCheck;
}
output_high_port_a(LCD_RD);
nop();
output_high_port_a(LCD_CE);
nop();
set_tris_b(0x00);
asm bcf STATUS,RP0;
nop();
}
//////////////////////////////////////////////////////////////////////////////////////////////////
// SEND_CMD - Sends command to LCD //
// command in COMMANDBUF //
//////////////////////////////////////////////////////////////////////////////////////////////////
void lcd_SendCMD(void)
{
lcd_BusyCheck(); // Wait for LCD to be ready
nop(); // sets CE, C/D & WR, clears RD, Data lines O/Ps
output_port_b(COMMANDBUF);
nop();
output_high_port_a(LCD_RD);
nop();
output_low_port_a(LCD_CE);
nop();
output_low_port_a(LCD_WR);
nop(); // busy check call long enough
output_high_port_a(LCD_WR);
nop();
output_high_port_a(LCD_CE);
nop();
}
#endif
//////////////////////////////////////////////////////////////////////////////////////////////////
// AutoSend - Sends a byte to the LCD //
// data1 in DATABUFA //
// assumes that the autowrite command has been sent //
//////////////////////////////////////////////////////////////////////////////////////////////////
#ifdef portC_LCDcontrol
void lcd_AutoSend(void)
{
lcd_AutoStatusCheck(); // Wait for LCD to be ready
nop(); // sets CE, C/D & WR, clears RD, Data lines O/Ps
output_port_b(DATABUFA);
nop();
output_low_port_c(LCD_C_D);
nop();
output_high_port_c(LCD_RD);
nop();
output_low_port_c(LCD_WR);
nop();
output_low_port_c(LCD_CE);
nop();
output_high_port_c(LCD_CE);
}
//////////////////////////////////////////////////////////////////////////////////////////////////
// This routine checks the auto busy flags, returns when not busy //
// //
// this routine assumes data lines set to O/P //
//////////////////////////////////////////////////////////////////////////////////////////////////
void lcd_AutoStatusCheck(void)
{
nop();
output_low_port_c(LCD_CE);
nop();
set_tris_b(0xFF);
nop();
output_high_port_c(LCD_C_D); // Set LCD to status read
nop();
output_low_port_c(LCD_RD);
nop();
output_high_port_c(LCD_WR);
nop();
output_low_port_c(LCD_CE);
TESTLCDSTATUS:
asm nop;
if(!(input_pin_port_b(2)) && !(input_pin_port_b(3)))
{
goto TESTLCDSTATUS;// goto AutoStatusCheck;
}
output_high_port_c(LCD_CE);
nop();
set_tris_b(0x00);
nop();
}
//////////////////////////////////////////////////////////////////////////////////////////////////
// SEND_2DATA_CMD - Sends 2 byte of data and command to LCD //
// command in COMMANDBUF, data1 in DATABUFA, data2 in DATABUFB //
//////////////////////////////////////////////////////////////////////////////////////////////////
void lcd_Send2DataCMD(void)
{
lcd_BusyCheck(); // Wait for LCD to be ready
nop(); // sets CE, C/D & WR, clears RD, Data lines O/Ps
output_port_b(DATABUFB);
nop();
output_low_port_c(LCD_C_D);
nop();
output_high_port_c(LCD_RD);
nop();
output_low_port_c(LCD_CE);
nop();
output_low_port_c(LCD_WR);
nop();
output_high_port_c(LCD_WR);
nop();
output_high_port_c(LCD_CE); // busy_check will set CE high again
nop();
lcd_Send1DataCMD();
nop();
}
//////////////////////////////////////////////////////////////////////////////////////////////////
// SEND_1DATA_CMD - Sends 1 byte of data and command to LCD //
// command in COMMANDBUF, data in DATABUFA //
//////////////////////////////////////////////////////////////////////////////////////////////////
void lcd_Send1DataCMD(void)
{
lcd_BusyCheck(); // Wait for LCD to be ready
nop(); // sets CE, C/D & WR, clears RD, Data lines O/Ps
output_port_b(DATABUFA);
nop();
output_low_port_c(LCD_C_D);
nop();
output_high_port_c(LCD_RD);
nop();
output_low_port_c(LCD_CE);
nop();
output_low_port_c(LCD_WR);
nop(); // busy check call long enough
output_high_port_c(LCD_WR);
nop();
output_high_port_c(LCD_CE); // busy_check will set CE high again
nop();
lcd_SendCMD();
nop();
}
//////////////////////////////////////////////////////////////////////////////////////////////////
// This routine checks the busy flags, returns when not busy //
// //
// this routine assumes data lines set to O/P //
//////////////////////////////////////////////////////////////////////////////////////////////////
void lcd_BusyCheck(void)
{
nop();
output_high_port_c(LCD_CE);
nop();
set_tris_b(0xFF);
nop();
output_high_port_c(LCD_C_D); // Set LCD to status read
nop();
output_high_port_c(LCD_WR);
nop();
output_low_port_c(LCD_CE); // Enable
nop();
output_low_port_c(LCD_RD);
TESTLCDBUSY:
if(!(input_pin_port_b(0)) && !(input_pin_port_b(1)))
{
goto TESTLCDBUSY; // goto BusyCheck;
}
output_high_port_c(LCD_RD);
nop();
output_high_port_c(LCD_CE);
nop();
set_tris_b(0x00);
asm bcf STATUS,RP0;
nop();
}
//////////////////////////////////////////////////////////////////////////////////////////////////
// SEND_CMD - Sends command to LCD //
// command in COMMANDBUF //
//////////////////////////////////////////////////////////////////////////////////////////////////
void lcd_SendCMD(void)
{
lcd_BusyCheck(); // Wait for LCD to be ready
nop(); // sets CE, C/D & WR, clears RD, Data lines O/Ps
output_port_b(COMMANDBUF);
nop();
output_high_port_c(LCD_RD);
nop();
output_low_port_c(LCD_CE);
nop();
output_low_port_c(LCD_WR);
nop(); // busy check call long enough
output_high_port_c(LCD_WR);
nop();
output_high_port_c(LCD_CE);
nop();
}
#endif
//////////////////////////////////////////////////////////////////////////////////////////////////
//
//////////////////////////////////////////////////////////////////////////////////////////////////
char lcd_MakeASCII(char textReg)
{
return(textReg - 0x20);
}
//////////////////////////////////////////////////////////////////////////////////////////////////
// DISPLAY MODE ROUTINE'S //
//////////////////////////////////////////////////////////////////////////////////////////////////
void lcd_GrhModeSet(void)
{
COMMANDBUF = OR_MODE;
lcd_SendCMD();
}
//////////////////////////////////////////////////////////////////////////////////////////////////
//
//////////////////////////////////////////////////////////////////////////////////////////////////
void lcd_DisplayXORMode(void)
{
COMMANDBUF = XOR_MODE;
lcd_SendCMD();
}
//////////////////////////////////////////////////////////////////////////////////////////////////
//
//////////////////////////////////////////////////////////////////////////////////////////////////
void lcd_TxtModeOn(void)
{
COMMANDBUF = TEXT_ON;
lcd_SendCMD();
}
//////////////////////////////////////////////////////////////////////////////////////////////////
//
//////////////////////////////////////////////////////////////////////////////////////////////////
void lcd_GrhModeOn(void)
{
COMMANDBUF = GRAPHIC_ON;
lcd_SendCMD();
}
//////////////////////////////////////////////////////////////////////////////////////////////////
//
//////////////////////////////////////////////////////////////////////////////////////////////////
void lcd_GrhTxtModeOn(void)
{
COMMANDBUF = TXT_GRH_ON ;
lcd_SendCMD();
}
//////////////////////////////////////////////////////////////////////////////////////////////////
//
//////////////////////////////////////////////////////////////////////////////////////////////////
void lcd_GrhHomeArea(void)
{
COMMANDBUF = GRAPH_AREA_SET;
lcd_Send2DataCMD();
}
//////////////////////////////////////////////////////////////////////////////////////////////////
//
//////////////////////////////////////////////////////////////////////////////////////////////////
void lcd_GrhHomeAdres(void)
{
COMMANDBUF = GRAPH_HOME_SET;
lcd_Send2DataCMD();
}
//////////////////////////////////////////////////////////////////////////////////////////////////
//
//////////////////////////////////////////////////////////////////////////////////////////////////
void lcd_SetCursor(void)
{
COMMANDBUF = CURSOR_PTR_SET;
lcd_Send2DataCMD();
}
//////////////////////////////////////////////////////////////////////////////////////////////////
//
//////////////////////////////////////////////////////////////////////////////////////////////////
void lcd_HomePointer(void)
{
COMMANDBUF = ADDR_PTR_SET;
lcd_Send2DataCMD();
}
//////////////////////////////////////////////////////////////////////////////////////////////////
//
//////////////////////////////////////////////////////////////////////////////////////////////////
void lcd_TxtHomeAdres(void) // SET FIRST ADRES OF TEXT ADRES IN DISPLAY
{
COMMANDBUF = TEXT_HOME_SET;
lcd_Send2DataCMD();
}
//////////////////////////////////////////////////////////////////////////////////////////////////
//
//////////////////////////////////////////////////////////////////////////////////////////////////
void lcd_TxtHomeArea(void) // SET TEXT COLLUM WITH
{
COMMANDBUF = TEXT_AREA_SET;
lcd_Send2DataCMD();
}
//////////////////////////////////////////////////////////////////////////////////////////////////
// WRITE GRAPHIC DATA //
//////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////
// WRITE GRAPHIC DATA INCREMENT ADRES POINTER //
//////////////////////////////////////////////////////////////////////////////////////////////////
void lcd_WriteGrhInc(char data)
{
DATABUFA = data;
COMMANDBUF = DATA_WR_INC;
lcd_Send1DataCMD();
}
//////////////////////////////////////////////////////////////////////////////////////////////////
// WRITE GRAPHIC DATA DECREMENT ADRES POINTER //
//////////////////////////////////////////////////////////////////////////////////////////////////
void lcd_WriteGrhDec(char data)
{
DATABUFA = data;
COMMANDBUF = DATA_WR_DEC;
lcd_Send1DataCMD();
}
//////////////////////////////////////////////////////////////////////////////////////////////////
// WRITE GRAPHIC DATA NO CHANCE OF ADRES POINTER //
//////////////////////////////////////////////////////////////////////////////////////////////////
void lcd_WriteGrhNor(char data)
{
DATABUFA = data;
COMMANDBUF = DATA_WR;
lcd_Send1DataCMD();
}
//////////////////////////////////////////////////////////////////////////////////////////////////
// WRITE ASCII DATA WITH INCREMENT OF DATA POINTER //
//////////////////////////////////////////////////////////////////////////////////////////////////
void LCDputchar(char data)
{
DATABUFA = data - 0x20;
COMMANDBUF = DATA_WR_INC;
lcd_Send1DataCMD();
}
//////////////////////////////////////////////////////////////////////////////////////////////////
// WRITE ASCII DATA WITH DECREMENT OF DATA POINTER //
//////////////////////////////////////////////////////////////////////////////////////////////////
void lcd_WriteASCII_Dec(char data)
{
DATABUFA = data - 0x20;
COMMANDBUF = DATA_WR_DEC;
lcd_Send1DataCMD();
}
//////////////////////////////////////////////////////////////////////////////////////////////////
// WRITE ASCII DATA NO MODIFICATION OF DATA POINTER //
//////////////////////////////////////////////////////////////////////////////////////////////////
void lcd_WriteASCII_Nor(char data)
{
DATABUFA = data - 0x20;
COMMANDBUF = DATA_WR;
lcd_Send1DataCMD();
}
//////////////////////////////////////////////////////////////////////////////////////////////////
// INITIALISATION OF LCD //
//////////////////////////////////////////////////////////////////////////////////////////////////
void LCDIniSet(void)
{
lcd_GrhModeSet();
DATABUFB = 0x00;
DATABUFA = 0x10;
lcd_GrhHomeAdres();
DATABUFB = 16;
DATABUFA = 0x00;
lcd_GrhHomeArea();
DATABUFB = 0x00;
DATABUFA = 0x00;
lcd_TxtHomeAdres();
DATABUFB = 16;
DATABUFA = 0;
lcd_TxtHomeArea();
COMMANDBUF = TXT_GRH_ON;
lcd_SendCMD();
DATABUFB = 0x00;
DATABUFA = 0x00;
lcd_HomePointer();
lcd_DisplayXORMode();
}
//////////////////////////////////////////////////////////////////////////////////////////////////
//
//////////////////////////////////////////////////////////////////////////////////////////////////
void LCDSetAdresPointer(unsigned int lineNumber)
{
DATABUFA = lineNumber >> 8 ;
DATABUFB = lineNumber & 0x00FF ;
ADRES_HIGH = DATABUFA ;
ADRES_LOW = DATABUFB ;
lcd_HomePointer();
}
//////////////////////////////////////////////////////////////////////////////////////////////////
// LINE DRAW ROUTINES //
//////////////////////////////////////////////////////////////////////////////////////////////////
void LCDDrawHorLine(char lineShape, char lineSize)
{
char Temp = 0;
for(Temp = 0 ; Temp < lineSize;Temp++)
{
lcd_WriteGrhInc(lineShape);
}
}
//////////////////////////////////////////////////////////////////////////////////////////////////
// DRAW A VERTICAL LINE //
// LINESHAPE : SHAPE OF LINE USE PREDEFINED LINE SHAPES //
// LINE HIGHT = VERTICAL SIZE OF LINE //
// SET THE ADRES POINTER FIRST //
// //
//////////////////////////////////////////////////////////////////////////////////////////////////
void LCDDrawVerLine(char lineShape, char lineSize, char bitPosition)
{
unsigned char i;
for( i = 0; i < lineSize; i++)
{
if( lineShape & 10000000b == 10000000b)
{
lcd_WriteGrhInc(bitPosition);
}
else
{
lcd_WriteGrhInc(0x00);
}
asm movlw d'16';
asm addwf _ADRES_LOW,f;
asm btfsc STATUS,C;
asm incf _ADRES_HIGH,f;
DATABUFA = ADRES_HIGH;
DATABUFB = ADRES_LOW;
lcd_HomePointer();
asm btfsc param00_LCDDrawVerLine,7;
asm bsf STATUS,C;
asm btfss param00_LCDDrawVerLine,7;
asm bcf STATUS,C;
asm rlf param00_LCDDrawVerLine,f;
}
}
//////////////////////////////////////////////////////////////////////////////////////////////////
// CLEAR ALL TEXT RAM PAGES //
//////////////////////////////////////////////////////////////////////////////////////////////////
void LCDClearTextRAM(void)
{
LCDSetAdresPointer(0);
asm movlw D'8';
asm movwf _XCOUNT;
NXT_TXT_CLR:
asm movlw D'128';
asm movwf _YCOUNT;
NEXT_TXT_BYTE:
LCDputchar(' ') ;
asm decfsz _YCOUNT;
goto NEXT_TXT_BYTE;
asm decfsz _XCOUNT;
goto NXT_TXT_CLR;
}
//////////////////////////////////////////////////////////////////////////////////////////////////
// clear a selected textpage //
//////////////////////////////////////////////////////////////////////////////////////////////////
void LCDClearTextPage(char pageNumber)
{
switch(pageNumber)
{
case 0x01 : LCDSetAdresPointer(LINE1_PAGE1T);
break;
case 0x02 : LCDSetAdresPointer(LINE1_PAGE2T);
break;
case 0x03 : LCDSetAdresPointer(LINE1_PAGE3T);
break;
case 0x04 : LCDSetAdresPointer(LINE1_PAGE4T);
break;
case 0x05 : LCDSetAdresPointer(LINE1_PAGE5T);
break;
case 0x06 : LCDSetAdresPointer(LINE1_PAGE6T);
break;
case 0x07 : LCDSetAdresPointer(LINE1_PAGE7T);
break;
default: return;
};
asm movlw D'1';
asm movwf _XCOUNT;
NXT_TXT_PAGE_CLR:
asm movlw D'128';
asm movwf _YCOUNT;
NEXT_TXT_PAGE_BYTE:
LCDputchar(' ') ;
asm decfsz _YCOUNT;
goto NEXT_TXT_PAGE_BYTE;
asm decfsz _XCOUNT;
goto NXT_TXT_PAGE_CLR;
}
//////////////////////////////////////////////////////////////////////////////////////////////////
// CLEAR ALL GRAPHIC RAM PAGES //
//////////////////////////////////////////////////////////////////////////////////////////////////
void LCDClearGraphicRAM(void)
{
LCDSetAdresPointer(1024);
asm movlw D'56';
asm movwf _XCOUNT;
NEXT_CLR:
asm movlw D'128';
asm movwf _YCOUNT;
NEXT_BYTE:
lcd_WriteGrhInc(0x00);
asm decfsz _YCOUNT;
goto NEXT_BYTE;
asm decfsz _XCOUNT;
goto NEXT_CLR;
}
//////////////////////////////////////////////////////////////////////////////////////////////////
// clear a selected graphic page //
//////////////////////////////////////////////////////////////////////////////////////////////////
void LCDClearGraphicPage(char pageNumber)
{
switch(pageNumber)
{
case 0x01 : LCDSetAdresPointer(LINE1_PAGE1G);
break;
case 0x02 : LCDSetAdresPointer(LINE1_PAGE2G);
break;
case 0x03 : LCDSetAdresPointer(LINE1_PAGE3G);
break;
case 0x04 : LCDSetAdresPointer(LINE1_PAGE4G);
break;
case 0x05 : LCDSetAdresPointer(LINE1_PAGE5G);
break;
case 0x06 : LCDSetAdresPointer(LINE1_PAGE6G);
break;
case 0x07 : LCDSetAdresPointer(LINE1_PAGE7G);
break;
default: return;
};
asm movlw D'8';
asm movwf _XCOUNT;
NEXT_GRH_LINE_CLR:
asm movlw D'128';
asm movwf _YCOUNT;
NEXT_GRH_BYTE_CLR:
lcd_WriteGrhInc(0x00);
asm decfsz _YCOUNT;
goto NEXT_GRH_BYTE_CLR;
asm decfsz _XCOUNT;
goto NEXT_GRH_LINE_CLR;
}
//////////////////////////////////////////////////////////////////////////////////////////////////
// Set or clear pixel on a specified line //
//////////////////////////////////////////////////////////////////////////////////////////////////
void LCDSetOrClearPixel(unsigned int lineNumber, char pixelNumber, char setOrClear)
{
char pixeloffset;
pixeloffset = pixelNumber / 8;
LCDSetAdresPointer(lineNumber + pixeloffset);
pixeloffset = pixelNumber % 8;
pixeloffset = 7 - pixeloffset;
pixeloffset = pixeloffset + setOrClear;
COMMANDBUF = pixeloffset;
lcd_SendCMD();
}
//////////////////////////////////////////////////////////////////////////////////////////////////
// //
//////////////////////////////////////////////////////////////////////////////////////////////////
void LCDPortIOInit(char portAInit, char portBInit, char portCInit)
{
set_tris_a(portAInit);
set_tris_b(portBInit);
set_tris_c(portCInit);
asm bsf STATUS,RP0;
asm movlw b'10001110';
asm movwf ADCON1;
asm bcf OPTION_REG,7;
asm bcf STATUS,RP0;
asm bcf RCSTA,SPEN;
asm bcf SSPCON,SSPEN;
output_high_port_a(LCD_RD);
output_high_port_a(LCD_WR);
}
//////////////////////////////////////////////////////////////////////////////////////////////////
// Draw Square figure //
//////////////////////////////////////////////////////////////////////////////////////////////////
void LCDDrawSquare(unsigned int lineNumber, char sizeHor, char sizeVer)
{
LCDSetAdresPointer(lineNumber);
LCDDrawVerLine(11111111b,sizeVer, 10000000b);
LCDDrawHorLine(11111111b,sizeHor);
LCDSetAdresPointer(lineNumber + (sizeHor-1));
LCDDrawVerLine(11111111b,sizeVer, 00000001b);
LCDSetAdresPointer(lineNumber);
LCDDrawHorLine(11111111b,sizeHor);
}
//////////////////////////////////////////////////////////////////////////////////////////////////
// Erase a Square figure //
//////////////////////////////////////////////////////////////////////////////////////////////////
void LCDEraseSquare(unsigned int lineNumber , char sizeHor, char sizeVer)
{
LCDSetAdresPointer(lineNumber);
LCDDrawVerLine(00000000b,sizeVer, 00000000b);
LCDDrawHorLine(00000000b,sizeHor);
LCDSetAdresPointer(lineNumber + (sizeHor-1));
LCDDrawVerLine(00000000b,sizeVer, 00000000b);
LCDSetAdresPointer(lineNumber);
LCDDrawHorLine(00000000b,sizeHor);
}
//////////////////////////////////////////////////////////////////////////////////////////////////
// Increment the adrespointer one line //
//////////////////////////////////////////////////////////////////////////////////////////////////
void LCDIncAdresPoint1Line(void)
{
ADRESPOINT = ADRESPOINT + 16;
DATABUFA = ADRESPOINT >> 8 ;
DATABUFB = ADRESPOINT & 0x00FF ;
ADRES_HIGH = DATABUFA ;
ADRES_LOW = DATABUFB ;
lcd_HomePointer();
}
//////////////////////////////////////////////////////////////////////////////////////////////////
// Draw a box with rounded edges
//////////////////////////////////////////////////////////////////////////////////////////////////
void LCDDrawTextBox(unsigned int lineNumber , char sizeHor, char sizeVer)
{
char i;
int offset ;
char verify ;
verify = sizeVer - 6;
ADRESPOINT = lineNumber ;
LCDIncAdresPoint1Line();
lcd_WriteGrhNor(00011111b);
LCDIncAdresPoint1Line();
lcd_WriteGrhNor(00100000b);
LCDIncAdresPoint1Line();
lcd_WriteGrhNor(01000000b);
LCDIncAdresPoint1Line();
for(i =0 ;i < verify ;i++)
{
lcd_WriteGrhNor(10000000b);
LCDIncAdresPoint1Line();
}
lcd_WriteGrhNor(01000000b);
LCDIncAdresPoint1Line();
lcd_WriteGrhNor(00100000b);
LCDIncAdresPoint1Line();
lcd_WriteGrhNor(00011111b);
LCDIncAdresPoint1Line();
offset = 16 * sizeVer ;
ADRESPOINT = lineNumber + offset;
ADRESPOINT = ADRESPOINT - 15;
LCDIncAdresPoint1Line();
LCDDrawHorLine(11111111b,sizeHor - 2);
ADRESPOINT = lineNumber + 1;
LCDIncAdresPoint1Line();
LCDDrawHorLine(11111111b,sizeHor - 2);
ADRESPOINT = lineNumber + (sizeHor - 1);
LCDIncAdresPoint1Line();
lcd_WriteGrhNor(11111000b);
LCDIncAdresPoint1Line();
lcd_WriteGrhNor(00000100b);
LCDIncAdresPoint1Line();
lcd_WriteGrhNor(00000010b);
LCDIncAdresPoint1Line();
for(i =0 ;i < verify ;i++)
{
lcd_WriteGrhNor(00000001b);
LCDIncAdresPoint1Line();
}
lcd_WriteGrhNor(00000010b);
LCDIncAdresPoint1Line();
lcd_WriteGrhNor(00000100b);
LCDIncAdresPoint1Line();
lcd_WriteGrhNor(11111000b);
}
/////////////////////////////////////////////////////////////////////////////////////////////////
// Erase a box with rounded edges //
/////////////////////////////////////////////////////////////////////////////////////////////////
void LCDEraseTextBox(unsigned int lineNumber , char sizeHor, char sizeVer)
{
char i;
int offset ;
char verify ;
verify = sizeVer - 6;
ADRESPOINT = lineNumber ;
LCDIncAdresPoint1Line();
for(i =0 ;i < sizeVer ;i++)
{
lcd_WriteGrhNor(00000000b);
LCDIncAdresPoint1Line();
}
offset = 16 * sizeVer ;
ADRESPOINT = lineNumber + offset;
ADRESPOINT = ADRESPOINT - 15;
LCDIncAdresPoint1Line();
LCDDrawHorLine(000000000b,sizeHor - 2);
ADRESPOINT = lineNumber + 1;
LCDIncAdresPoint1Line();
LCDDrawHorLine(000000000b,sizeHor - 2);
ADRESPOINT = lineNumber + (sizeHor - 1);
LCDIncAdresPoint1Line();
for(i =0 ;i < sizeVer ;i++)
{
lcd_WriteGrhNor(00000000b);
LCDIncAdresPoint1Line();
}
}
//////////////////////////////////////////////////////////////////////////////////////////////////
// Chance LCD picture from page //
//////////////////////////////////////////////////////////////////////////////////////////////////
void LCDSelectGraphicPage(char pageNumber)
{
switch(pageNumber)
{
case 0x01 : DATABUFB = 0x00;
DATABUFA = 0x10;
lcd_GrhHomeAdres();
break;
case 0x02 : DATABUFB = 0x00;
DATABUFA = 0x14;
lcd_GrhHomeAdres();
break;
case 0x03 : DATABUFB = 0x00;
DATABUFA = 0x18;
lcd_GrhHomeAdres();
break;
case 0x04 : DATABUFB = 0x00;
DATABUFA = 0x1C;
lcd_GrhHomeAdres();
break;
case 0x05 : DATABUFB = 0x00;
DATABUFA = 0x04;
lcd_GrhHomeAdres();
break;
case 0x06 : DATABUFB = 0x00;
DATABUFA = 0x08;
lcd_GrhHomeAdres();
break;
case 0x07 : DATABUFB = 0x00;
DATABUFA = 0x0C;
lcd_GrhHomeAdres();
break;
default: DATABUFB = 0x00;
DATABUFA = 0x10;
lcd_GrhHomeAdres();
};
}
//////////////////////////////////////////////////////////////////////////////////////////////////
// Chance LCD text from page //
//////////////////////////////////////////////////////////////////////////////////////////////////
void LCDSelectTextPage(char pageNumber)
{
switch(pageNumber)
{
case 0x01 : DATABUFB = 0;
DATABUFA = 0;
lcd_TxtHomeAdres();
break;
case 0x02 : DATABUFB = 128;
DATABUFA = 0;
lcd_TxtHomeAdres();
break;
case 0x03 : DATABUFB = 0;
DATABUFA = 1;
lcd_TxtHomeAdres();
break;
case 0x04 : DATABUFB = 128;
DATABUFA = 1;
lcd_TxtHomeAdres();
break;
case 0x05 : DATABUFB = 0;
DATABUFA = 2;
lcd_TxtHomeAdres();
break;
case 0x06 : DATABUFB = 128;
DATABUFA = 2;
lcd_TxtHomeAdres();
break;
case 0x07 : DATABUFB = 0;
DATABUFA = 3;
lcd_TxtHomeAdres();
break;
case 0x08 : DATABUFB = 128;
DATABUFA = 3;
lcd_TxtHomeAdres();
break;
default: DATABUFB = 0;
DATABUFA = 0;
lcd_TxtHomeAdres();
};
}
//////////////////////////////////////////////////////////////////////////////////////////////////
// lineNumber begins from top of picture //
//////////////////////////////////////////////////////////////////////////////////////////////////
void LCDDrawVerticalBar(unsigned int lineNumber, char pixelNumber, char valueToDraw)
{
char setPixel,i,clearPixel,pixeloffset;
LINE_OFFSET = lineNumber;
setPixel = valueToDraw / VERTICAL_BAR_STEPSIZE ;
clearPixel = PIXELHIGHT - setPixel;
for( i = 0 ; i < clearPixel ; i ++ )
{
pixeloffset = pixelNumber >> 3;
pixeloffset = pixeloffset & 00011111b;
LCDSetAdresPointer(LINE_OFFSET + pixeloffset);
pixeloffset = pixelNumber & 00000111b;
pixeloffset = 7 - pixeloffset;
pixeloffset = pixeloffset + CLEARPIXEL;
COMMANDBUF = pixeloffset;
lcd_SendCMD();
LINE_OFFSET = LINE_OFFSET + 16;
}
for( i = 0 ; i < setPixel ; i ++ )
{
pixeloffset = pixelNumber >> 3;
pixeloffset = pixeloffset & 00011111b;
LCDSetAdresPointer(LINE_OFFSET + pixeloffset);
pixeloffset = pixelNumber & 00000111b;
pixeloffset = 7 - pixeloffset;
pixeloffset = pixeloffset + SETPIXEL;
COMMANDBUF = pixeloffset;
lcd_SendCMD();
LINE_OFFSET = LINE_OFFSET + 16;
}
}
//////////////////////////////////////////////////////////////////////////////////////////////////
// //
//////////////////////////////////////////////////////////////////////////////////////////////////
void LCDDrawSignalMeter(unsigned int lineNumber, char pixelNumber, char valueToDraw)
{
char j = 1;
char i,setBar,clearBar,setPixel,clearPixel,pixeloffset,y,z;
setBar = valueToDraw / SIGNAL_METER_STEPSIZE ;
clearBar = 11 - setBar;
for(i = 0 ; i < setBar; i++)
{
for( z = 0 ; z < 5; z++)
{
LINE_OFFSET = lineNumber;
setPixel = j ;
clearPixel = 11 - setPixel;
for( y = 0 ; y < clearPixel ; y ++ )
{
pixeloffset = pixelNumber >> 3;
pixeloffset = pixeloffset & 00011111b;
LCDSetAdresPointer(LINE_OFFSET + pixeloffset);
pixeloffset = pixelNumber & 00000111b;
pixeloffset = 7 - pixeloffset;
pixeloffset = pixeloffset + CLEARPIXEL;
COMMANDBUF = pixeloffset;
lcd_SendCMD();
LINE_OFFSET = LINE_OFFSET + 16;
}
for( y = 0 ; y < setPixel ; y ++ )
{
pixeloffset = pixelNumber >> 3;
pixeloffset = pixeloffset & 00011111b;
LCDSetAdresPointer(LINE_OFFSET + pixeloffset);
pixeloffset = pixelNumber & 00000111b;
pixeloffset = 7 - pixeloffset;
pixeloffset = pixeloffset + SETPIXEL;
COMMANDBUF = pixeloffset;
lcd_SendCMD();
LINE_OFFSET = LINE_OFFSET + 16;
}
pixelNumber = pixelNumber + 1;
}
j++;
if( j > 10 )
{
j = 10;
}
}
for(i = 0 ; i < clearBar; i++)
{
for( z = 0 ; z < 5; z++)
{
LINE_OFFSET = lineNumber;
for( y = 0 ; y < 12 ; y ++ )
{
pixeloffset = pixelNumber >> 3;
pixeloffset = pixeloffset & 00011111b;
LCDSetAdresPointer(LINE_OFFSET + pixeloffset);
pixeloffset = pixelNumber & 00000111b;
pixeloffset = 7 - pixeloffset;
pixeloffset = pixeloffset + CLEARPIXEL;
COMMANDBUF = pixeloffset;
lcd_SendCMD();
LINE_OFFSET = LINE_OFFSET + 16;
}
pixelNumber = pixelNumber + 1;
}
}
}
//////////////////////////////////////////////////////////////////////////////////////////////////
// all text on the display wil go off and on //
// page eight of text page must be clear // //
//////////////////////////////////////////////////////////////////////////////////////////////////
void LCDBlinkingText(int blinkOn_OffTime, char howManyBlinks,char pageNumber)
{
int i;
LCDClearTextPage(8);
for( i = 0 ; i < howManyBlinks; i++)
{
LCDSelectTextPage(0x08);
delay_ms(blinkOn_OffTime);
LCDSelectTextPage(pageNumber);
delay_ms(blinkOn_OffTime);
}
}
Copyright © 2002-2006 SourceBoost Technologies