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.

8051 port mapping to variables

Status
Not open for further replies.

jovin555

Advanced Member level 4
Joined
May 20, 2012
Messages
115
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,296
Activity points
2,036
how is it possible to map a port in 8051 to a variable and also its bits to the variables bits?and also i need to store the lower nibble of port bits to the variables higher nibble and vice versa?how to implement this in kiel?can anyone give me the code?for port0 and variable 'var' ,i want to store P0^0-P0^4 in Var^4-Var^7 and vice versa.
 

If you are using C programming,

We have a command Sbit

Its syntax is as follows:-
sbit <variable name> = <port>

Example:- sbit var = P1^0
 

The port registers P0 to P2 are already defined in reg51.h and you can access it in C expressions. This should answer your question about nibble access, simply think about C shift and bit masking operations.

For an optimal implementation you may want to utilize the SWAP A assembly instruction, no idea if the compiler can infer it on it's own.
 

If you are using C programming,

We have a command Sbit

Its syntax is as follows:-
sbit <variable name> = <port>

Example:- sbit var = P1^0

Yes,you are right!But don't miss ";"after"sbit var = P1^0"
 

but i need to use lik this
var = P0;
var^0=P0^7;
var^1=P0^6;
Lik dat.is dat possible?
 

but i need to use lik this
var = P0;
var^0=P0^7;
var^1=P0^6;
Lik dat.is dat possible?

No bro, thats not possible.
Atleast you will have to define first that you are assigning a PORT to any variable.
Otherwise how will the compiler know.
 
then is it possible to declare a variable at a particular address and then initialize it with port values.
unsigned char var _at_ 0x20;
sbit var^0 = P0^7; or
#define var^0 P0^7.

is it possible to do anything like this?
 

The language constructs supported by the Keil compiler can be differentiated in tow categories:
- generic C syntax, as described in your C text book
- Language Extensions discussed in the Keil manual, e.g. sbit

The constructs suggested in your latest posts are covered by none of both categories.

sbit e.g. is restricted to bit addressable SFRs and bdata variables. Please review the Bit-addressable Objects paragraph in the compiler manual. Bit addressable objects can be copied to each other, but not the way you did.

You probably can make your life much easier by telling what you exactly want to achieve rather than trying arbitrary language constructs.
 

I did a code for LCD 4 bit.So i want to initialize the port pins use for LCD at the beginning of the code itself.and then copy the address of that pins to the lower nibble or upper nibble of a variable.So while writing to the LCD i just need to write the value of that variable.i think all of you might have understood my aim. And i like to make a header for that LCD and just change the pins if i want to use it for another project.
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top