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.

Proteus - Logic contentions detected

Status
Not open for further replies.

Jeffrey Peter

Member level 5
Joined
Aug 28, 2011
Messages
82
Helped
1
Reputation
2
Reaction score
1
Trophy points
1,288
Location
Tirunelveli,Tamill Nadu, India
Activity points
1,802
Hi, I'm getting the logic contentions detected error in Proteus. This program is a simple 8051 and LCd interfacing program written in Keil. What could be the problem ?
Thanks in advance
HTML:
#include<at89x51.h>
#define TRUE 1
#define cmdport P3
#define dataport P2	   

sbit rs = cmdport^0;  //register select pin
sbit rw = cmdport^1;  // read write pin
sbit e = cmdport^6;  //enable pin
sbit LED = P1^7;
sbit BF= dataport^7; //Busy Flag

void led_blink() 
{
	LED=~LED;
}
void delay_msec(unsigned int msec) //Delay function
{
	unsigned int i,j;
	LED = TRUE;	
	for(i=0;i<msec;i++)
	for(j=0;j<1250;j++)
	{
		led_blink();
	}
}
void lcd_busy()	 //Check Busy Flag
{
	BF = 1;
	e = 1;
	rs = 0;
	rw = 1;
	while(BF)
	{
		e=0;
		delay_msec(2);
		e=1;
	}
}
void lcd_cmd(unsigned char item)  //Function to send command to LCD
{
	dataport = item;
	rs= 0;
	rw=0;
	e=1;
	delay_msec(1);
	e=0;
	lcd_busy();
}
void lcd_data(unsigned char item)  //Function to send data to LCD
{
	dataport = item;
	rs= 1;
	rw=0;
	e=1;
	delay_msec(1);
	e=0;
	lcd_busy();
}

void lcd_time(unsigned char *lcddata)	//Displays a string in lcd
{
	unsigned int LCDL1=0x80;
	while(*lcddata)
	{
		LCDL1++;
		lcd_cmd(LCDL1);    //Set cursor to blink at line 1 positon 1
		lcd_data(*lcddata++);
	}		
}

void lcd_ini(unsigned char *lcddata)  //Function to initialize LCD
{
	lcd_cmd(0x38);    // Configuring settings to 8-bit 2 row 
	lcd_cmd(0x0E); 	   // turn display ON for cursor blinking
	lcd_cmd(0x06);    //Display on
	lcd_cmd(0x81);    //Set cursor to blink at line 1 positon 1
	lcd_time(lcddata);
	//lcd_data('a');
	//delay_msec(100);
}

void main()
{
	unsigned short int LCDL1=0x80;
	unsigned short int LCDL2=0xc0;
	unsigned char *lcdtime="Good Work";
	lcd_ini(lcdtime);
	while(1)
   	{	
		delay_msec(1);
	}
}
Capture.PNG
 

Check with this .dsn file.
 

Attachments

  • 89C52.rar
    12 KB · Views: 44

I got the same error... In this program I started to get the error when I replaced by delay call statements with lcd_busy statement. I did this to get accurate delays
 

I think it has to do something with 8 bit LCD or 4 bit LCD. Is your code for 8 bit LCD?

Just comment out the 2
Code:
 lcd_busy();
statements. It will work fine.
 

Attachments

  • ss40.jpg
    ss40.jpg
    236.6 KB · Views: 151
Last edited:

Mine is 8 bit mode...
HTML:
void lcd_busy()	 //Check Busy Flag
{
	BF = 1;
	e = 1;
	rs = 0;
	rw = 1;
	while(BF)
	{
		e=0;
		//delay_msec(2);
		e=1;
		//delay_msec(2);
	}
}
Yeah if I'm using delay instead of this lcd_busy function its working fine. To be more accurate the error is occurring within the while loop... I found this example in the site https://www.8051projects.net/lcd-interfacing/busyflag.php
 

Try using
Code:
 void LCD_busy()
{
         unsigned char i,j;
         for(i=0;i<50;i++)        //A simple for loop for delay
            for(j=0;j<255;j++);
}

for LCD_busy(). See if it works
 

Hi;
I'm not familiar with this proc neither the Keil C, but:

- to examine the Busy flag you must read the LCD datas, using an input port!
- other LCD commands write the LCD datas, using an output port.

So if you set the LCD - via its RS and RW pins, in lcd_busy() - to a read state, all LCD data pins will be outputs while you apply an E pulse.
This occurs a logic contentions error (in Proteus too), because outputs are connected to each other.

Solution:
before testing of the busy_flag simply set your port P2 to input, then - after success, before return - switch back it to its original (output) state, all inside the lcd_busy().

Sorry for my poor English, hope you understand and it helps you
zuisti
PS.
The example you pointed in the net is also wrong, in my humble opinion.
 

Pls tell me the step to change P2 as input/ output....

Please refer to your proc's datasheet about the "data direction register" (like DDR ?)

Look at this site:
**broken link removed**

But sorry if here is not a "data direction register", as I wrote I don't know your processor ...
 
Last edited:

Please refer to your proc's datasheet about the "data direction register" (like DDR ?)

Look at this site:
**broken link removed**

But sorry if here is not a "data direction register", as I wrote I don't know your processor ...


There is no direction settings in 8051/52
 

So 8051 has bidirectional ports... Still the problem persists.

I can't use delay because the I have to find the exact time taken for the LCD to execute the instructions....
 

Pls tell me the step to change P2 as input/ output....

Yes, I also see now (after I checked the datasheet), there is no direction settings in 8051/52.
If you want to use the P2 as an input port, simply write to the P2 the value FFh (255 dec), to switch off the pull_down mosfets.

Add this instruction to your lcd_busy routine (to begin):
dataport = 255; // P2 = 255, all bits set to 1

From the datasheet:

Port 2 is an 8-bit quasi bi-directional I/O port with internal pullups.
The Port 2 output buffers can sink/source four TTL inputs. When 1s are written to Port 2 pins, they are pulled high by
the internal pullups and can be used as inputs
. As inputs, Port 2 pins that are externally being pulled low will source
current (IIL) because of the internal pullups.


Try it!
zuisti
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top