Microcontroller › 8051 › AT89C51 DS1307 ]- LCD only shows bars (updated : schematic and Photo. › I’ve got an led blinking off
April 21, 2013 at 6:30 pm
#9547
Rohan Thacker
Participant
I’ve got an led blinking off pin 1. I also tried this with a different LCD screen (same 16×2) and the only difference was that the older one showed 4 bars instead of 6. I also put in a different 89c51uC, still no different.
I’ve checked the schematic with the various circuts form a google search and the wiring seem to be correct, can you guys verify that? I’m not really if my reset (pin9) is connected correct.
This is the code i use
<code>
#include<reg51.h>
//Function declarations
void cct_init(void);
void delay(int);
void lcdinit(void);
void writecmd(int);
void writedata(char);
void ReturnHome(void);
//*******************
//Pin description
/*
P2.4 to P2.7 is data bus
P1.0 is RS
P1.1 is E
*/
//********************
// Defines Pins
sbit RS = P1^0;
sbit E = P1^1;
// ***********************************************************
// Main program
//
void main(void)
{
cct_init(); //Make all ports zero
lcdinit(); //Initilize LCD
writedata(‘T’); //write
writedata(‘H’); //write
writedata(‘A’); //write
writedata(‘C’); //write
writedata(‘K’); //write
writedata(‘ ‘); //write
writedata(‘E’); //write
writedata(‘l’); //write
writedata(‘e’); //write
writedata(‘c’); //write
writedata(‘t’); //write
writedata(‘r’); //write
ReturnHome(); //Return to 0 position
while(1)
{
}
}
void cct_init(void)
{
P0 = 0x00; //not used
P1 = 0x00; //not used
P2 = 0x00; //used as data port
P3 = 0x00; //used for generating E and RS
}
void delay(int a)
{
int i;
for(i=0;i<a;i++); //null statement
}
void writedata(char t)
{
RS = 1; // This is data
P2 &= 0x0F; // Make P2.4 to P2.7 zero
P2 |= (t&0xF0); // Write Upper nibble of data
E = 1; // => E = 1
delay(150);
E = 0; // => E = 0
delay(150);
P2 &= 0x0F; // Make P2.4 to P2.7 zero
P2 |= ((t<<4)&0xF0);// Write Lower nibble of data
E = 1; // => E = 1
delay(150);
E = 0; // => E = 0
delay(150);
}
void writecmd(int z)
{
RS = 0; // This is command
P2 &= 0x0F; // Make P2.4 to P2.7 zero
P2 |= (z&0xF0); // Write Upper nibble of data
E = 1; // => E = 1
delay(150);
E = 0; // => E = 0
delay(150);
P2 &= 0x0F; // Make P2.4 to P2.7 zero
P2 |= ((z<<4)&0xF0);// Write Lower nibble of data
E = 1; // => E = 1
delay(150);
E = 0; // => E = 0
delay(150);
}
void lcdinit(void)
{
///////////// Reset process from datasheet /////////
delay(15000);
P2 &= 0x0F; // Make P2.4 to P2.7 zero
P2 |= (0x30&0xF0); // Write 0x3
E = 1; // => E = 1
delay(150);
E = 0; // => E = 0
delay(150);
delay(4500);
P2 &= 0x0F; // Make P2.4 to P2.7 zero
P2 |= (0x30&0xF0); // Write 0x3
E = 1; // => E = 1
delay(150);
E = 0; // => E = 0
delay(150);
delay(300);
P2 &= 0x0F; // Make P2.4 to P2.7 zero
P2 |= (0x30&0xF0); // Write 0x3
E = 1; // => E = 1
delay(150);
E = 0; // => E = 0
delay(150);
delay(650);
P2 &= 0x0F; // Make P2.4 to P2.7 zero
P2 |= (0x20&0xF0); // Write 0x2
E = 1; // => E = 1
delay(150);
E = 0; // => E = 0
delay(150);
delay(650);
/////////////////////////////////////////////////////
writecmd(0x28); //function set
writecmd(0x0c); //display on,cursor off,blink off
writecmd(0x01); //clear display
writecmd(0x06); //entry mode, set increment
}
void ReturnHome(void) //Return to 0 location
{
writecmd(0x02);
delay(1500);
}
</code>
Looks incomplete. is it?