Code: Select all
{
****************************************************************
* Name : Util.BAS *
* Author : Medrea Florin Andrei *
* Notice : Copyright (c) 2007 -YO2LIO- *
* : All Rights Reserved *
* Date : 9/27/2007 *
* Version : 1.0 *
* Notes : *
* : *
****************************************************************
}
Module Util
Public Sub ClearBit(ByRef data As Byte, pos As Byte)
Dim Pin_,PinMask_ As Byte
FSR2 = AddressOf(data)
Pin_ = 1 << pos
PinMask_ = Not(Pin_)
INDF2 = INDF2 And PinMask_
End Sub
Public Sub SetBit(ByRef data As Byte, pos As Byte)
Dim Pin_ As Byte
FSR2 = AddressOf(data)
Pin_ = 1 << pos
INDF2 = INDF2 Or Pin_
End Sub
Public Function TestBit(ByRef data As Byte, pos As Byte) As Byte
Dim Pin_ As Byte
FSR2 = AddressOf(data)
Pin_ = 1 << pos
If (INDF2 And Pin_) > 0 Then result = 1
Else result = 0 End If
End Function
Public Sub MemCpy(addr1, addr2, len As Word)
Dim i As Word
FSR1 = addr1
FSR2 = addr2
i = 0
While i < len
POSTINC1 = POSTINC2
Inc(i)
Wend
End Sub
Public Function MemCmp(addr1, addr2, len As Word) As Byte
Dim i As Word
FSR1 = addr1
FSR2 = addr2
i = 0
result = $FF
While i < len
If POSTINC1 <> POSTINC2 Then Exit End If
Inc(i)
Wend
result = 0
End Function
ClearBit(PORTC,5) // Clear bit 5 from PORTC
SetBit(PORTC,5) // Set bit 5 from PORTC
res = TestBit(PORTC,5) // Test bit 5 from PORTC, return 0 or 1
MemCpy(@data1, @data2, 100) // Copies 100 bytes from the memory area starting at the address data2 to data1.
res = MemCmp(@data1, @data2, 100) // Compare 2 parts from memory area starting at the address data2 and data1, return 0 if it's the same, else 255.