lpc213xx and nokia7110

17
In this tutorial we are going to interface ARM with NOKIA7110 graphic LCD and display a lcd pattern of a image. The drivers we are using is SED1565 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 D/C pin must be low [Indicates command mode] ->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 void lcd_write_dorc(char byteforlcd) { char caa; for (caa=8;caa>0;caa--) { lcd_sclk(0); if ((byteforlcd&0x80)==0) // tramission starts from D7, D6, .., D1, D0. if D7 is 0, send 0. { lcd_sdata(0); } else { lcd_sdata(1); } lcd_sclk(1); byteforlcd=byteforlcd<<1; //shift left the next bit. } }

Upload: hypernuclide

Post on 27-Apr-2015

260 views

Category:

Documents


0 download

DESCRIPTION

A tutorial on displaying a image in NOKIA7110 with ARM

TRANSCRIPT

Page 1: Lpc213xx and Nokia7110

���������� ������� ����

In this tutorial we are going to interface ARM with NOKIA7110 graphic LCD and display a lcd pattern of a

image.

The drivers we are using is SED1565

�������� �������� �� �

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 D/C pin must be low [Indicates command mode]

->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

void lcd_write_dorc(char byteforlcd) {

char caa;

for (caa=8;caa>0;caa--)

{

lcd_sclk(0);

if ((byteforlcd&0x80)==0) // tramission starts from D7, D6, .., D1, D0. if D7 is

0, send 0.

{

lcd_sdata(0);

}

else

{

lcd_sdata(1);

}

lcd_sclk(1);

byteforlcd=byteforlcd<<1; //shift left the next bit.

}

}

Page 2: Lpc213xx and Nokia7110

���������

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.

!�"��������#���������$� %��&������ � ����������' �

����������� ��������������������������������������� ������������������������������� ��������������������������������������� ������������������������������� ��������������������������������������� ������������������������������� ��������������������������������������� ��������������������

����������������������������������������������������������������������������������������������������������������������������������������������������������������������������

'��$� %����������(�� �

Page 3: Lpc213xx and Nokia7110

You can get a better view and more information in the datasheet

The row address is the format (No. pages)x(8 rows)

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.

void lcd_setpixel(char lcd_row, char lcd_col) { //row: 0 - 63, col: 0-95

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;

VidRAM[x][lcd_col] |= y; //set the bit;

lcd_write_command(0xB0 + x); // page address set. pg 8-48 in the datasheet.

lcd_write_command(0x10 | (lcd_col>>4)); // column address 4 most bit set

lcd_write_command(0x0f & lcd_col); // column address 4 least bit set

lcd_write_data(VidRAM[x][lcd_col]);

}

������� �������$��&� " �

Suppose u want to set a pixel at (50,2) i.e 50th row and 2

nd column

Note the column address will be 18+2 [since starting column address starts from 0x12 ]

Now x = 50/8 = 6

Here x will give us the page address and

y = 1<<(50%8) = 1<<2 = 00000010

and since VidRAM[ ][ ] array is initially installed to 0

Page 4: Lpc213xx and Nokia7110

VidRAM[6][2] = 00000010

Now if u want to set the at (53,2)

x = 53/8 = 6 still

but y = 1<<(53%8) = 1<<5 = 00010000

since VidRAM[6][2] has 00000010 data in it, this will be ORed with it

so VidRAM[6][2]= 00010000 | 00000010 = 00010010

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.

And similarly we can clear the pixel.

���)�����&� ��" &�����*�#�����'�� � � ������$� %��&��� �

There are many free software’s available to do this, the program I used for this is Image2GLCD.

This and other LCD tools are available here http://www.hypernuclide.com/bbs/viewtopic.php?f=7&t=208

The Image2GLCD tool will generate output in the following manner:

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;

const unsigned char *t;

t=img;

mcu_init();

lcd_init();

lcd_cls();

Page 5: Lpc213xx and Nokia7110

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]

Page 6: Lpc213xx and Nokia7110

�������� �

#include <LPC21xx.h>

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

/// Visit http://www.hypernuclide.com/bbs ///

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

#define res 0

#define sdata 1

#define led 2

#define sclk 3

#define dc 4

#define cs 5

#define lcd_res(x) (x)?(IOSET0=1<<res):(IOCLR0=1<<res);

#define lcd_sdata(x) (x)?(IOSET0=1<<sdata):(IOCLR0=1<<sdata);

#define lcd_led(x) (x)?(IOSET0=1<<led):(IOCLR0=1<<led);

#define lcd_sclk(x) (x)?(IOSET0=1<<sclk):(IOCLR0=1<<sclk);

#define lcd_dc(x) (x)?(IOSET0=1<<dc):(IOCLR0=1<<dc);

#define lcd_cs(x) (x)?(IOSET0=1<<cs):(IOCLR0=1<<cs);

// display attributes

#define NORMAL 0x00 // normal black on green

