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.

Function and without function in AVR ?

Status
Not open for further replies.
I have posted hex for both 8 bit and 4 bit. It is for 8 MHz Clock and ATMega128. The connection should be as shown in Proteus file. If it does not work all you have to do is increase the delays in lcd initialization routine. I have not tested them on hardware.

You selected AT90CAN128. Earlier you used ATMega128.

I fix it to ATMEGA 128, but still not working, I have no idea....
Am I missing something on AVR Studio 6.10 ?
I tested the hardware port by port and it's working....
but by the time I give LCD_command, combination between port A and port D it's stopped working...

- - - Updated - - -

I have posted hex for both 8 bit and 4 bit. It is for 8 MHz Clock and ATMega128. The connection should be as shown in Proteus file. If it does not work all you have to do is increase the delays in lcd initialization routine. I have not tested them on hardware.

You selected AT90CAN128. Earlier you used ATMega128.
I fixed it into ATMega128, but I don't understand with the LCD command,
combination between portA and portD in one function,
it's not working, but if I tested each port by itself it's working ???????
 

Check you lcd. Maybe it is defective. All you have to do is increase delays in LCD initialization routine. Increase _delay_ms(150) to _delay_ms(300); If it still doesn't work then buy a new LCD.

LCD 8 bit 2 Control pins. RW should be connected to ground.


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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
#include <avr/io.h>
#include <util/delay.h>
 
//Mention Clock frequency here
#define _XTAL_FREQ 8000000 
 
// structure to allow bit field operations, name conversions: PORTA.0 -> PORT_A.b0  PORTB.7 -> PORT_B.b7
typedef struct{ uint8_t b0:1;
                uint8_t b1:1;
                uint8_t b2:1;
                uint8_t b3:1;
                uint8_t b4:1;
                uint8_t b5:1;
                uint8_t b6:1;
                uint8_t b7:1; } bits;
 
// define all the ports of your microcontroller, add more ports depending on the available mcu ports
#define PORT_A (* (volatile bits *) &PORTA)
#define PIN_A (* (volatile bits *) &PINA)
#define DDR_A (* (volatile bits *) &DDRA)
 
#define PORT_B (* (volatile bits *) &PORTB)
#define PIN_B (* (volatile bits *) &PINB)
#define DDR_B (* (volatile bits *) &DDRB)
 
#define lcd_data_pin  PORTD
#define en  PORT_A.b0
#define rs  PORT_A.b1
//#define rw  PORT_A.b2
 
 
void lcd_init();
void lcd_data(unsigned char data1);
void lcd_cmd(unsigned char cmd);
void lcd_control(unsigned char cmdordata);
void lcd_string(unsigned char *str);
 
 
void lcd_init(){
 
    lcd_cmd(0x38);
    _delay_ms(150);      
    lcd_cmd(0x0E);
    _delay_ms(150);      
    lcd_cmd(0x01);
    _delay_ms(150);    
    lcd_cmd(0x06);
    _delay_ms(150);
    lcd_cmd(0x0C);
    _delay_ms(150);
    lcd_cmd(0x80);
 
}
 
void lcd_data(unsigned char data1)
{
     
    lcd_data_pin = data1;
    lcd_control(2);
    
        
}
 
void lcd_cmd(unsigned char cmd){
 
    lcd_data_pin = cmd;
    lcd_control(1);
}
 
void lcd_control(unsigned char cmdordata){
 
    if(cmdordata == 1){
        rs=0;
        //rw=0;
        en=1;
        _delay_ms(5);       
        en=0;
    }
    else if(cmdordata == 2){
        rs=1;
        //rw=0;
        en=1;
        _delay_ms(5);
        en=0;
    }
}
 
void lcd_string(unsigned char *str){
 
    while(*str){
        lcd_data(*str++);       
    }
 
}
 
 
unsigned char msg[20] = "Working?"; 
 
