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.

LCD in 4 Bit Mode using atmega8

Status
Not open for further replies.

Briez

Member level 5
Joined
Nov 30, 2012
Messages
83
Helped
4
Reputation
8
Reaction score
4
Trophy points
1,288
Activity points
1,835
I want to use lcd in 4 bit mode using atmega8, and i am facing problems in that... Someone help me to sort out this problem.​

I am using 16x2 character LCD and my pin configurations are,


Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
LCD_DATA   > PORTD   (PD4,PD5,PD6,PD7)
Rs              > PC5
E               > PC4
 
my code is/ /****************************************************************************************************//
 
#define F_CPU 4000000UL
 
#include<avr/io.h>
#include<util/delay.h>
 
#define DATA PORTD
//#define RS PC5
//#define E PC4
void lcd_init(void)
{
    lcd_cmd(0x28);
        _delay_ms(25);
    lcd_cmd(0x01);
        _delay_ms(25);
    lcd_cmd(0x0E);
        _delay_ms(25);
    lcd_cmd(0x06);
        _delay_ms(25);
 
}
void lcd_cmd(unsigned int cmd)
{
    DATA=cmd & 0xF0;
    PORTC=(0<<PC5);//|(1<<PC4);
    PORTC=(1<<PC4);
    _delay_ms(25);
    PORTC=(0<<PC4);
    
    DATA=((cmd<<4) & 0xF0);
    PORTC=(0<<PC5);//|(1<<PC4);
    PORTC=(1<<PC4);
    _delay_ms(25);
    PORTC=(0<<PC4);
return;
}
void lcd_data1(unsigned char data1)
{
    DATA=data1 & 0xF0;
    PORTC=(1<<PC5);//|(1<<PC4);
    PORTC=(1<<PC4);
    _delay_ms(25);
    PORTC=(0<<PC4);
    
    DATA=((data1<<4) & 0xF0);
    PORTC=(1<<PC5);//|(1<<PC4);
    PORTC=(1<<PC4);
    _delay_ms(25);
    PORTC=(0<<PC4);
return;
}
 
int main(void)
{
    DDRD=0xFF;
    DDRC=0x30;
_delay_ms(2);
    lcd_init();
while(1)
    {
    _delay_ms(2);
    lcd_data1('B');
    }
return 0;   
}

 
Last edited by a moderator:

If you're willing to write your own driver then I'd suggest you to use a minimum of 50 micro-seconds delay for the Enable high state. But if you just need to use an LCD then you might want to check out the C driver I made:
https://www.edaboard.com/blog/1817/
p.s. I'm not sure the driver will work on atmega8 PICs, but it's almost all standard C so it should.
 


Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top