#define UNDERLINE 0x80

#define STRIKE 0x10

#define OVERLINE 0x01

#define REVERSE 0xff //green on black

#define negative_lcd lcd_write_command(lcd_reverse)

Page 7: Lpc213xx and Nokia7110

#define normal_lcd lcd_write_command(lcd_normal)

/**********************************************************

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 elec_vol 0x81 // (18) electronic volume mode

#define adc_normal 0xA0 // (8) <ADC select> (0xA1/0b10100001 reverse lcd -

0xA0/0b10100000 select normal)

#define adc_reverse 0xA1

#define lcd_bias_1_over_9 0xA2 // (11) lcd bias (1/9 0xA2/0b10100010 - 1/7

0xA3/0b10100011)

#define lcd_bias_1_over_7 0xA3

#define lcd_all_off 0xA4 //turn all pixels off

#define lcd_all_on 0xA5 //lcd all points on - turn on all pixels. 0xA4: normal

display.

#define lcd_normal 0xA6 // 0b10100110 = 0xA6, lcd in normal display mode

(0xA7/0b10100111 negative mode)

#define lcd_reverse 0xA7

#define lcd_off 0xAE //

#define lcd_on 0xAF // lcd on - display on. 0xAE: display off.

#define comm_normal 0xC0 // (15) common output normal (0xC8 reverse)

#define comm_reverse 0xC8

#define lcd_nop 0xE3 // nop (command for no-operation, 0b11100011.

#define lcd_1st_col 0x12 //first displayable column. datasheet didn't mention this.

WEIRD!

#define ROW_RES 64 //max row resolution

#define COL_RES 132 //max col resolution

/**********************************************************

Page 8: Lpc213xx and Nokia7110

Global Variable

**********************************************************/

char page;

char VidRAM[8][COL_RES];

/**********************************************************

Function Prototype

**********************************************************/

void lcd_write_dorc(char byteforlcd);

void lcd_write_command(char byteforlcd_command);

void lcd_write_data(char byteforlcd_data);

void lcd_setpixel(char lcd_row, char lcd_col);

void lcd_clrpixel(char lcd_row, char lcd_col);

void lcd_reset(void);

void lcd_cls(void);

void lcd_init(void);

void mcu_init(void);

void DelayUs(int);

void DelayMs(int);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F, 0xFF, 0xFF, 0xFF, 0x78,

0x70, 0x04,

0x04, 0x19, 0xE9, 0xDC, 0x1B, 0xE4, 0x1C, 0x0F, 0xFF, 0x79, 0x24, 0x74, 0xFD, 0xC9,

0xE9, 0xDD,

0xDB, 0xE5, 0xC4, 0xFF, 0xFF, 0x01, 0x8C, 0x04, 0x04, 0x1A, 0x29, 0xD9, 0xFB, 0xE5,

0xE4, 0x0F,

Page 11: Lpc213xx and Nokia7110

0xFF, 0x79, 0xDC, 0x3C, 0xFD, 0x9B, 0x89, 0xD9, 0xFB, 0xE5, 0xE4, 0xFF, 0xFF, 0x79,

0xDC, 0x7C,

0x05, 0xEB, 0xCC, 0x1C, 0x18, 0x24, 0x1C, 0x0F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,

0xFF, 0xFF,

0x7F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,

0xFF, 0xFF};

/********************************************************

lcd clear LCD function

********************************************************/

void lcd_cls(void) {

char x, y;

for (page=0; page<9; page++) // 9 page, fill display RAM with 0s.

{

lcd_write_command(0xB0 | page); // page address ie:0xB0,0xB1,...,0xB7

lcd_write_command(0x11); // 0x11, most 4 bit column address command

0001 0011

lcd_write_command(0x01); // 0x02, least 4 bit column address command

0000 0011

for (x=96; x>0; x--) { // 96 column

lcd_write_data(0x00);

for (y=0; y<8; y++)

VidRAM[y][x]=0; //initialize the video ram

}

}

}

/**********************************************************

Reset LCD Function

**********************************************************/

void lcd_reset(void) {

lcd_cs(1);

DelayMs(10);

Page 12: Lpc213xx and Nokia7110

lcd_res(0);

DelayMs(10);

lcd_res(1);

DelayMs(100);

}

/**********************************************************

Initial LCD Function

**********************************************************/

void lcd_init(void) {

lcd_reset();

// the following initialization sequence per datasheet. All needs to be done in

5ms. (X) where X is the command on pg 8-56 of datasheet

lcd_write_command(lcd_normal); // 0b10100110 = 0xA6, lcd in normal display mode

(0xA7/0b10100111 negative mode)

lcd_write_command(lcd_bias_1_over_7); // (11) lcd bias (1/9 0xA2/0b10100010 - 1/7

0xA3/0b10100011)

lcd_write_command(adc_reverse); // (8) <ADC select> (0xA1/0b10100001 reverse lcd -

