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.

[SOLVED] port 0 problem on at89c52 with lcd ??

Status
Not open for further replies.

#MAAM#

Full Member level 2
Joined
Nov 21, 2009
Messages
131
Helped
29
Reputation
58
Reaction score
27
Trophy points
1,308
Location
Egypt
Activity points
1,920
Hi guys

When i interface LCD(2x16) (4 bit mode) with at89c52 in port 3 it work well. when i connect it to port 0 (by taking into account i change the code with port 0) it is not working !!!!!!!

my working code with port 3
basic calculator.c
Code:
#include <reg52.h>
#include "lcd.h"

main( )
{
    LCD_init();
    LCD_row1(); LCD_putc(0+48);//LCD_puts("Hello World");
    LCD_row2(); LCD_puts("Good Morning");
    while (1);
}

lcd.h

Code:
 sbit LCD_en =P3^7;
 sbit LCD_rs =P3^5;
 sbit rw =P3^6; 
 #define LCD_DELAY 1535 /* Delay for 1 ms */
 #define LCD_clear() LCD_command(0x1)	/* Clear display LCD */
 #define LCD_origin() LCD_command(0x2)	/* Set to origin LCD */
 #define LCD_row1() LCD_command(0x80)	/* Begin at Line 1 */
 #define LCD_row2() LCD_command(0xC0)   /* Begin at Line 2 */
 
/***************************************************
 * Prototype(s)                                    *
 ***************************************************/
void LCD_delay(unsigned char ms);
void LCD_enable();
void LCD_command(unsigned char command);
void LCD_putc(unsigned char ascii);
void LCD_puts(unsigned char *lcd_string);
void LCD_init();

/***************************************************
 * Sources                                         *
 ***************************************************/
void LCD_delay(unsigned char ms)
{
	unsigned char n;
	unsigned int i;
	for (n=0; n<ms; n++)
	{
		for (i=0; i<LCD_DELAY; i++); /* For 1 ms */
	}
    
}

void LCD_enable()
{
    LCD_en = 0; /* Clear bit P2.4 */
    LCD_delay(1);
    LCD_en = 1; /* Set bit P2.4 */
}

void LCD_command(unsigned char command)
{
    LCD_rs = 0; /* Clear bit P2.5 */
    P3 = (P3 & 0xF0)|((command>>4) & 0x0F);
    LCD_enable();
    P3 = (P3 & 0xF0)|(command & 0x0F);
    LCD_enable();
    LCD_delay(1);
}

void LCD_putc(unsigned char ascii)
{
    LCD_rs = 1; /* Set bit P2.5 */
    P3 = (P3 & 0xF0)|((ascii>>4) & 0x0F);
    LCD_enable();
    P3 = (P3 & 0xF0)|(ascii & 0x0F);
    LCD_enable();
    LCD_delay(1);
}

void LCD_puts(unsigned char *lcd_string)
{
	while (*lcd_string) 
	{
		LCD_putc(*lcd_string++);
	}
}

void LCD_init()
{
    LCD_en = 1; /* Set bit P2.4 */
    LCD_rs = 0; /* Clear bit P2.5 */
	rw=0;   
    LCD_command(0x33);
    LCD_command(0x32);
    LCD_command(0x28);
    LCD_command(0x0C);
    LCD_command(0x06);
    LCD_command(0x01); /* Clear */
    LCD_delay(256);
}

my not working code with port 0
basic calculator.c
Code:
#include <reg52.h>
#include "lcd.h"

main( )
{
    LCD_init();
    LCD_row1(); LCD_putc(0+48);//LCD_puts("Hello World");
    LCD_row2(); LCD_puts("Good Morning");
    while (1);
}

lcd.h
Code:
 sbit LCD_en =P0^7;
 sbit LCD_rs =P0^5;
 sbit rw =P0^6; 
 #define LCD_DELAY 1535 /* Delay for 1 ms */
 #define LCD_clear() LCD_command(0x1)	/* Clear display LCD */
 #define LCD_origin() LCD_command(0x2)	/* Set to origin LCD */
 #define LCD_row1() LCD_command(0x80)	/* Begin at Line 1 */
 #define LCD_row2() LCD_command(0xC0)   /* Begin at Line 2 */
 
/***************************************************
 * Prototype(s)                                    *
 ***************************************************/
void LCD_delay(unsigned char ms);
void LCD_enable();
void LCD_command(unsigned char command);
void LCD_putc(unsigned char ascii);
void LCD_puts(unsigned char *lcd_string);
void LCD_init();

/***************************************************
 * Sources                                         *
 ***************************************************/
void LCD_delay(unsigned char ms)
{
	unsigned char n;
	unsigned int i;
	for (n=0; n<ms; n++)
	{
		for (i=0; i<LCD_DELAY; i++); /* For 1 ms */
	}
    
}

void LCD_enable()
{
    LCD_en = 0; /* Clear bit P2.4 */
    LCD_delay(1);
    LCD_en = 1; /* Set bit P2.4 */
}

void LCD_command(unsigned char command)
{
    LCD_rs = 0; /* Clear bit P2.5 */
    P0 = (P0 & 0xF0)|((command>>4) & 0x0F);
    LCD_enable();
    P0 = (P0 & 0xF0)|(command & 0x0F);
    LCD_enable();
    LCD_delay(1);
}

void LCD_putc(unsigned char ascii)
{
    LCD_rs = 1; /* Set bit P2.5 */
    P0 = (P0 & 0xF0)|((ascii>>4) & 0x0F);
    LCD_enable();
    P0 = (P0 & 0xF0)|(ascii & 0x0F);
    LCD_enable();
    LCD_delay(1);
}

void LCD_puts(unsigned char *lcd_string)
{
	while (*lcd_string) 
	{
		LCD_putc(*lcd_string++);
	}
}

void LCD_init()
{
    LCD_en = 1; /* Set bit P2.4 */
    LCD_rs = 0; /* Clear bit P2.5 */
	rw=0;   
    LCD_command(0x33);
    LCD_command(0x32);
    LCD_command(0x28);
    LCD_command(0x0C);
    LCD_command(0x06);
    LCD_command(0x01); /* Clear */
    LCD_delay(256);
}


i upload my project file including code & proteus simulation file. thanks in advance
 

Attachments

  • basic calculator.rar
    57.9 KB · Views: 107

put a pullup resistor on Port 0..
 
  • Like
Reactions: #MAAM#

    #MAAM#

    Points: 2
    Helpful Answer Positive Rating
You have to connect Pull at P0 otherwise it will not work
you get Resistor network of 8 resistors its 9pin component connect common pin to VCC and rest 8 pins to each port 0 pin
 
  • Like
Reactions: #MAAM#

    #MAAM#

    Points: 2
    Helpful Answer Positive Rating
put a pullup resistor on Port 0..
thanks... it works with me well now

You have to connect Pull at P0 otherwise it will not work
you get Resistor network of 8 resistors its 9pin component connect common pin to VCC and rest 8 pins to each port 0 pin
thanks for your advice
check if the data changes in port0... just to confirm port is working fine............
thanks the solution is to put a pull up resistor as mentioned before.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top