Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[AVR] Help on LCD 16x2 interfacing for AVR microcontroller

Status
Not open for further replies.

tauseefrehman

Junior Member level 1
Junior Member level 1
Joined
Dec 6, 2011
Messages
17
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Visit site
Activity points
1,392
Hi, i am trying to interface 16x2 lcd with avr microcontroller. i am new to c language and avr as well. although i am familiar with PIC and C++.
 

Which Compiler and what clock frequency are you using ? If you are using Atmel Studio 6.x then Zip and post your complete project files.
 

read this code clock FQ 8MHz
Code:
#include<avr/io.h>
#include <stdio.h>
#include <avr/interrupt.h>
//#include <avr/signal.h>
//#include <avr/io.h>
#include <asm.h>
#include <util/delay.h>
#include <avr/pgmspace.h>
#include <avr/sfr_defs.h>
#define LCD_PORT PORTC
#define rombyte pgm_read_byte
#define EN SBIT(PORTC,6)
#define SW SBIT(PORTA,1)
#//define LCD_EN {LCD_PORT|=0x40;_delay_us(1);LCD_PORT&=~0x40;}
#define LCD_EN {EN=1;_delay_us(1);EN=0;}
unsigned int a;
unsigned char d;
#define RS 0x10
#define RW 0x20
int x;
char s[] PROGMEM={"ARUN KUMAR SHARMA"};
char f[] PROGMEM={"Abhay Sharma"};
char *p;
char g;
void busy()
{
  DDRC=0xF0;
  LCD_PORT=0x2F;
  //LCD_PORT|=0x20;
  do
  {
  LCD_PORT|=0x40;
  _delay_us(1);
  ASM_NOP();
  d=(PINC&0x0F)<<4;
  LCD_PORT&=~0x40;
  _delay_us(1);
  LCD_PORT|=0x40;
  _delay_us(1);
  //d|=(PINC&0x0F)<<4;
  LCD_PORT&=~0x40;
  }while(d&0x80);
  DDRC=0xFF;
  }


void LCD_WRITE_DATA(unsigned char data)
{
  LCD_PORT&=~RW;
  LCD_PORT|=RS;
  LCD_PORT=(LCD_PORT&0xF0)|(data>>4);
  LCD_EN;
  LCD_PORT=(LCD_PORT&0xF0)|(data&0x0F);
  LCD_EN;
 busy();
 // _delay_us(1000);
  }
 void LCD_WRITE_CMD(unsigned char data)
 {
  LCD_PORT&=~RW;
  LCD_PORT&=~RS;
  LCD_PORT=(LCD_PORT&0xF0)|(data>>4);
  LCD_EN;
  LCD_PORT=(LCD_PORT&0xF0)|(data&0x0F);
  LCD_EN;
  busy();
  //_delay_us(1000);
  }
 void init_LCD()
 {
   LCD_PORT=0x00;
   LCD_PORT|=0x02;
   LCD_EN;
   _delay_us(50);
   LCD_WRITE_CMD(0x28);
   LCD_WRITE_CMD(0x0F);
   LCD_WRITE_CMD(0x01);
   LCD_WRITE_CMD(0x02);
   } 
ISR(INT0_vect)
{
LCD_WRITE_CMD(0x01);
}
 
int main()
	{
	int i=0;
	DDRA=0xf1;
	PORTA=0x02;
	DDRC=0xFF;
	PORTC=0x00;
    DDRD=0b11111011;
    PORTD=0b00000100;
    MCUCR=(1<<ISC00)|(1<<ISC01);
    GICR=0b01000000;
    sei();
   init_LCD();
   p=&s[0];
   //g=rombyte(&s);
   while(rombyte(&*p))
   {
   LCD_WRITE_DATA(rombyte(&*p));
 
   i++;
   //p=pgm_read_byte(s[i]);
   p++;
    }
   
  // LCD_WRITE_DATA('S');
 while(1)
{

if(bit_is_set(PINA,1)/*PINA&0x02*/)
g=1;
if(g&&bit_is_clear(PINA,1)/*((PINA&0x02)==0)*/)
{
  g=0;
  p=f;
  //LCD_WRITE_CMD(0x01);
  LCD_WRITE_CMD(0xC0);
  while(rombyte(&*p))
   {
   LCD_WRITE_DATA(rombyte(&*p));
   p++;
    }
    }
}
//return 0 ;
}
i think this will help you
 

@milan.rajik i am using AVR Studio 5

- - - Updated - - -

@arun_190175 thank you for your response but understanding assembly language is very difficult for me at this moment. C will be better because its easy to understand. if you can help me with a C code that would be very helpful.
 

@milan.rajik i am using AVR Studio 5

- - - Updated - - -

@arun_190175 thank you for your response but understanding assembly language is very difficult for me at this moment. C will be better because its easy to understand. if you can help me with a C code that would be very helpful.
plz. Look the code. Also c winavrgcc. And. Avrstudio
 

I don't have Atmel Studio 5. I have written code for Atmel Studio 6.2. I have included SBIT.H file. Include it in your projects. It is used for LCD defines. Try my code in AVR Studio. It might work.

https://www.edaboard.com/threads/287961/

Project attached. Proteus design attached. If display refresh seems slow then decrease delays used in LCD code.
 

Attachments

  • LCD 4 bit.rar
    49.4 KB · Views: 115

    V

    Points: 2
    Helpful Answer Positive Rating
Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top