Go Down

Topic: - 4 BIT LCD - (Read 800 times) previous topic - next topic

iparuk

Hello guys, I am quite new to AVR and GCC and I am having a bit of trouble trying to get a LCD to work in 4 bit mode, I have been able to get it to work in 8 bit mode, but I think I am initializing it wrong, I have actually no clue whats wrong, I have been following this for the initialization
This may be an Arduino forum but someone must know some gcc ?

http://www.bipom.com/documents/appnotes/LCD%20Interfacing%20using%20HD44780%20Hitachi%20chipset%20compatible%20LCD.pdf

and here is my code, I know it looks bad but i will neaten it up when it works!
:
Code: [Select]




#include<util/delay.h>  
#include<avr/interrupt.h>  
#define DATA_DDR       DDRB            
#define DATA_PORT        PORTB
#define CONTROL_DDR              DDRD      
#define CONTROL_PORT        PORTD
#define Enable_Pin              6
#define RegSelect_Pin     4    
#define ReadWrite_Pin     5
#define Set_Enable                          CONTROL_PORT|=_BV(Enable_Pin)
#define Clear_Enable                         CONTROL_PORT&=~_BV(Enable_Pin)
#define Write_Lcd                            CONTROL_PORT&=~_BV(ReadWrite_Pin)
#define Read_Lcd                                 CONTROL_PORT|=_BV(ReadWrite_Pin)
#define Select_InstructionRegister       CONTROL_PORT&=~_BV(RegSelect_Pin) //Sets register select low
#define Select_DataRegister                CONTROL_PORT|=_BV(RegSelect_Pin)






int main(void)
{
_delay_ms(20);
Select_InstructionRegister;

PORTB = 0B0000;
   Set_Enable;
     _delay_us(100);
     Clear_Enable;
     _delay_us(100);
PORTB = 0B0011;
     Set_Enable;
     _delay_us(100);
     Clear_Enable;
     _delay_us(100);

_delay_ms(5);

PORTB = 0B0000;
   Set_Enable;
     _delay_us(100);
     Clear_Enable;
     _delay_us(100);
PORTB = 0B0011;
     Set_Enable;
     _delay_us(100);
     Clear_Enable;
     _delay_us(100);

_delay_us(160);

PORTB = 0B0000;
   Set_Enable;
     _delay_us(100);
     Clear_Enable;
     _delay_us(100);
PORTB = 0B0011;
     Set_Enable;
     _delay_us(100);
     Clear_Enable;
     _delay_us(100);

_delay_us(160);


PORTB = 0B0000;
   Set_Enable;
     _delay_us(100);
     Clear_Enable;
     _delay_us(100);
PORTB = 0B0010;
     Set_Enable;
     _delay_us(100);
     Clear_Enable;
     _delay_us(100);

_delay_us(160);

PORTB = 0B0011;
   Set_Enable;
     _delay_us(100);
     Clear_Enable;
     _delay_us(100);
PORTB = 0B1000;
     Set_Enable;
     _delay_us(100);
     Clear_Enable;
     _delay_us(100);

PORTB = 0B0011;
   Set_Enable;
     _delay_us(100);
     Clear_Enable;
     _delay_us(100);
PORTB = 0B1000;
     Set_Enable;
     _delay_us(100);
     Clear_Enable;
     _delay_us(100);

PORTB = 0B0001;
   Set_Enable;
     _delay_us(100);
     Clear_Enable;
     _delay_us(100);
PORTB = 0B0000;
     Set_Enable;
     _delay_us(100);
     Clear_Enable;
     _delay_us(100);


PORTB = 0B0000;
   Set_Enable;
     _delay_us(100);
     Clear_Enable;
     _delay_us(100);
PORTB = 0B0001;
     Set_Enable;
     _delay_us(100);
     Clear_Enable;
     _delay_us(100);

PORTB = 0B0000;
   Set_Enable;
     _delay_us(100);
     Clear_Enable;
     _delay_us(100);
PORTB = 0B0110;
     Set_Enable;
     _delay_us(100);
     Clear_Enable;
     _delay_us(100);


PORTB = 0B0000;
   Set_Enable;
     
     Clear_Enable;
     _delay_us(100);
PORTB = 0B1100;
     Set_Enable;
     _delay_us(100);
     Clear_Enable;
     _delay_us(100);


for(;;) // loop forever
{

Select_DataRegister;

PORTB = 0B0010;  
   Set_Enable;
     _delay_us(100);
     Clear_Enable;
     _delay_us(100);
PORTB = 0B1110;
     Set_Enable;
     _delay_us(100);
     Clear_Enable;
     _delay_us(100);




}
}



Any help appreciated...

P.S I have posted this on other forums if you have seen this post before, I just want to get the quickest and best reply.

Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy