240x128 LCD T6963 controller driver (C51)

Publisher:艺泉阁Latest update time:2021-03-22 Source: eefocus Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

Introduction: This article mainly introduces the 240x128 LCD T6963 controller driver (C51).


#include "absacc.h"

#include "math.h"



#include "ASCII816.h" //Standard ASCII library

#include "HZTable.h" //Chinese character dot matrix library (self-made)

#include "menu.h" //Menu library (self-made)


#define ComPort 0xB101

#define DataPort 0xB000

#define GraphAddr 0x0000 //head of graph


//Calculated based on 8*8 characters, the number of characters that can be displayed horizontally and vertically on the display

//Take 240*128 as an example:

#define LineChar 30 //16 characters per line (8*8)

#define ColumnChar 16 //Total 16 columns



//Instructions, data read and write status check

#define RWCheck() { unsigned char sta; do{ sta=XBYTE[ComPort] & 0x03; } while(sta!=0x03); }

//Data automatic read status check

#define AutoRCheck() { unsigned char sta; do{ sta=XBYTE[ComPort] & 0x04; } while(sta!=0x04); }

//Data automatic write status check

#define AutoWCheck() { unsigned char sta; do{ sta=XBYTE[ComPort] & 0x08; } while(sta!=0x08); }


/*------Input/output function, communication with T6963------------------------------------------------*/

/*------------------------------------------------------------------------*/


// Send Data to the data port

#define OutPortData(dat ) { RWCheck(); XBYTE[DataPort]=that; }


//Write a command with 1 parameter

#define OutPortCom1(command) { RWCheck(); XBYTE[ComPort]= command; }


//Write a command with 2 parameters

#define OutPortCom2(dat, command) { OutPortData(dat); OutPortCom1(command); }


//Write a command with 3 parameters

#define OutPortCom3(data1, data2, command) { OutPortData(data1); OutPortData(data2); OutPortCom1(command);}



unsigned char InPortData() { RWCheck(); return(XBYTE[DataPort]); }


/*-----------------------------------------------------------------------------------*/

//Display 8*16 characters

//lin: row (0-7), column: column (0-15)

//ch: character code (standard ASCII code)

void ShowChar(unsigned char lin,unsigned char column,unsigned char ch)

{

unsigned char i;

unsigned char dat;

unsigned int StartAddr;


StartAddr=lin*LineChar +column; //Locate the starting line


for(i=0;i<16;i++)

{

dat=ASCII816[ ch-0x20 ][i];

OutPortCom3( (unsigned char)(StartAddr), (unsigned char)(StartAddr>>8), 0x24); //set address

OutPortCom2( dat, 0xc4);


StartAddr=StartAddr + LineChar;

}

}


/*----------------------------------------------------------------------------------------------*/

//Display a Chinese character (16*16 dot matrix)

//lin: row (0-7), column: column (0-7)

//hzcode: Chinese character code (customized)

void ShowHZ(unsigned char lin,unsigned char column,unsigned int hzcode)

{

unsigned char i;

unsigned int StartAddr;


StartAddr=lin*LineChar + column; //Locate the starting line


for(i=0;i<16;i++)

{

OutPortCom3( (unsigned char)(StartAddr), (unsigned char)(StartAddr>>8), 0x24);

OutPortCom2( HZTable[hzcode][i*2], 0xc0); //Add one to the left half of the address

OutPortCom2( HZTable[hzcode][i*2+1], 0xc4); //add one to the right half of the font address


StartAddr=StartAddr + LineChar;

}

}

/////////////////////////////////////////////////////////////////////////////////////////////

//Display a Chinese character (16*16 dot matrix)

//lin: row (0-7), column: column (0-7)

//hzcode: Chinese character code (customized)

void ShowHZD(unsigned char lin,unsigned char column,unsigned int hzcode)

{

unsigned char i,j;

unsigned int StartAddr;


StartAddr=lin*LineChar*16 +column; //Locate the starting line


for(i=0;i<35;i++)

{

OutPortCom3( (unsigned char)(StartAddr), (unsigned char)(StartAddr>>8), 0x24); //Locate the current operation position

for(j=0;j<5;j++) OutPortCom2( HZTable[hzcode][i*5+j], 0xc0); //Display the current line


StartAddr=StartAddr + LineChar;

}

}


////////////////////////////////////////////////////////////////////////////////////////////

/*-----------------------------------------------------------------------------------*/

//Display a line of string (Chinese characters, letters mixed, 16 bytes per line)

//lin: line

//lineheadaddr: the first address of the Chinese character code area in this line

void ShowLine(unsigned char lin,unsigned char column,unsigned char linehead[])

