[General] Writing to MCU data port

Status
Not open for further replies.

hithesh123

Full Member level 6
Joined
Nov 21, 2009
Messages
324
Helped
1
Reputation
2
Reaction score
1
Trophy points
1,298
Location
lax
Visit site
Activity points
3,548
I have a char array of parity bits, to be written to MCU port out.
The MCU port is called data1. I am trying to write array[2] to data1

data1=array[2];

array[2]='0' , But when I step thru the code, data1 becomes 1 after the above assignment.
I have both 0s and 1s in the array. But no matter what the array index is, data1 always becomes 1 after I execute
data1=array[2];
Can 'char' data type be assigned to port pins?
 


Code C - [expand]
1
2
3
4
5
6
7
8
9
mask = 0x01
for(i = 0; i < 8; i++){
    if(array[2] & mask)
        data1 = 1;
    else
        data1 = 0;
    
    mask = mask << 1;
}




Code C - [expand]
1
2
3
4
5
6
mask = 0x01
for(i = 0; i < 8; i++){
    (array[2] & mask)? data1 = 1 : data1 = 0;
    
    mask = mask << 1;
}

 
Last edited:

Status
Not open for further replies.

Similar threads

Cookies are required to use this site. You must accept them to continue using the site. Learn more…