0xA0/0b10100000 select normal)

lcd_write_command(comm_normal); // (15) common output normal (0xC8 reverse)

lcd_write_command(v5_ratio+2); // (17) V5 resistor ratio, from 0b00100000 to

0b00100111

lcd_write_command(elec_vol); // (18) electronic volume mode

lcd_write_command(pow_ctrl+0x0E); // (16) power control set value (contrast level -

-> 0x00 lightest to 0x3F darkest), from 0b00101000 to 0b00101111.

//this concludes the mandatory initialization, as specified on pg 8-56 of the

datasheet

lcd_write_command(0x2F); // power control set value, from 0b00101000 to 0b00101111.

see pg 8-52 of datasheet.

lcd_write_command(lcd_nop); // nop (command for no-operation, 0b11100011.

lcd_write_command(0x40); // start line - set the display line start address.

lcd_write_command(lcd_on); // lcd on - display on. 0xAE: display off.

// lcd_write_command(lcd_all_on); // lcd all points on - turn on all pixels. 0xA4:

normal display.

Page 13: Lpc213xx and Nokia7110

DelayMs(50);

// lcd_write_command(lcd_off); // lcd off - turn display off.

lcd_cls();

// lcd_write_command(lcd_on); // lcd on

// lcd_write_command(lcd_all_off); // lcd normal display mode

}

/**********************************************************

sent 8 bit data to LCD by series

**********************************************************/

void lcd_write_dorc(char byteforlcd) { // same lcdai 3310

char caa;

for (caa=8;caa>0;caa--)

{

lcd_sclk(0);

if ((byteforlcd&0x80)==0) // tramission starts from D7, D6, .., D1, D0. if D7 is

0, send 0.

{

lcd_sdata(0);

}

else

{

lcd_sdata(1);

}

lcd_sclk(1);

byteforlcd=byteforlcd<<1; //shift left the next bit.

}

Page 14: Lpc213xx and Nokia7110

}

/**********************************************************

Sent Command to LCD Function

**********************************************************/

void lcd_write_command(char byteforlcd_command) {

lcd_dc(0);

lcd_cs(0);

lcd_write_dorc(byteforlcd_command);

lcd_cs(1);

}

/**********************************************************

Sent Data to LCD Function

**********************************************************/

void lcd_write_data(char byteforlcd_data) {

lcd_dc(1);

lcd_cs(0);

lcd_write_dorc(byteforlcd_data);

lcd_cs(1);

}

/**********************************************************

set pixel at lcd_row and lcd_col

**********************************************************/

void lcd_setpixel(char lcd_row, char lcd_col) { //row: 0 - 63, col: 0-131

char x,y;

if (lcd_row>64) return;

Page 15: Lpc213xx and Nokia7110

if (lcd_col>0x72) return; //check for illegal addresses

x=lcd_row/8;

y=1<<(lcd_row % 8);

// VidRAM[x][lcd_col]=0;

VidRAM[x][lcd_col] |= y; //set the bit;

lcd_write_command(0xB0 + x); // page address set. pg 8-48 in the datasheet.

lcd_write_command(0x10 | (lcd_col>>4)); // column address 4 most bit set

lcd_write_command(0x0f & lcd_col); // column address 4 least bit set

lcd_write_data(VidRAM[x][lcd_col]);

}

/**********************************************************

clear pixel at lcd_row and lcd_col

**********************************************************/

void lcd_clrpixel(char lcd_row, char lcd_col) { //row: 0 - 63, col: 0-131

char x=lcd_row/8,y=1<<(lcd_row % 8);

if (lcd_row>64) return;

if (lcd_col>0x83) return; //check for illegal addresses

x=lcd_row/8;

y=1<<(lcd_row % 8);

VidRAM[x][lcd_col] &= (~y); //set the bit;

lcd_write_command(0xB0 + x); // page address set. pg 8-48 in the datasheet.

lcd_write_command(0x10 | (lcd_col>>4)); // column address 4 most bit set

lcd_write_command(0x0f & lcd_col); // column address 4 least bit set

lcd_write_data(VidRAM[x][lcd_col]);

}

/**********************************************************

Page 16: Lpc213xx and Nokia7110

delay routines

***********************************************************/

void DelayUs(int us) {

for (; us>0; us--);

}

void DelayMs(int ms) {

for (; ms>0; ms--)

DelayUs(1000);

}

void mcu_init(void) {

PINSEL0=0x00;

IODIR0=0xff;

}

/*****************************************************************

Main Progarm

*****************************************************************/

int main(void)

{

char i,j,b,k;

const unsigned char *t;

t=img;

mcu_init();

lcd_init();

lcd_cls();

Page 17: Lpc213xx and Nokia7110

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++;

}

}

}

Get the Proteus and Keil simulation here :

http://www.hypernuclide.com/bbs/viewtopic.php?f=30&t=209

Register at http://www.hypernuclide.com/bbs