Code: Select all
dim loop as byte
dim temp_longword as longword
while loop<32'a longword is being accessed a bit at a time
if temp_longword.loop=1 then
'do something here
endif
inc(loop)
wend
Moderators: David Barker, Jerry Messina
Code: Select all
dim loop as byte
dim temp_longword as longword
while loop<32'a longword is being accessed a bit at a time
if temp_longword.loop=1 then
'do something here
endif
inc(loop)
wend
Code: Select all
dim loop as byte
dim temp_longword as longword
loop = 0
while loop < 32'a longword is being accessed a bit at a time
if temp_longword.Bits(loop)=1 then
'do something here
endif
inc(loop)
wend
Code: Select all
{
****************************************************************
* Name : BIT_lib.BAS *
* Author : Florin Andrei Medrea *
* Notice : Copyright (c) 2007 - YO2LIO - *
* : All Rights Reserved *
* Date : 10/5/2007 *
* Version : 1.0 *
* Notes : Library for accesing individual bits *
* : *
****************************************************************
}
Module BIT_lib
Include "SYS_lib"
Dim gen_buf As Word
Sub ClearB(bit_pos As Byte)
Save(FSR2)
FSR2 = gen_buf
bit_pos = bit_pos And $07
bit_pos = GetMask(bit_pos)
ASM
comf bit_pos,w
andwf INDF2,f
End ASM
Restore
End Sub
Sub SetB(bit_pos As Byte)
Save(FSR2)
FSR2 = gen_buf
bit_pos = bit_pos And $07
bit_pos = GetMask(bit_pos)
ASM
movf bit_pos,w
iorwf INDF2,f
End ASM
Restore
End Sub
Sub TestB(bit_pos As Byte)
Save(FSR2)
FSR2 = gen_buf
bit_pos = bit_pos And $07
bit_pos = GetMask(bit_pos)
ASM
movf bit_pos,w
andwf INDF2,w
End ASM
Restore
End Sub
Public Sub ClearBit(ByRef data As Byte, bit_pos As Byte)
gen_buf = AddressOf(data)
ClearB(bit_pos)
End Sub
Public Sub SetBit(ByRef data As Byte, bit_pos As Byte)
gen_buf = AddressOf(data)
SetB(bit_pos)
End Sub
Public Function TestBit(ByRef data As Byte, bit_pos As Byte) As Byte
result = 0
gen_buf = AddressOf(data)
TestB(bit_pos)
If WREG <> 0 Then Inc(result) End If
End Function
Public Sub ClearBit(ByRef data As ShortInt, bit_pos As Byte)
gen_buf = AddressOf(data)
ClearB(bit_pos)
End Sub
Public Sub SetBit(ByRef data As ShortInt, bit_pos As Byte)
gen_buf = AddressOf(data)
SetB(bit_pos)
End Sub
Public Function TestBit(ByRef data As ShortInt, bit_pos As Byte) As Byte
result = 0
gen_buf = AddressOf(data)
TestB(bit_pos)
If WREG <> 0 Then Inc(result) End If
End Function
Public Sub ClearBit(ByRef data As Word, bit_pos As Byte)
ASM
rlncf bit_pos,w
swapf WREG,f
andlw 3
End ASM
gen_buf = AddressOf(data) + WREG
ClearB(bit_pos)
End Sub
Public Sub SetBit(ByRef data As Word, bit_pos As Byte)
ASM
rlncf bit_pos,w
swapf WREG,f
andlw 3
End ASM
gen_buf = AddressOf(data) + WREG
SetB(bit_pos)
End Sub
Public Function TestBit(ByRef data As Word, bit_pos As Byte) As Byte
result = 0
ASM
rlncf bit_pos,w
swapf WREG,f
andlw 3
End ASM
gen_buf = AddressOf(data) + WREG
TestB(bit_pos)
If WREG <> 0 Then Inc(result) End If
End Function
Public Sub ClearBit(ByRef data As Integer, bit_pos As Byte)
ASM
rlncf bit_pos,w
swapf WREG,f
andlw 3
End ASM
gen_buf = AddressOf(data) + WREG
ClearB(bit_pos)
End Sub
Public Sub SetBit(ByRef data As Integer, bit_pos As Byte)
ASM
rlncf bit_pos,w
swapf WREG,f
andlw 3
End ASM
gen_buf = AddressOf(data) + WREG
SetB(bit_pos)
End Sub
Public Function TestBit(ByRef data As Integer, bit_pos As Byte) As Byte
result = 0
ASM
rlncf bit_pos,w
swapf WREG,f
andlw 3
End ASM
gen_buf = AddressOf(data) + WREG
TestB(bit_pos)
If WREG <> 0 Then Inc(result) End If
End Function
Public Sub ClearBit(ByRef data As LongWord, bit_pos As Byte)
ASM
rlncf bit_pos,w
swapf WREG,f
andlw 3
End ASM
gen_buf = AddressOf(data) + WREG
ClearB(bit_pos)
End Sub
Public Sub SetBit(ByRef data As LongWord, bit_pos As Byte)
ASM
rlncf bit_pos,w
swapf WREG,f
andlw 3
End ASM
gen_buf = AddressOf(data) + WREG
SetB(bit_pos)
End Sub
Public Function TestBit(ByRef data As LongWord, bit_pos As Byte) As Byte
result = 0
ASM
rlncf bit_pos,w
swapf WREG,f
andlw 3
End ASM
gen_buf = AddressOf(data) + WREG
TestB(bit_pos)
If WREG <> 0 Then Inc(result) End If
End Function
Public Sub ClearBit(ByRef data As LongInt, bit_pos As Byte)
ASM
rlncf bit_pos,w
swapf WREG,f
andlw 3
End ASM
gen_buf = AddressOf(data) + WREG
ClearB(bit_pos)
End Sub
Public Sub SetBit(ByRef data As LongInt, bit_pos As Byte)
ASM
rlncf bit_pos,w
swapf WREG,f
andlw 3
End ASM
gen_buf = AddressOf(data) + WREG
SetB(bit_pos)
End Sub
Public Function TestBit(ByRef data As LongInt, bit_pos As Byte) As Byte
result = 0
ASM
rlncf bit_pos,w
swapf WREG,f
andlw 3
End ASM
gen_buf = AddressOf(data) + WREG
TestB(bit_pos)
If WREG <> 0 Then Inc(result) End If
End Function
Public Sub ClearBitArray(ByRef data() As Byte, byte_pos As Word, bit_pos As Byte)
gen_buf = AddressOf(data) + byte_pos
ClearB(bit_pos)
End Sub
Public Sub SetBitArray(ByRef data() As Byte, byte_pos As Word, bit_pos As Byte)
gen_buf = AddressOf(data) + byte_pos
SetB(bit_pos)
End Sub
Public Function TestBitArray(ByRef data() As Byte, byte_pos As Word, bit_pos As Byte) As Byte
result = 0
gen_buf = AddressOf(data) + byte_pos
TestB(bit_pos)
If WREG <> 0 Then Inc(result) End If
End Function
Public Sub ClearBitArray(ByRef data As String, byte_pos As Word, bit_pos As Byte)
gen_buf = AddressOf(data) + byte_pos
ClearB(bit_pos)
End Sub
Public Sub SetBitArray(ByRef data As String, byte_pos As Word, bit_pos As Byte)
gen_buf = AddressOf(data) + byte_pos
SetB(bit_pos)
End Sub
Public Function TestBitArray(ByRef data As String, byte_pos As Word, bit_pos As Byte) As Byte
result = 0
gen_buf = AddressOf(data) + byte_pos
TestB(bit_pos)
If WREG <> 0 Then Inc(result) End If
End Function
Code: Select all
{
****************************************************************
* Name : SYS_lib.bas *
* Author : Florin Andrei Medrea *
* Notice : Copyright (c) 20067 - YO2LIO - *
* : All Rights Reserved *
* Date : 28/10/2007 *
* Version : 1.1 *
* Notes : *
* : *
****************************************************************
}
Module SYS_lib
{
****************************************************************************
* Name : ClrWDT *
* Purpose : Clear the watch dog timer *
****************************************************************************
}
Public Inline Sub ClrWDT()
ASM-
ClrWDT
End ASM
End Sub
{
****************************************************************************
* Name : Nop *
* Purpose : Single NOP instruction *
****************************************************************************
}
Public Inline Sub Nop()
ASM-
Nop
End ASM
End Sub
{
****************************************************************************
* Name : Reset *
* Purpose : Reset instruction *
****************************************************************************
}
Public Inline Sub Reset()
ASM-
Reset
End ASM
End Sub
{
****************************************************************************
* Name : Sleep *
* Purpose : Sleep instruction *
****************************************************************************
}
Public Inline Sub Sleep()
ASM-
Sleep
End ASM
End Sub
{
****************************************************************************
* Name : Swap_F *
* Purpose : Swapf instruction (exchange the upper and lower *
* nibbles of register ‘f’) *
****************************************************************************
}
Public Inline Function Swap_F(data_b As Byte) As Byte
ASM-
Swapf data_b,w
End ASM
result = WREG
End Function
{
****************************************************************************
* Name : Neg_F *
* Purpose : Negf instruction ('f' is negated using two’s complement *
****************************************************************************
}
Public Inline Function Neg_F(data_b As Byte) As Byte
ASM-
Negf data_b,w
End ASM
result = WREG
End Function
{
****************************************************************************
* Name : SetBank *
* Purpose : Set memmory bank *
****************************************************************************
}
Public Inline Sub SetBank(data_b As Byte)
ASM-
Movlb data_b
End ASM
End Sub
{
****************************************************************************
* Name : Daw_F *
* Purpose : Adjusts the eight-bit value in W *
* resulting from the earlier addition of two *
* variables (each in packed BCD format) *
* and produces a correct packed BCD *
****************************************************************************
}
Public Inline Function Daw_F(data_b As Byte) As Byte
ASM-
movf data_b,w
daw
End ASM
result = WREG
End Function
{
****************************************************************************
* Name : GetMask *
* Purpose : Get mask of bit 0 - 7 *
****************************************************************************
}
Public Function GetMask(data As Byte) As Byte
Dim i As Byte
result = 1
i = 0
While i < data
ASM
Rlncf result,f
End ASM
Inc(i)
Wend
End Function
Code: Select all
Public Inline Function Swap_F(data_b As Byte) As Byte
ASM-
Swapf data_b,w
End ASM
result = WREG
End Function
Code: Select all
Public Inline Function Swap_F(data_b As Byte) As WREG
ASM-
Swapf data_b,w
End ASM
End Function
Thanks XORxor wrote:Swordfish is really a slick tool!