int main(){
 
    
 
    DDRA = 0xFF;
    DDRD = 0xFF;
    PORTA = 0x00;
    PORTD = 0x00; 
 
    lcd_init();
    lcd_data('A');
    lcd_cmd(0xC0);
    lcd_string(msg);
    
    while(1){
 
        ;
 
    }
    
    return (0);
}



90638d1367823857-lcd8bit2ctrlpin.jpg

lcd8bit2ctrlpin.jpg
 
Last edited:

Check you lcd. Maybe it is defective. All you have to do is increase delays in LCD initialization routine. Increase _delay_ms(150) to _delay_ms(300); If it still doesn't work then buy a new LCD.

LCD 8 bit 2 Control pins. RW should be connected to ground.


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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
#include <avr/io.h>
#include <util/delay.h>
 
//Mention Clock frequency here
#define _XTAL_FREQ 8000000 
 
// structure to allow bit field operations, name conversions: PORTA.0 -> PORT_A.b0  PORTB.7 -> PORT_B.b7
typedef struct{ uint8_t b0:1;
                uint8_t b1:1;
                uint8_t b2:1;
                uint8_t b3:1;
                uint8_t b4:1;
                uint8_t b5:1;
                uint8_t b6:1;
                uint8_t b7:1; } bits;
 
// define all the ports of your microcontroller, add more ports depending on the available mcu ports
#define PORT_A (* (volatile bits *) &PORTA)
#define PIN_A (* (volatile bits *) &PINA)
#define DDR_A (* (volatile bits *) &DDRA)
 
#define PORT_B (* (volatile bits *) &PORTB)
#define PIN_B (* (volatile bits *) &PINB)
#define DDR_B (* (volatile bits *) &DDRB)
 
#define lcd_data_pin  PORTD
#define en  PORT_A.b0
#define rs  PORT_A.b1
//#define rw  PORT_A.b2
 
 
void lcd_init();
void lcd_data(unsigned char data1);
void lcd_cmd(unsigned char cmd);
void lcd_control(unsigned char cmdordata);
void lcd_string(unsigned char *str);
 
 
void lcd_init(){
 
    lcd_cmd(0x38);
    _delay_ms(150);      
    lcd_cmd(0x0E);
    _delay_ms(150);      
    lcd_cmd(0x01);
    _delay_ms(150);    
    lcd_cmd(0x06);
    _delay_ms(150);
    lcd_cmd(0x0C);
    _delay_ms(150);
    lcd_cmd(0x80);
 
}
 
void lcd_data(unsigned char data1)
{
     
    lcd_data_pin = data1;
    lcd_control(2);
    
        
}
 
void lcd_cmd(unsigned char cmd){
 
    lcd_data_pin = cmd;
    lcd_control(1);
}
 
void lcd_control(unsigned char cmdordata){
 
    if(cmdordata == 1){
        rs=0;
        //rw=0;
        en=1;
        _delay_ms(5);       
        en=0;
    }
    else if(cmdordata == 2){
        rs=1;
        //rw=0;
        en=1;
        _delay_ms(5);
        en=0;
    }
}
 
void lcd_string(unsigned char *str){
 
    while(*str){
        lcd_data(*str++);       
    }
 
}
 
 
unsigned char msg[20] = "Working?"; 
 
int main(){
 
    
 
    DDRA = 0xFF;
    DDRD = 0xFF;
    PORTA = 0x00;
    PORTD = 0x00; 
 
    lcd_init();
    lcd_data('A');
    lcd_cmd(0xC0);
    lcd_string(msg);
    
    while(1){
 
        ;
 
    }
    
    return (0);
}

my LCD is working fine, I checked it with MCS51 controller, it's ok....I check all the ports on ATMEGA 128, it's allright, so it's the code, not yet right..
do you compile this code above with AVR Studio 6.1 ?
thanks
 

Check you lcd. Maybe it is defective. All you have to do is increase delays in LCD initialization routine. Increase _delay_ms(150) to _delay_ms(300); If it still doesn't work then buy a new LCD.
Delays are already a large multiple of specified values. But no problem as such. You can shrink it to reasonable delays once the application is working. In case of doubt, refer to the HD44780 datsheet.

