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.

Help in writing code for 89c51

Status
Not open for further replies.

sam_kevin

Junior Member level 1
Joined
Jan 21, 2013
Messages
16
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,429
Hi Friends

can you please guide me for writing code on 89c51 mcu, I designed the whole circuit, but programming mcu is new to me.

The instruction list is listed below

Instruction list for programming 89c51 microcontroller

Case-1​
1. Port – 0 and Port – 2 is used in this project, all 8 pins of port 0 is assigned as input and all 8 pins of port – 2 is assigned as output
2. When the microcontroller is powered ON, all pins of port 0 and 2 should be pulled to low.
3. Port -0.0 (pin no 39) will act as a main switch, If Port -0.0 becomes high, then port – 0.1, 0.2, 0.3, 0.4, 0.5, 0.6 and Port – 2.0, 2.1, 2.2, 2.3, 2.4, 2.5, 2.6 should pulled to high. But P-0.7 and P 2.7 will remain low.
4. While Input P0.0 remains in high status, When Input P0.1 gets low pulse then output P2.1 should pulled to low permanently, and there should be no effect occurred on P2.1 even when input P0.1 keeps changing its status (low or high)
5. Step 4 will be applied for input P (0.1 to 0.6), (Input P 0.1 will drive output P 2.1, Input P 0.2 will drive output p2.2........................... and Input P 0.6 will drive output P 2.6 )
6. Finally P2.0 will turn low when all the output pins from P 2.1 to 2.6 gets low. Till then P 2.0 will remain in high status

Case-2​
1. When Input P0.0 becomes low, all the pins of port 0 and port 2 should be pulled to low except P0.7, P2.0 and P2.7 should remain high.
2. While Input P0.0 remains Low, When Input P0.7 gets low pulse then output P2.7 should pulled to low permanently, and there should be no effect occurred on P2.7 even when input P0.7 keeps changing its status (low or high)
3. Once p2.7 pulled to low, immediately p2.0 should pulled to low.
 

jayanth.devarayanadurga : I want to write it in "C"
 

Explain this.

Port -0.0 (pin no 39) will act as a main switch, If Port -0.0 becomes high, then port – 0.1, 0.2, 0.3, 0.4, 0.5, 0.6 and Port – 2.0, 2.1, 2.2, 2.3, 2.4, 2.5, 2.6 should pulled to high

P0 is input port. How can you make it high? You can make it high if it is an output port or pin.
 

you can start by using keil software and any problem you faced we can help you
 

Explain this.



P0 is input port. How can you make it high? You can make it high if it is an output port or pin.

Sorry, it's my fault, I goggled and came to know, if a port need to made as an input then it has to initialized as 1.

Now please guide me If a port is made high for input, then how could i sense that port is receiving high signal ?
 

Sorry, it's my fault, I goggled and came to know, if a port need to made as an input then it has to initialized as 1.

Now please guide me If a port is made high for input, then how could i sense that port is receiving high signal ?


Code:
P0=0xFF; // P0 is a input port
P0=0x00;// to clear the value in port now it ready to get input high signal.

by using this you can sense the input value.

best regards
 

Hello friends,

I worked out on my point no 1,2 and 3. below is my Code, kindly CheCk it.

#include<stdio.h>
#include <REG51.H>
sbit Ign = P0^0;

void main()

{
P0= 0xff;
P2= 0x00;

{
if (Ign ==1)

P2=0x7f;
}
}

Now please guide me on point 4,5 and 6.



Thanks
 

you have two missing statement. look at this code

Code:
#include<stdio.h>
#include <REG51.H>
sbit Ign = P0^0;

void main()

{  
P0= 0x00; //port 0 pulled to low
P2= 0x00;
	
if (Ign ==1)
{
        P0= 0x7f;  
        P2= 0x7f;	 	
}
}

complete other points and we will review
 
Dear #MAAM#:

In you code P0 is assigned as input or output port ?? Can you please guide me what kind of statement i should use to check each bit of port 0 and make port 2 low (point no 4, 5 and 6)
 

Dear #MAAM#:

In you code P0 is assigned as input or output port ?? Can you please guide me what kind of statement i should use to check each bit of port 0 and make port 2 low (point no 4, 5 and 6)

Dear sam_kevin:

In 8051 family there is no assignment of input or output in port. I mean it's bidirectional port you can refer to datasheet about this point.

example:

if you need to make port 1 as output

Code:
P1=0x7f; //random value it's only example about output

if you need to make port 1 as input

Code:
variable=P1; //variable it's only variable to saves the value from the Port1
 
Thank you MAAM,

I'm totally blank for proceeding with point no 4,5 and 6.

how can I check each bit of Po low and make P2 individual bit low, and if p2 is 0x01 then automatically P2 should be 0x00 Please guide.
 

Is thi.s correct ?

code:

#include<stdio.h>
#include <REG51.H>
sbit Ign = P0^0;
int a, b;

void main()

{
P0= 0x00; //port 0 pulled to low
P2= 0x00;

while (1)

if (Ign ==1)
{
P0= 0x7f;
a = P0;
P2= 0x7f;
b = P2;

while (1)
{
b = a;
}
}
}
 

This is meaningless.

Port -0.0 (pin no 39) will act as a main switch, If Port -0.0 becomes high, then port – 0.1, 0.2, 0.3, 0.4, 0.5, 0.6 and Port – 2.0, 2.1, 2.2, 2.3, 2.4, 2.5, 2.6 should pulled to high.

If P0 is input pins then no need to pull them high through code.

Fix the error and explain how you want your program to work. I will write a code.
 
your points are confusing. please review what you want exactly to help you
 
Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top