bianchi77
Advanced Member level 4
- Joined
- Jun 11, 2009
- Messages
- 1,313
- Helped
- 21
- Reputation
- 44
- Reaction score
- 20
- Trophy points
- 1,318
- Location
- California
- Activity points
- 9,442
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,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.
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..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); }
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.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.
which test file do you mean ?What is the test file for? 8 data pin, 3 control pins?
Yes it is working in Simulator.
Please find the circuit and atmel studio 6.1 code.hex file in LCD_Test.zip
Post your Circuit and Atmel Studio 6.1 Code.
.hex file in LCD_Test.zip
Post your Circuit and Atmel Studio 6.1 Code.
.hex file in LCD_Test.zip
Post your Circuit and Atmel Studio 6.1 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); }
/*
* 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
}
}
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?