Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

my LCD

Status
Not open for further replies.

XL-power

New Member
hi all
i have a problem with the LCD
my problem is that i don't know what is the wrong ,i write the program and test it using Proteus and the LCD is working on the program
i do double check the wire but no thing is happen all what i see is
a black boxes then after a while they dissapper, for pin 3 i do the voltage divier in order to get small voltage (less than 5volt),and same problem
i heard that the Proteus may not give the correct job....

this is my program :
#define F_CPU 8000000UL // crystal frequency in Hz

#include <ctype.h>

#include <stdint.h>

#include <stdio.h>

#include <avr/io.h>

#include <avr/pgmspace.h>

#include <util/delay.h>

#define setbit(port, bit) (port) |= (1 << (bit))

#define clearbit(port, bit) (port) &= ~(1 << (bit))

void my_delay(int ms) //Delay function

{

int i;

for(i=0; i< ms ; i++)

_delay_ms(1);

}

void write(unsigned char z) // function in inorder to write on LCD

{

PORTD=z;

setbit(PORTB,1);

_delay_ms(10);

setbit(PORTB,2);

_delay_ms(10);

clearbit(PORTB,2);

_delay_ms(10); //wait until the LCD finished execution

}

void startLCD()

{

//** 1) Set function set **//

PORTD=0b00111000; //0x38 in hex

clearbit(PORTB,1); //RS=0

_delay_ms(10);

setbit(PORTB,2); // enabled(toggel)

_delay_ms(10);

clearbit(PORTB,2); //unenabled

_delay_ms(10);

//** 2) display ON / OFF control **//

PORTD=0b00001111;

clearbit(PORTB,1);

_delay_ms(4205);

setbit(PORTB,2);

_delay_ms(10);

clearbit(PORTB,2);

_delay_ms(10);

//** 3) clear display **//

PORTD=0b00000001;

clearbit(PORTB,1);

_delay_ms(10);

setbit(PORTB,2);

_delay_ms(10);

clearbit(PORTB,2);

_delay_ms(10);

//** 4) Entry mode **//

PORTD=0b00000110;

clearbit(PORTB,1);

_delay_ms(10);

setbit(PORTB,2);

_delay_ms(10);

clearbit(PORTB,2);

_delay_ms(10);

}

int main()

{

DDRB = 0x06; // making pin (1) of port D as input and mask others

DDRD = 0xFF; // making all of port B pins as outputs

// delay until the LCD become Ready

_delay_ms(10);

_delay_ms(10);

startLCD(); // call LCD function

write(0x20);

write('A');

write('B');


return 0;

}
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top