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.

pl explain this to me (89s52 c code)

Status
Not open for further replies.

lgeorge123

Full Member level 2
Joined
Jun 13, 2004
Messages
130
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,296
Location
Hong Kong
Activity points
1,403
i have the following code from somewhere and tried to transfer to pic18f452 so i have to understand the code first.
void WriteByte()
{
uchar k;
for(k=0;k<8;k++)
{
dat=dat<<1;
R1=CY;
R2=1;
CLK=0;
CLK=1;
}
}

I guess the code is transfer the 7th bit of dat to R1 until all of the dat is done , am I correct ????
 

I think "CY" is the 89s52's carry flag,
so R1 receive all "dat" bits (from msb to lsb)

because whe can suppose
dat << 1 shift the msb bit to carry but this is absolutly not portable,
this a 89s52 or compiler trick

You need to examine the generated code
to see if this can work with the pic18F
 

You could achieve the same result using this code snippet.

Code:
uchar k;
uchar dat;


for(k = 0;  k < 8; k++) /* MSB first */
    {
    DATA_OUT = ((dat << k) & 0x80U) ? 1 : 0; 

    CLOCK = 0;
    CLOCK = 1;
    }
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top