Read Bit / Write Bit

General discussion on mikroC for dsPIC30/33 and PIC24.
Post Reply
Author
Message
mercuryhg
Posts: 7
Joined: 22 Oct 2009 08:31

Read Bit / Write Bit

#1 Post by mercuryhg » 23 Nov 2009 11:51

hi there,
I wanted to read 1 bit and write 1 bit of the onewire device to get the onewire search algorithm to work. Is there anyway to read 1 bit instead of reading 1 byte with the built-in ow_read function? It would be helpful if i can get a working onewire search algorithm code too. Thanks.

Sobrietytest
Posts: 619
Joined: 05 Jul 2008 06:05
Location: Thailand

#2 Post by Sobrietytest » 07 Dec 2009 06:14

Provided you know the bit you want to read, you can use standard boolean arithmatic. For example, if you want to know the state of bit 4 of a byte (7:0) read from the OW line...

Code: Select all

// Read a byte from the One-Wire Bus connected to pin RF6
unsigned short read_data;
unsigned short status;

read_data = Ow_Read(&PORTF, 6);

status = read_data & 0b00010000;

Therefore 'status' will either equal zero if the bit isn't set or 16 if it is.


ST

Post Reply

Return to “mikroC for dsPIC30/33 and PIC24 General”