The present lcd_init() code is however relying on power-on reset of the LCD controller. Personally I'm using the "initialization by instruction" method since ever, just in case.
 

can you test my hex file in your simulation please ?
it was compiled with AVR 6.10
thanks
 

Attachments

  • LCD_test.zip
    588 bytes · Views: 54

.hex file in LCD_Test.zip

Post your Circuit and Atmel Studio 6.1 Code.

Could you try this code into your simulator please ?
I compiled it with avr studio 4

Thanks

- - - Updated - - -

The code :

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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
#include <avr/io.h>
#include <util/delay.h>
 
// structure to allow bit field operations, name conversions: PORTA.0 -> PORT_A.b0  PORTB.7 -> PORT_B.b7
typedef struct{ uint8_t b0:1;
                uint8_t b1:1;
                uint8_t b2:1;
                uint8_t b3:1;
                uint8_t b4:1;
                uint8_t b5:1;
                uint8_t b6:1;
                uint8_t b7:1; } bits;
 
// define all the ports of your microcontroller, add more ports depending on the available mcu ports
#define PORT_A (* (volatile bits *) &PORTA)
#define PIN_A (* (volatile bits *) &PINA)
#define DDR_A (* (volatile bits *) &DDRA)
 
#define PORT_B (* (volatile bits *) &PORTB)
#define PIN_B (* (volatile bits *) &PINB)
#define DDR_B (* (volatile bits *) &DDRB)
 
//Mention Clock frequency here
#define _XTAL_FREQ 8000000 
 
#define lcd_data_pin PORTD
 
#define en PORT_A.b0
#define rs PORT_A.b1
#define rw PORT_A.b2
 
 
void lcd_init();
void lcd_data(unsigned char data1);
void lcd_cmd(unsigned char cmd);
void lcd_control(unsigned char cmdordata);
void lcd_string(unsigned char *str);
 
 
void lcd_init(){
 
    lcd_cmd(0x02);      
    lcd_cmd(0x28);      
    lcd_cmd(0x0C);
    lcd_cmd(0x06);
    lcd_cmd(0x80);
 
}
 
void lcd_data(unsigned char data1)
{
     
    lcd_data_pin = data1;
    lcd_control(2);
    
        
}
 
void lcd_cmd(unsigned char cmd){
 
    lcd_data_pin = cmd & 0xF0;
    lcd_control(1);
 
    lcd_data_pin = (cmd << 4) & 0xF0;
    lcd_control(1);
 
 
}
 
void lcd_control(unsigned char cmdordata){
 
    if(cmdordata == 1){
        en=1;
        rs=0;
        rw=0;
        _delay_ms(1);       
        en=0;
    }
    else if(cmdordata == 2){
        en=1;
        rs=1;
        rw=0;
        _delay_ms(1);
        en=0;
    }
}
 
void lcd_string(unsigned char *str){
 
    while(*str){
        lcd_data(*str++);       
    }
 
}
 
 
 
 
int main(){
 
    DDRA = 0xFF;
    DDRD = 0xFF;
 
    lcd_init();
    lcd_data('A');
    
    
    while(1){
 
        lcd_string("Working?");
 
    }
    
    return (0);
}



- - - Updated - - -

I tested the port with this code, and there's no problem
port test2.jpg
Code:
/*
 * port.c
 *
 * Created: 7/05/2013 7:31:27 PM
 *  Author: Antonius
 */ 


#include <avr/io.h>
#include <avr/delay.h>
int main(void)
{
	DDRD = 0xFF;
	DDRA = 0xFF;
    while(1)
    {
		PORTD = 0xFF;
		_delay_ms(200);
		PORTD = 0;
        _delay_ms(200);
		PORTA = 0xFF;
		_delay_ms(200);
		PORTA = 0;
        //TODO:: Please write your application code 
    }
}
 

Attachments

  • Atmega128.zip
    560 bytes · Views: 49

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top