Arduino Projects   |   Raspberry Pi   |   Electronic Circuits   |   AVR   |   PIC   |   8051   |   Electronic Projects

Lcd interfacing with Attiny Microcontroller

4 posts / 0 new
Last post
Chetan Patil
Chetan Patil's picture
Offline
Last seen: 8 years 11 months ago
Joined: 20/08/2010 - 11:04
Lcd interfacing with Attiny Microcontroller

Hi all. This is my first post an im beginner.

Im interfacing Attiny 2313 with 16*2 lcd.following is the code.

i have used PORTD6,PORTAO,PORTA1 pins for controlling lcd.progarm displays A to Z.here is code its executed succesfully but nothing is displayed on lcd.

i also wanted to know if we can use PORTD and PORTA as input or output lines...please help.Waiting for replies...thanks in advance

#include

#define F_CPU 1000000UL

#include

#include

#define LCD_data PORTB

#define LCD_D7 PORTB

#define LCD_rs PORTA

#define LCD_rw PORTA

#define LCD_en PORTD

#define HIGH LCD_en | (0x01 << 5)

#define LOW LCD_en & ~(0x01 << 5)

void LCD_busy()

{

LCD_D7 = LCD_D7 | (0x01 << 7); //Make D7th bit of LCD as i/p

LCD_en = LCD_en | (0x01 << 5); //Make port pin as o/p

LCD_rs = LCD_rs & ~(0x01 << 0); //Selected command register

LCD_rw = LCD_rw | (0x01 << 1); //We are reading

while(LCD_D7 & (0x01 << 7))

{ //read busy flag again and again till it becomes 0

LCD_en = LOW; //Enable H->L

LCD_en = HIGH;

}

}

void LCD_command(unsigned char var)

{

LCD_data = var; //Function set: 2 Line, 8-bit, 5x7 dots

LCD_rs = LCD_rs & ~(0x01 << 0); //Selected command register

LCD_rw = LCD_rw & ~(0x01 << 1); //We are writing in instruction register

LCD_en = HIGH; //Enable H->L

LCD_en = LOW;

LCD_busy(); //Wait for LCD to process the command

} // Using the above function is really simple

// var will carry the command for LCD

// e.g. // // LCD_command(0x01); which is used to clear lcd

void LCD_init()

{

LCD_command(0x38); //Function set: 2 Line, 8-bit, 5x7 dots

LCD_busy(); //Wait for LCD to process the command

LCD_command(0x0F); //Display on, Curson blinking command

LCD_busy(); //Wait for LCD to process the command

LCD_command(0x01); //Clear LCD

LCD_busy(); //Wait for LCD to process the command

LCD_command(0x06); //Entry mode, auto increment with no shift LCD_busy();

}

void LCD_clear()

{

LCD_command(0x01);

LCD_busy();

}

void LCD_senddata(unsigned char var)

{

LCD_data = var; //Function set: 2 Line, 8-bit, 5x7 dots

LCD_rs = LCD_rs | (0x01 << 0); //Selected data register

LCD_rw = LCD_rw & ~(0x01 << 1); //We are writing

LCD_en = HIGH; //Enable H->L

LCD_en = LOW;

LCD_busy(); //Wait for LCD to process the command

} // Using the above function is really simple

// we should pass the character to display as argument to function // e.g. // LCD_senddata('A');

main()

{

DDRB = 0xff;

DDRA = 0x03;

DDRD = 0x40;

LCD_init();

unsigned char ch = 'A';

while(1)

{

if(ch == 'Z')

{ ch = 'A';

LCD_clear();

}

LCD_senddata('A'); ch++; _delay_ms(1000);

}

}

nikhiljain
nikhiljain's picture
problem with ATtiny + LCD
first of all this code cannot display A to Z.. bcoz in main() u have given: LCD_senddata('A') so it will always display 'A'.. u shud change it to: LCD_senddata(ch) The possible problems may be: a. ur connections may be improper b. u might have connected the LCD data pins to ATtiny pins in d wrong order
Chetan Patil
Chetan Patil's picture
Offline
Last seen: 8 years 11 months ago
Joined: 20/08/2010 - 11:04
problem with ATtiny + LCD
hi thanks Nikhil atlast i got a reply from someone....i have grounded contrast control pin is thatt ok or should i connect potentiometer to it?? i have connected Do pin of lcd to portb0 an D1 to portb1 an so on ,i hope its correct order.
nikhiljain
nikhiljain's picture
problem with ATtiny + LCD
the order of connection is ok.. connect a preset/pot to the contrast pin of LCD. Please check that : R/W=0 when we write to LCD Also check for RS signals.
Log in or register to post comments