Sign in

username:

password:



Not a member?

Search avrclub



Search tips

Subscribe to avrclub



avrclub by Keywords

AT90S2313 | AT90S8515 | ATMega | ATmega128 | ECL | FETS | IAR | Keyboard | LCD | STK50 | TMOS | UART

Ads

Discussion Groups

Discussion Groups | AVRclub | [AVR club] 16x2 CHARACTER LCD interfacing problem

Atmel AVR Microcontroller discussion group.

[AVR club] 16x2 CHARACTER LCD interfacing problem - Kurian Polachan - Mar 8 9:22:37 2008

hi,

I have written a small program for displaying hello in the 16x2 character
LCD but nothing is displayed on the LCD after loading the module please
check my code for any bugs.
*Code:*

#include
#include
#include
#define PORTA (void*)0xffe02800

#define PIO_PER 0x0000
#define PIO_PDR 0x0004
#define PIO_OER 0x0010
#define PIO_SODR 0x0030
#define PIO_CODR 0x0034

#define RS 0 //RS is PA00
#define RW 1 //RW is PA01
#define ENABLE 2 // E is PA02
#define DB0 3 //DB0 is PA03
#define DB1 4 //DB0 is PA04
#define DB2 5 //DB0 is PA05
#define DB3 6 //DB0 is PA06
#define DB4 7 //DB0 is PA07
#define DB5 8 //DB0 is PA08
#define DB6 9 //DB0 is PA09
#define DB7 21 //DB0 is PA21
//functions for setting and clearing bits
#define clrbit(x) __raw_writel( (1L<<(x)) ,PORTA + PIO_CODR )
#define setbit(x) __raw_writel( (1L<<(x)) ,PORTA + PIO_SODR )

void transferthedata (unsigned char data)
{
printk("Entered the trasnfer data function\n");
if (data & 0x01)
setbit(DB0);
else if ( ! (data & 0x01) )
clrbit(DB0);
if ( ( data >> 1 ) & 0x01 )
setbit(DB1);
else if ( !(( data >> 1 ) & 0x01) )
clrbit(DB1);
if ( ( data >> 2 ) & 0x01 )
setbit(DB2);
else if ( !(( data >> 2 ) & 0x01) )
clrbit(DB2);
if ( ( data >> 3 ) & 0x01 )
setbit(DB3);
else if ( !(( data >> 3 ) & 0x01) )
clrbit(DB3);
if ( ( data >> 4 ) & 0x01 )
setbit(DB4);
else if ( !(( data >> 4 ) & 0x01) )
clrbit(DB4);
if ( ( data >> 5 ) & 0x01 )
setbit(DB5);
else if ( !(( data >> 5 ) & 0x01) )
clrbit(DB5);
if ( ( data >> 6 ) & 0x01 )
setbit(DB6);
else if ( !(( data >> 6 ) & 0x01) )
clrbit(DB6);
if ( ( data >> 7 ) & 0x01 )
setbit(DB7);
else if ( !(( data >> 7 ) & 0x01) )
clrbit(DB7);
printk("exited the transferthedata function\n");
}

void writecommand(unsigned char data)
{
printk("Entered the writecommand function \n");
clrbit(ENABLE);
clrbit(RS);
//clrbit(RW); not needed since the RW pin is always low since its
grounded.
transferthedata(data);
setbit(ENABLE);
ndelay(1000); //1000 nano seconds delay for ENABLE pin to stay high
before its lowered
clrbit(ENABLE);
msleep(10); //10 millisecond delay for completing the execution of the
instruction
printk("exited the writecommand function \n");

}

void writedata(unsigned char data)
{

printk("Entered the writecommand function \n");
clrbit(ENABLE);
setbit(RS);
//clrbit(RW); not needed since the RW pin is always low since its
grounded.
transferthedata(data);
setbit(ENABLE);
ndelay(1000); //1000 nano seconds delay for ENABLE pin to stay high
before its lowered
clrbit(ENABLE);
msleep(10); //10 millisecond delay for completing the execution of the
instruction
printk("exited the writecommand function \n");

}

void lcdinitialization(void)
{
msleep(1000); // 1 second delay
printk("entered the initialization function \n");

writecommand(0x38); //8 bit mode , 5x8 dot character font , two line
display
writecommand(0x0e); //turn lcd on and cursor on
writecommand(0x06); //used to automatically move the cursor right
writecommand(0x01); //clearing the display
printk("finished lcd initialization");
}

int init_module(void)
{

printk("hello the module is loaded\n");
__raw_writel( ((1L << RS) | (1L << RW) | (1L << ENABLE) | (1L <<
DB0) | (1L << DB1) | (1L << DB2) | (1L << DB3) | (1L << DB4) | (1L << DB5) |
(1L << DB6) | (1L << DB7) ), PORTA + PIO_PER);

__raw_writel( ((1L << RS) | (1L << RW) | (1L << ENABLE) | (1L << DB0) |
(1L << DB1) | (1L << DB2) | (1L << DB3) | (1L << DB4) | (1L << DB5) | (1L <<
DB6) | (1L << DB7) ), PORTA + PIO_OER);
__raw_writel( ((1L << RS) | (1L << RW) | (1L << ENABLE) | (1L << DB0) |
(1L << DB1) | (1L << DB2) | (1L << DB3) | (1L << DB4) | (1L << DB5) | (1L <<
DB6) | (1L << DB7) ), PORTA + PIO_CODR);

lcdinitialization();
//displaying hello in the lcd
writedata('H');
writedata('E');
writedata('L');
writedata('L');
writedata('O');

return 0;

}
void cleanup_module(void)
{
printk("Module unloaded sucessfully\n");
}

Wiring Information

GND of LCD connected to pin 2 of jumper 5
RS of LCD connected to pin 3 of jumper 5
RW grounded
E of LCD connected to pin 5 of jumper 5
DB0 of LCD connected to pin 6 of jumper 5

"""""""""""
"""""""""""

DB7 of LCD connected to pin 13 of jumper 5
[Non-text portions of this message have been removed]



(You need to be a member of avrclub -- send a blank email to avrclub-subscribe@yahoogroups.com )