{

unsigned char i,j;

unsigned char byte;

unsigned int hzcode;


for( i= column,j=0; i< column+14 ; )

{ byte=linehead[j];

if(byte < 0x80) //letter

{

ShowChar(lin, i , byte);

i=i+1;j=j+1;

}

else // byte >= 0x80 (Chinese character)

{

byte=byte & 0x7f; //The highest position is 0, that is: minus 0x8000

hzcode=byte*256 + linehead[j+1]; //Add the lower 8 bits to form an integer address

ShowHZ( lin,i,hzcode);

i=i+2;j=j+2;

}

}

}


/*-----------------------------------------------------------------------------------*/

//Display a screen of Chinese characters

//pageheadaddr: the first address of the Chinese character code address area on this screen

void ShowPage(unsigned char lin,unsigned char column1,unsigned char pagehead[][14])

{

unsigned char i;

for(i=0;i< 4 ;i++)

ShowLine((lin+i*20),column1,pagehead[i]); //1 line of 8 Chinese characters, 16 bytes

}


/*----------------------------------------------------------------------------------------------------*/

//Reverse display a character

//lin: row (0-7), column: column (0-15)

void ReverseShowChar(unsigned char lin,unsigned char column)

{

unsigned char i;

unsigned char dat;

unsigned int StartAddr;


StartAddr=lin*LineChar +column; //Locate the starting line


for(i=0;i<16;i++)

{

OutPortCom3( (unsigned char)(StartAddr), (unsigned char)(StartAddr>>8), 0x24); //set address

OutPortCom1( 0xc5 ); //Read data once, address remains unchanged

dat=InPortData(); //Read data

that=~that; //取反

OutPortCom2(dat, 0xc4); //Send back


StartAddr=StartAddr+ LineChar;

}

}



/*----------------------------------------------------------------------------------------------------*/

//Reverse display a Chinese character

//lin: row (0-7), column: column (0-15)

void ReverseShowHZ(unsigned char lin,unsigned char column)

{

ReverseShowChar(lin,column);

ReverseShowChar(lin,column+1);

}

/*----------------------------------------------------------------------------------------------------*/

//Reverse display of a line of Chinese characters

//lin: row (0-7)

void ReverseShowLine(unsigned char lin)

{

unsigned char column;

for(column=0; column< ColumnChar; column++) ReverseShowChar(lin,column);

}



//////////////////////////////////////////////////////////////////////////////////////

void ShowPicture(unsigned char Startline,unsigned char Startcolumn,unsigned char LineWidth,unsigned char ColumnWidth,unsigned int address)

