interfacing HC9S12DP256 with LCD (HD44780U) 8 bit

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

interfacing HC9S12DP256 with LCD (HD44780U) 8 bit

1,487 Views
Seitec
Contributor III
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
Labels (1)
0 Kudos
2 Replies

256 Views
Lundin
Senior Contributor IV
You don't set the port pins as outputs anywhere. Write to the data direction registers for each port.

Also, using loops to cause time delays is considered poor programming. They keep the CPU busy when it could be working and they make the code non-portable. Use on-chip hardware timers instead.
0 Kudos

256 Views
Seitec
Contributor III
Yes you hava absolutely true. I am forget on it. And I am delete delay and compensate it check busy flag. and now it working. Thank you very much Lundin
0 Kudos