Ondrej Machek

interfacing HC9S12DP256 with LCD (HD44780U) 8 bit

Discussion created by Ondrej Machek on Jan 8, 2009
Latest reply on Jan 9, 2009 by Ondrej Machek
hello,

i can´t understant where i hava error in my code. pleas look at my code. see anybody where is error?

Thank you very much.



#include       /* common defines and macros */

#include      /* derivative information */

#pragma LINK_INFO DERIVATIVE "mc9s12dp256b"



#define LCD_data PORTA

#define LCD_D7 PORTA_BIT7

#define LCD_rs PORTB_BIT0

#define LCD_rw PORTB_BIT1

#define LCD_en PORTB_BIT2



/*****************zpozdeni pri praci s LCD************************/

void LCD_busy(void){

         unsigned char i,j;

         for(i=0;i<50;i++)        //A simple for loop for delay

            for(j=0;j<255;j++);

}





void LCD_init(){

  int i = 0;

  LCD_data = 0x30;           /*prikaz 0x30*/

  LCD_rs   = 0;

  LCD_rw   = 0;

  LCD_en   = 0;

  LCD_en   = 1;

  LCD_en   = 0;

  for(i=0; i<2000; i++);     /*pauza 4.1 ms*/

  for(i=0; i<2000; i++);

 

  LCD_data = 0x30;           /*prikaz 0x30*/

  LCD_rs   = 0;

  LCD_rw   = 0;

  LCD_en   = 0;

  LCD_en   = 1;

  LCD_en   = 0;

  for(i=0; i<2000; i++);     /*pauza 100 us*/

 

  LCD_data = 0x30;           /*prikaz 0x30*/

  LCD_rs   = 0;

  LCD_rw   = 0;

  LCD_en   = 0;

  LCD_en   = 1;

  LCD_en   = 0;

  for(i=0; i<2000; i++);     /*pauza 4.1 ms*/

 

  LCD_data = 0x38;             /*dva radky a 5x8 dots*/

  LCD_rs   = 0;

  LCD_rw   = 0;

  LCD_en   = 1;

  LCD_en   = 0;

  LCD_busy();

 

  LCD_data = 0x0E;

  LCD_rs   = 0;

  LCD_rw   = 0;

  LCD_en   = 1;

  LCD_en   = 0;

  LCD_busy();

 

  LCD_data = 0x01;

  LCD_rs   = 0;

  LCD_rw   = 0;

  LCD_en   = 1;

  LCD_en   = 0;

  LCD_busy();

 

  LCD_data = 0x06;

  LCD_rs   = 0;

  LCD_rw   = 0;

  LCD_en   = 1;

  LCD_en   = 0;

  LCD_busy();

 

}









/******************odesilani prikazu****************************/

void LCD_command(unsigned char var){

  LCD_data = var;

  LCD_rs   = 0;

  LCD_rw   = 0;

  LCD_en   = 1;

  LCD_en   = 0;

  LCD_busy();

}





/*****************odesilani dat*********************************/

void LCD_senddata(unsigned char var){

  LCD_data = var;

  LCD_rs   = 1;

  LCD_rw   = 0;

  LCD_en   = 1;

  LCD_en   = 0;

  LCD_busy();

  LCD_rs   = 0;

 

}



/******************odeslani retezce******************************/

void LCD_sendstring(unsigned char *var, int line){

  unsigned char instruction;

  if(line == 1){

    instruction = 0x80;

  }else{

    instruction = 0xC0;

  }

  LCD_command(instruction);

 

  while(*var){

    LCD_senddata(*var++);

  }

}



void main(void) {

  /* put your own code here */

  EnableInterrupts;

  LCD_init();

  LCD_sendstring("ahoj", 1);

  for(;:smileywink: {} /* wait forever */

  /* please make sure that you never leave this function */

}



Message Edited by Seitec on 2009-01-08 09:55 PM

Outcomes