{

unsigned char i,j;

unsigned int StartAddr;


StartAddr=Startline*LineChar + Startcolumn; //Locate the starting position


for(i=0;i{


OutPortCom3( (unsigned char)(StartAddr), (unsigned char)(StartAddr>>8), 0x24); //set address

for(j=0;j{

OutPortCom2( CBYTE[address + i*LineWidth+ j ], 0xc0);

}

StartAddr=StartAddr + LineChar;

}

}


////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

/////////////////////////////////////////////////////////////////////////////

//Graphics function, used to draw points

//---------------------------------------------------------------------------

// Display a point at the specified position

//If the display exceeds 256*256, please modify the type of this function PointX, PointY

//Mode 1: Display 0: Clear the point

Pixel(unsigned char PointX,unsigned char PointY, bit Mode)

{

unsigned int StartAddr=0;

unsigned char dat;


StartAddr=PointX*LineChar + PointY/8;

dat=0xf0+7-PointY%8;

if(Mode) dat=dat|0x08;


OutPortCom3( (unsigned char)(StartAddr),(unsigned char)(StartAddr>>8),0x24 ); //Set the unit address of this point

OutPortCom1(dat);

}


//-------------------------------------------------------------------------------

//Strikethrough function

void Line( unsigned char x1, unsigned char y1, unsigned char x2, unsigned char y2, bit Mode)

{

unsigned char x,y;

double k,b;


if( abs(y1-y2) <= abs(x1-x2) ) // |k|<=1

{

k=(float)(y2-y1) / (float)(x2-x1) ;

b=y1-k*x1;


if( x1 <= x2 )

{

for(x=x1;x<=x2;x++)

{

y=k*x+b;

Pixel(x, y, Mode);

}

}

else

{

for(x=x2;x<=x1;x++)

{ y=k*x+b;

Pixel(x, y, Mode);

}

}

}

else // abs(y1-y2) > abs(x1-x2) |K|>1

{

k=(float)(x2-x1) / (float)(y2-y1) ;

b=x1-k*y1;


if( y1 <= y2 )

{

for(y=y1;y<=y2;y++)

{ x=k*y+b;

Pixel( x , y,Mode );

}

}

else

{

for(y=y2;y<=y1;y++)

{ x=k*y+b;

Pixel( x , y,Mode );

}

}

}

}




/*---------------------------------------------------------------------------------------------------*/

void ClearScreen()

{


unsigned int i;

///////// Clear display RAM area 0000h--2000h (8k)

OutPortCom3(0x00,0x00,0x24); //Set pointer address to 0000H


OutPortCom1(0xb0); //Set automatic write status

for(i=0x00;i<0x2000;i++) OutPortData(0x00); // data=0;

OutPortCom1(0xb2); // Automatic write end

}


// Initialize LCD

// Need to set manually

void InitLCD()

{

OutPortCom3( 0x00,0x00,0x42 ); //Set the first address of the graphics display area GraphAddr

OutPortCom3( 30,0x00,0x43 ); //Set the width of the graphics display area: LineChar


// OutPortCom3( 0x00,0x00,0x42 ); //Set the first address of the graphics display area GraphAddr

// OutPortCom3(0x10,0x00,0x43); //Set the width of the graphics display area: 10H


OutPortCom1(0xa7); //Set cursor shape cursor size 8x8

OutPortCom1(0x80); //Set the display mode: CGROM mode text graphics "or"

OutPortCom1(0x98); //Set display switch: 1001 1100 graphics


ClearScreen();

}


Reference address:240x128 LCD T6963 controller driver (C51)

Previous article:A brief discussion on the debounce problem of single-chip microcomputer buttons
Next article:Flowing water lamp made with timer

Recommended ReadingLatest update time:2024-11-16 14:44

Data types of single chip microcomputer C language C51
The data types of C51 are divided into basic data types and combined data types, which are basically the same as the data types in standard C, but the char type is the same as the short type, and the float type is the same as the double type. In addition, C51 also has special function register types and bit types spec
[Microcontroller]
Data types of single chip microcomputer C language C51
Analysis and study of mini2440 I2C driver (Part 3)
Finally, let’s talk about the relationship between i2c and smbus. First, the SMBus protocol is introduced in detail in a link: http://www.mjmwired.net/kernel/Documentation/i2c/smbus-protocol. My general understanding is that i2c is a subset of smbus, which means that all devices that support i2c should support the
[Microcontroller]
Analysis of the servo program using 51 single-chip microcomputer
A servo, also known as a servo motor, is an electromechanical structure with a closed-loop control system. A servo is mainly composed of a housing, a circuit board, a coreless motor, gears, and a position detector. Its working principle is that the controller sends a PWM (pulse width modulation) signal to the servo, w
[Microcontroller]
Linear high voltage LED drive solutions and their development trends
  According to the load characteristics of LED , a controllable constant current source is needed to control it. If the rectified AC voltage is directly added to the output LED, the problem is that constant current cannot be achieved, that is, the current passing through the LED is not constant during the entire power
[Power Management]
Linear high voltage LED drive solutions and their development trends
Design of high power factor driver for LED lamp (Part 1)
With the application of LED lights in many fields, such as commercial lighting and home lighting, LED lighting has completely replaced traditional incandescent lamps and fluorescent lamps. Compared with traditional lighting, LED lighting is more expensive, but it has significant advantages such as energy saving, high
[Power Management]
Design of high power factor driver for LED lamp (Part 1)
5W dimmable LED driver design with power factor correction
1. Circuit Features Description RD-251 provides 350 mA single-channel constant current output at 12 V and 18 V LED lamp string voltages. Using a standard AC mains thyristor dimmer, the output current can be reduced to 1% (3 mA), which will not cause unstable LED load performan
[Power Management]
5W dimmable LED driver design with power factor correction
Inventory of excellent LED driver ICs in power supply design
The figure below is a good PFC circuit that can be used in high-power street lamps or lamps. ZXLD1350 has received very good market response and is compact and suitable for spotlight products. This IC was originally designed for automotive LED applications. I think it is most suitable for spotlights. Its small
[Power Management]
Inventory of excellent LED driver ICs in power supply design
Nissan GT-R's core technology! Analysis of the Atesa E-TS four-wheel drive control system
Not only the GT-R , but many high-power models use 4WD for a simple reason. In order to make the car run faster, the excess power is distributed to the four wheels to ensure that the driving force can be efficiently transmitted regardless of the road conditions. In addition, the four wheels are
[Automotive Electronics]
Nissan GT-R's core technology! Analysis of the Atesa E-TS four-wheel drive control system
Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号