Code to manupulate LCD display.

Go To Last Post
7 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi, Could someone please write a code to manipulate LCD Display for me?

Following purpose should be full fill by the code.

1. to write a character/digit/text in the display.
2. to delete a character/digit/text that already exists in the display.
3. to change a character/digit/text by another character in the display.

Micro-controller: ATmega16
Compiler: Atmelstudio 6.1

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

If you actually put some effort into it, you can get all the help here you will need.

But it's not very likely you will get anyone here to do it for you.

You might also want to have a look at this thread...

https://www.avrfreaks.net/index.php?name=PNphpBB2&file=viewtopic&t=134409

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Here's how I do it. 46 lines of code. All muscle. No fluff.

//-----------------text lcd routines----------------------
//data pd4567

//#define RWLO() PORTB &= ~0x02 //gnd
//#define RWHI() PORTB |=  0x02

#define RSLO() PORTB &= ~0x01 //d8 pb0
#define RSHI() PORTB |=  0x01

#define ENLO() PORTB &= ~0x02 //d9 pb1
#define ENHI() PORTB |=  0x02

//------------------------
void lcddel10us(int n){
//delay 10 usec
int j;

  while(n--) {
    j=26;
    while(j--){}; //2600=1ms, 260=100usec, 26=10usec
  }
}

//--------------------
void putnib(char c){
//lo bytes of d to hi bits of port

  PORTD = (PORTD & 0x0f)|(c << 4);
  ENHI();
  asm("nop"); //8x62=500ns
  asm("nop");
  asm("nop");
  asm("nop");
  asm("nop");
  asm("nop");
  asm("nop");
  asm("nop");
  ENLO();
}

//--------------------
void lcdputbyte(unsigned char c){
//either data or cmd byte, previously set

//  RWLO(); //write
  putnib(c >> 4);    //hi nib
  putnib(c & 0x0f);  //lo nib
  lcddel10us(5);
}

//--------------------
void lcdcmdbyte(unsigned char c){
//cmd byte

  RSLO(); //command
  lcdputbyte(c);
}

//--------------------
void lcddatabyte(unsigned char c){
//data byte

  RSHI();  //data
  lcdputbyte(c);
}

//----------------
void lcdcls(void){
//clear lcd screen    1.64ms

  lcdcmdbyte(0x01);
  lcddel10us(165);
}

//--------------------------------------
void lcdgotoxy(unsigned char column, unsigned char line){
//position cursor  top line chars 0-39, 2nd line 40-79
unsigned char addr;

  addr = (line * 64) + column;
  lcdcmdbyte(addr | 0x80);
}

//----------------
void lcdcursoron(void){
//cursor on

  lcdcmdbyte(0x0e);
}

//----------------
void lcdcursoroff(void){
//cursor off

  lcdcmdbyte(0x0c);
}

//------------------
void lcdputc(char c){
//put c

  lcddatabyte(c);
}

//------------------
void lcdcputs(__flash char *ptr){
//put rom string at ptr

  while(*ptr != 0x00){
    lcdputc(*ptr++);
  }  
}

//------------------
void lcdputs(char *ptr){
//put ram string at ptr

  while(*ptr != 0x00){
    lcdputc(*ptr++);
  }  
}

//------------------
void lcdinit(void){
//init lcd 4 bit mode

  lcddel10us(1500); //15000us
  lcdcmdbyte(0x38); //8 bit 2 lines
  lcddel10us(410);  //4100us
  lcdcmdbyte(0x28); //4 bit 2 lines
  lcddel10us(10);   //100us
  lcdcmdbyte(0x28); //4 bit 2 lines
  lcdcmdbyte(0x0c); //display on    40usec
  lcdcmdbyte(0x06); //cursor on, increment  40usec
  lcdcmdbyte(0x80); //cg addr 0     40usec
  lcdcmdbyte(0x40); //data addr 0   40usec
}

//-----------------------------
void lcdsplash(void){
//power on splash screen on lcd
	
  lcdcls();
  //        0123456789012345
  lcdcputs(" LCD Menu Demo  ");
  lcdgotoxy(0,1);
  lcdcputs("    12/28/12    ");
}



Imagecraft compiler user

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

@Bob,

I was fascinated whether your functions would work.
The init() is not strictly to the HD44780 recommendation. i.e. the second nibble is sent after 50us and not 4100us !

I had to make your delay counter volatile and add :

   DDRD |= 0xF0;
   DDRB |= 0x03;

to the lcd_init() function to make the signals active.

And my module actually initialised ok !
Note that you have a 50us per nibble when you only need 50us per byte. (after initialisation)

David.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Yup. I see no requirement for delay after the 1st nibble. The initdevices generated by the imagecraft appbuilder inits the ports, uart etc. I call lcd init in the app main. Sure is compact aint it? I think 'Lean and Mean' might describe it. I guess the imagecraft compiler doesn't fret too much about counting down a local stack variable. I think it treats globals as volatile though. Seems I recall reading that in the docs a while back.

Imagecraft compiler user

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Bob wrote:
The initdevices generated by the imagecraft appbuilder inits the ports, uart etc.

Pray tell us how it will help the OP to post code that relies on a intrinsic init function specific to one compiler when the OP has explicitly mentioned using another compiler?

Quote:
Hi, Could someone please write a code to manipulate LCD Display for me?

You need to write it yourself. We will gladly help you accomplish it, but the major part of the effort will have to come from you.

As an alternative, you could just pick up some already-written code that has bee proven over time. For your convenience I have collected links to several character LCD implementations here: http://www.johanekdahl.se/rwiki/... . They do not have all the functionality you need, but any of them will be a good starting point.

As of January 15, 2018, Site fix-up work has begun! Now do your part and report any bugs or deficiencies here

No guarantees, but if we don't report problems they won't get much of  a chance to be fixed! Details/discussions at link given just above.

 

"Some questions have no answers."[C Baird] "There comes a point where the spoon-feeding has to stop and the independent thinking has to start." [C Lawson] "There are always ways to disagree, without being disagreeable."[E Weddington] "Words represent concepts. Use the wrong words, communicate the wrong concept." [J Morin] "Persistence only goes so far if you set yourself up for failure." [Kartman]

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Or just dl the 45 day free demo of the imagecraft compiler and create a project and hit the build button. If you dl the compiler and tell me which avr and clock rate you want, I'll create the project and send you the files.

Imagecraft compiler user