Professional Documents
Culture Documents
image.
There are two kinds of modes for this LCD .command mode and data mode.
In order to send commands to the LCD, the LCD must be configured like this.
->The CS pin must be low, this selects the chip [negative logic]
->Send the serial data[command], the following snippet of code shows how this can be done
char caa;
for (caa=8;caa>0;caa--)
lcd_sclk(0);
lcd_sdata(0);
else
lcd_sdata(1);
lcd_sclk(1);
}
To configure the LCD in data mode the D/C pin must be set high [indicates data mode] and the rest
remains same as the Command mode configurations.
' $ % (
You can get a better view and more information in the datasheet
Here the number of pages are 8 and each page has 8 rows [D0,D1,D2,…,D7] in total 64 rows, when we
send data we need to first set the page address and send the data byte.
The columns are indicated at the bottom as SEG00..SEG83 [in HEX] , the column addresses can be
reversed using ADC, 0 indicates normal order while 1 indicates a descending order
You can even read the display data from the LCD using COM outputs, read more in the datasheet.
! & $ '
The following code shows how to a set pixel.
char x,y;
if (lcd_row>64) return;
x=lcd_row/8;
y=1<<(lcd_row % 8);
// VidRAM[x][lcd_col]=0;
lcd_write_data(VidRAM[x][lcd_col]);
$ & "
Suppose u want to set a pixel at (50,2) i.e 50th row and 2nd column
Note the column address will be 18+2 [since starting column address starts from 0x12 ]
Now x = 50/8 = 6
x = 53/8 = 6 still
since VidRAM[6][2] has 00000010 data in it, this will be ORed with it
Therefore this function can be used to set a single pixel or a column of 8 bits in a page, this will be helpful
when we type a different font the LCD.
It will convert the color pixel value into a binary 1 or 0 depending upon the threshold you set for it and
combine the 8 sequential pixel values into a 8 bit data which are stored in a character array, so we need
to display the data horizontally. . .
int main(void)
char i,j,b,k;
t=img;
mcu_init();
lcd_init();
lcd_cls();
for(i=0;i<64;i++)
for(j=18;j<114;j++)
for(b=0;b<8;b++)
if( ((*t)<<b&(0x80)) == 0 )
lcd_clrpixel(i,j++);
else
lcd_setpixel(i,j++);
j--;
t++;
The LCD image data is stored in img[ ] array this is pointed by pointer t, this part of the code
for(b=0;b<8;b++)
if( ((*t)<<b&(0x80)) == 0 )
lcd_clrpixel(i,j++);
else
lcd_setpixel(i,j++);
will display the data by setting the sequential pixels in a row , next we increment t value by 1 to point to
next byte of data.
The outer for loop for(j=18;j<114;j++){. . .} [114-18 = 96]will keep the above process until
all the 96 pixels in a row are exhausted, after this loop breaks the final external loop
for(i=0;i<64;i++) will increment the row value to next, this will continue until all the rows are filled.
[we need to observe the value of j here when 8 bit display breaks j value increments twice to reduce it I
subtracted the j value once every time the inner loop breaks]
#include <LPC21xx.h>
//////////////////////////////////////////////////
////////////////////////////////////////////////
#define res 0
#define sdata 1
#define led 2
#define sclk 3
#define dc 4
#define cs 5
// display attributes
/**********************************************************
LCD Commands
**********************************************************/
#define pow_ctrl 0x20 // (16) power control set value (contrast level --> 0x00
lightest to 0x3F darkest), from 0b00101000 to 0b00101111.
#define v5_ratio 0x22 //(17) V5 resistor ratio, from 0b00100000 to 0b00100111. need to
add some ratio
#define start_line 0x40 // start line - set the display line start address.
#define lcd_all_on 0xA5 //lcd all points on - turn on all pixels. 0xA4: normal
display.
#define lcd_1st_col 0x12 //first displayable column. datasheet didn't mention this.
WEIRD!
/**********************************************************
Global Variable
**********************************************************/
char page;
char VidRAM[8][COL_RES];
/**********************************************************
Function Prototype
**********************************************************/
void lcd_reset(void);
void lcd_cls(void);
void lcd_init(void);
void mcu_init(void);
void DelayUs(int);
void DelayMs(int);
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xBF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF,
0xFF, 0xFC, 0x1F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xF3,
0xE3, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xE7, 0xF3, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xDF, 0xFC, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF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0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF};
/********************************************************
********************************************************/
void lcd_cls(void) {
char x, y;
for (page=0; page<9; page++) // 9 page, fill display RAM with 0s.
lcd_write_data(0x00);
/**********************************************************
**********************************************************/
void lcd_reset(void) {
lcd_cs(1);
DelayMs(10);
lcd_res(0);
DelayMs(10);
lcd_res(1);
DelayMs(100);
/**********************************************************
**********************************************************/
void lcd_init(void) {
lcd_reset();
lcd_cls();
// lcd_write_command(lcd_on); // lcd on
/**********************************************************
**********************************************************/
char caa;
for (caa=8;caa>0;caa--)
lcd_sclk(0);
lcd_sdata(0);
else
lcd_sdata(1);
lcd_sclk(1);
}
}
/**********************************************************
**********************************************************/
lcd_dc(0);
lcd_cs(0);
lcd_write_dorc(byteforlcd_command);
lcd_cs(1);
/**********************************************************
**********************************************************/
lcd_dc(1);
lcd_cs(0);
lcd_write_dorc(byteforlcd_data);
lcd_cs(1);
/**********************************************************
**********************************************************/
char x,y;
if (lcd_row>64) return;
if (lcd_col>0x72) return; //check for illegal addresses
x=lcd_row/8;
y=1<<(lcd_row % 8);
// VidRAM[x][lcd_col]=0;
lcd_write_data(VidRAM[x][lcd_col]);
/**********************************************************
**********************************************************/
if (lcd_row>64) return;
x=lcd_row/8;
y=1<<(lcd_row % 8);
lcd_write_data(VidRAM[x][lcd_col]);
/**********************************************************
delay routines
***********************************************************/
DelayUs(1000);
void mcu_init(void) {
PINSEL0=0x00;
IODIR0=0xff;
/*****************************************************************
Main Progarm
*****************************************************************/
int main(void)
char i,j,b,k;
t=img;
mcu_init();
lcd_init();
lcd_cls();
for(i=0;i<64;i++)
for(j=18;j<114;j++)
for(b=0;b<8;b++)
if( ((*t)<<b&(0x80)) == 0 )
lcd_clrpixel(i,j++);
else
lcd_setpixel(i,j++);
j--;
t++;