- •Table of Contents
- •Index
- •Keyword Reference
- •Installation
- •Installation of BASCOM
- •BASCOM IDE
- •Running BASCOM-AVR
- •File New
- •File Close
- •File Save
- •File Save As
- •File Print Preview
- •File Print
- •File Exit
- •View PinOut
- •View PDF viewer
- •View Error Panel
- •Edit Undo
- •Edit Redo
- •Edit Cut
- •Edit Copy
- •Edit Paste
- •Edit Find
- •Edit Find Next
- •Edit Replace
- •Edit Goto
- •Edit Toggle Bookmark
- •Edit Goto Bookmark
- •Edit Indent Block
- •Edit Unindent Block
- •Edit Remark Block
- •Program Compile
- •Program Syntax Check
- •Program Show Result
- •Program Simulate
- •Program Send to Chip
- •Tools Terminal Emulator
- •Tools LCD Designer
- •Tools LIB Manager
- •Tools Graphic Converter
- •Tools Stack Analyzer
- •Tools Plugin Manager
- •Tools Batch Compile
- •Options Compiler
- •Options Compiler Chip
- •Options Compiler Output
- •Options Compiler Communication
- •Options Compiler I2C, SPI, 1WIRE
- •Options Compiler LCD
- •Options Communication
- •Options Environment
- •Options Simulator
- •Options Programmer
- •Supported Programmers
- •ISP programmer
- •PG302 programmer
- •Sample Electronics cable programmer
- •KITSRUS Programmer
- •MCS Universal Interface Programmer
- •STK500 Programmer
- •Lawicel BootLoader
- •AVR ISP Programmer
- •USB-ISP Programmer
- •MCS Bootloader
- •Options Monitor
- •Options Printer
- •Window Cascade
- •Window Tile
- •Window Arrange Icons
- •Window Minimize All
- •Help About
- •Help Index
- •Help MCS Forum
- •Help MCS Shop
- •Help Support
- •Help Knowledge Base
- •Help Credits
- •BASCOM Editor Keys
- •Program Development Order
- •PlugIns
- •Font Editor
- •PinOut
- •BASCOM HARDWARE
- •Additional Hardware
- •AVR Internal Hardware
- •AVR Internal Registers
- •AVR Internal Hardware TIMER0
- •AVR Internal Hardware TIMER1
- •AVR Internal Hardware Watchdog timer
- •AVR Internal Hardware Port B
- •AVR Internal Hardware Port D
- •Adding XRAM
- •Attaching an LCD Display
- •Memory usage
- •Using the 1 WIRE protocol
- •Using the SPI protocol
- •Power Up
- •Chips
- •ATtiny22
- •ATtiny13
- •ATtiny15
- •ATtiny25
- •ATtiny45
- •ATtiny85
- •ATtiny26
- •ATtiny2313
- •ATMEGA8
- •ATMEGA16
- •ATMEGA32
- •ATMEGA48
- •ATMEGA88
- •ATMEGA168
- •ATMEGA64
- •ATMEGA103
- •ATMEGA128
- •ATMEGA161
- •ATMEGA162
- •ATMEGA163
- •ATMEGA165
- •ATMEGA169
- •ATMEGA323
- •ATMEGA603
- •ATMEGA8515
- •ATMEGA8535
- •BASCOM Language Fundamentals
- •Changes compared to BASCOM-8051
- •Language Fundamentals
- •Mixing ASM and BASIC
- •Assembler mnemonics
- •Reserved Words
- •Error Codes
- •Newbie problems
- •Tips and tricks
- •ASCII chart
- •BASCOM Language Reference
- •$BAUD
- •$BAUD1
- •$BOOT
- •$CRYSTAL
- •$DATA
- •$DEFAULT
- •$EEPLEAVE
- •$EEPROM
- •$EEPROMHEX
- •$EXTERNAL
- •$FRAMESIZE
- •$HWSTACK
- •$INCLUDE
- •$INITMICRO
- •$LCDPUTCTRL
- •$LCDPUTDATA
- •$LCDRS
- •$LCDVFO
- •$LOADER
- •$LOADERSIZE
- •$NOCOMP
- •$NOINIT
- •$NORAMCLEAR
- •$PROG
- •$PROGRAMMER
- •$REGFILE
- •$ROMSTART
- •$SERIALINPUT
- •$SERIALINPUT1
- •$SERIALINPUT2LCD
- •$SERIALOUTPUT
- •$SERIALOUTPUT1
- •$SWSTACK
- •$TIMEOUT
- •$TINY
- •$WAITSTATE
- •$XRAMSIZE
- •$XRAMSTART
- •1WIRECOUNT
- •1WRESET
- •1WREAD
- •1WSEARCHFIRST
- •1WSEARCHNEXT
- •1WVERIFY
- •1WWRITE
- •ACOS
- •ALIAS
- •ASIN
- •BASE64DEC
- •BASE64ENC
- •BAUD
- •BAUD1
- •BINVAL
- •BIN2GRAY
- •BITWAIT
- •BITS
- •BLOAD
- •BSAVE
- •BUFSPACE
- •BYVAL
- •CALL
- •CHECKSUM
- •CIRCLE
- •CLEAR
- •CLOCKDIVISION
- •CLOSE
- •CLOSESOCKET
- •CONFIG
- •CONFIG 1WIRE
- •CONFIG ACI
- •CONFIG ADC
- •CONFIG ATEMU
- •CONFIG BCCARD
- •CONFIG CLOCK
- •CONFIG CLOCKDIV
- •CONFIG COM1
- •CONFIG COM2
- •CONFIG COMx
- •CONFIG DATE
- •CONFIG DCF77
- •CONFIG DEBOUNCE
- •CONFIG I2CDELAY
- •CONFIG I2CSLAVE
- •CONFIG INPUT
- •CONFIG INTx
- •CONFIG GRAPHLCD
- •CONFIG KBD
- •CONFIG KEYBOARD
- •CONFIG LCD
- •CONFIG LCDBUS
- •CONFIG LCDMODE
- •CONFIG LCDPIN
- •CONFIG PORT
- •CONFIG PRINT
- •CONFIG PRINTBIN
- •CONFIG PS2EMU
- •CONFIG RC5
- •CONFIG SDA
- •CONFIG SCL
- •CONFIG SERIALIN
- •CONFIG SERIALIN1
- •CONFIG SERIALOUT
- •CONFIG SERIALOUT1
- •CONFIG SINGLE
- •CONFIG SPI
- •CONFIG SERVOS
- •CONFIG TCPIP
- •CONFIG TIMER0
- •CONFIG TIMER1
- •CONFIG TIMER2
- •CONFIG TWI
- •CONFIG TWISLAVE
- •CONFIG WAITSUART
- •CONFIG WATCHDOG
- •CONFIG X10
- •CONFIG XRAM
- •CONST
- •COSH
- •COUNTER0 and COUNTER1
- •CPEEK
- •CPEEKH
- •CRYSTAL
- •CURSOR
- •DATA
- •DAYOFWEEK
- •DAYOFYEAR
- •DATE$
- •DATE
- •DEBUG
- •DEBOUNCE
- •DECR
- •DECLARE FUNCTION
- •DECLARE SUB
- •DEFxxx
- •DEFLCDCHAR
- •DELAY
- •DISABLE
- •DISKFREE
- •DISKSIZE
- •DISPLAY
- •DO-LOOP
- •DriveCheck
- •DriveGetIdentity
- •DriveInit
- •DriveReset
- •DriveReadSector
- •DriveWriteSector
- •DTMFOUT
- •ECHO
- •ELSE
- •ENABLE
- •ENCODER
- •EXIT
- •FILEATTR
- •FILEDATE
- •FILEDATETIME
- •FILELEN
- •FILETIME
- •FLUSH
- •FORMAT
- •FOR-NEXT
- •FOURTHLINE
- •FRAC
- •FREEFILE
- •FUSING
- •GETADC
- •GETATKBD
- •GETATKBDRAW
- •GETDSTIP
- •GETDSTPORT
- •GETKBD
- •GETRC
- •GETRC5
- •GETTCPREGS
- •GETSOCKET
- •GLCDCMD
- •GLCDDATA
- •GOSUB
- •GOTO
- •GRAY2BIN
- •HEXVAL
- •HIGH
- •HIGHW
- •HOME
- •I2CINIT
- •I2CRECEIVE
- •I2CSEND
- •I2START,I2CSTOP, I2CRBYTE, I2CWBYTE
- •IDLE
- •IF-THEN-ELSE-END IF
- •INCR
- •INITFILESYSTEM
- •INITLCD
- •INKEY
- •INPUTBIN
- •INPUTHEX
- •INPUT
- •INSTR
- •ISCHARWAITING
- •KILL
- •LCASE
- •LCDAT
- •LCDCONTRAST
- •LEFT
- •LINE
- •LINE INPUT
- •LTRIM
- •LOAD
- •LOADADR
- •LOADLABEL
- •LOADWORDADR
- •LOCAL
- •LOCATE
- •LOOKDOWN
- •LOOKUP
- •LOOKUPSTR
- •LOWERLINE
- •MAKEBCD
- •MAKEINT
- •MAKEDEC
- •MAKETCP
- •MEMCOPY
- •NBITS
- •ON INTERRUPT
- •ON VALUE
- •OPEN
- •PEEK
- •POKE
- •POPALL
- •POWER
- •POWERDOWN
- •POWERSAVE
- •PRINTBIN
- •PSET
- •PS2MOUSEXY
- •PULSEIN
- •PULSEOUT
- •PUSHALL
- •RC5SEND
- •RC5SENDEXT
- •RC6SEND
- •READ
- •READEEPROM
- •READMAGCARD
- •RESET
- •RESTORE
- •RETURN
- •RIGHT
- •ROTATE
- •ROUND
- •RTRIM
- •SECELAPSED
- •SECOFDAY
- •SEEK
- •SELECT-CASE-END SELECT
- •SETFONT
- •SETTCP
- •SETTCPREGS
- •SENDSCAN
- •SENDSCANKBD
- •SERIN
- •SEROUT
- •SETIPPROTOCOL
- •SHIFT
- •SHIFTCURSOR
- •SHIFTIN
- •SHIFTOUT
- •SHIFTLCD
- •SHOWPIC
- •SHOWPICE
- •SINH
- •SOCKETCONNECT
- •SOCKETLISTEN
- •SOCKETSTAT
- •SONYSEND
- •SOUND
- •SPACE
- •SPIIN
- •SPIINIT
- •SPIMOVE
- •SPIOUT
- •SPLIT
- •START
- •STCHECK
- •STOP
- •STRING
- •SYSSEC
- •SYSSECELAPSED
- •SYSDAY
- •SWAP
- •TCPCHECKSUM
- •TCPREAD
- •TCPWRITE
- •TCPWRITESTR
- •TANH
- •THIRDLINE
- •TIME$
- •TIME
- •TOGGLE
- •TRIM
- •UCASE
- •UDPREAD
- •UDPWRITE
- •UDPWRITESTR
- •UPPERLINE
- •VARPTR
- •VERSION
- •WAIT
- •WAITKEY
- •WAITMS
- •WAITUS
- •WHILE-WEND
- •WRITE
- •WRITEEEPROM
- •X10DETECT
- •X10SEND
- •#IF ELSE ENDIF
- •International Resellers
- •International Resellers
- •ASM Libraries
- •EXTENDED I2C
- •MCSBYTE
- •MCSBYTEINT
- •TCPIP
- •LCD4BUSY
- •GLCD
- •GLCDSED
- •LCD-EPSON
- •AVR-DOS File System
- •CF Card
- •Compact FlashCard Driver
- •Elektor CF-Interface
- •XRAM CF-Interface for simulation
- •New CF-Card Drivers
- •Floating Point
- •FP_TRIG
- •DOUBLE
- •I2C SLAVE
- •I2CSLAVE
- •I2C TWI Slave
- •SPISLAVE
- •DATE TIME
- •EUROTIMEDATE
- •DATETIME
- •PS2-AT Mouse and Keyboard Emulation
- •AT_EMULATOR
- •PS2MOUSE_EMULATOR
- •BCCARD
- •BCCARD
- •BCDEF
- •BCCALL
- •BCRESET
- •Tools
- •LCD RGB-8 Converter
© MCS Electronics, 1995-2007
COUNTER0 and COUNTER1
Action
Set or retrieve the internal 16 bit hardware register.
Syntax
COUNTER0 = var |
TIMER0 can also be used |
var = COUNTER0 |
|
COUNTER1 = var |
TIMER1 can also be used |
var = COUNTER1 |
|
CAPTURE1 = var |
TIMER1 capture register |
var = CAPTURE1 |
|
COMPARE1A = var |
TIMER1 COMPARE A register |
var = COMPARE1A |
|
COMARE1B = var |
TIMER1 COMPARE B register |
var = COMPARE1B |
|
PWM1A = var |
TIMER1 COMPAREA register. (Is used for PWM) |
var = PWM1A |
|
PWM1B = var |
TIMER1 COMPARE B register. (Is used for PWM) |
var = PRM1B |
|
|
|
Remarks
Var |
A byte, Integer/Word variable or constant that is assigned to the register |
|
or is read from the register. |
|
|
Because the above 16 bit register pairs must be accessed somewhat differently than you may expect, they are implemented as variables.
The exception is TIMER0/COUNTER0, this is a normal 8 bit register and is supplied for compatibility with the syntax.
When the CPU reads the low byte of the register, the data of the low byte is sent to the CPU and the data of the high byte is placed in a temp register. When the CPU reads the data in the high byte, the CPU receives the data in the temp register.
When the CPU writes to the high byte of the register pair, the written data is placed in a temp register. Next when the CPU writes the low byte, this byte of data is combined with the byte data in the temp register and all 16 bits are written to the register pairs. So the MSB must be accessed first.
All of the above is handled automatically by BASCOM when accessing the above registers.
Note that the available registers may vary from chip to chip.
The BASCOM documentation used the 90S8515 to describe the different hardware registers.
CPEEK
page -407-
© MCS Electronics, 1995-2007
Action
Returns a byte stored in code memory.
Syntax
var = CPEEK( address )
Remarks
Var |
Numeric variable that is assigned with the content of the program memory |
|
at |
|
address |
Address |
Numeric variable or constant with the address location |
|
|
There is no CPOKE statement because you can not write into programmemory. Cpeek(0) will return the first byte of the file. Cpeek(1) will return the second byte of the binary file.
See also
PEEK , POKE , INP , OUT
Example
'----------------------------------------------------------------------------- |
|
------------ |
: peek.bas |
'name |
|
'copyright |
: (c) 1995-2005, MCS Electronics |
'purpose |
: demonstrates PEEk, POKE, CPEEK, INP and OUT |
'micro |
: Mega48 |
'suited for demo |
: yes |
'commercial addon needed |
: no |
'-----------------------------------------------------------------------------
------------
$regfile = "m48def.dat" |
' specify the used |
micro |
' used crystal |
$crystal = 4000000 |
|
frequency |
' use baud rate |
$baud = 19200 |
|
$hwstack = 32 |
' default use 32 |
for the hardware stack |
' default use 10 |
$swstack = 10 |
|
for the SW stack |
' default use 40 |
$framesize = 40 |
|
for the frame space |
|
Dim I As Integer , B1 As Byte |
|
'dump internal memory |
'only 32 registers |
For I = 0 To 31 |
|
in AVR |
'get byte from |
B1 = Peek(i) |
|
internal memory |
|
Print Hex(b1) ; " "; |
'write a value into memory |
'Poke I , 1 |
|
Next |
'new line |
'be careful when writing into internal memory !!
page -408-
|
© MCS Electronics, 1995-2007 |
'now dump a part ofthe code-memory(program) |
|
For I = 0 To 255 |
'get byte from |
B1 = Cpeek(i) |
|
internal memory |
"; |
Print Hex(b1) ; " |
|
Next |
|
'note that you can not write into codememory!! |
|
Out &H8000 , 1 |
'write 1 into XRAM |
at address 8000 |
'return value from |
B1 = Inp(&H8000) |
|
XRAM |
|
Print B1 |
|
End |
|
CPEEKH
Action
Returns a byte stored in upper page of code memory of micro with more then 64KB such as M103, M128.
Syntax
var = CPEEKH( address )
Remarks
Var |
Numeric variable that is assigned with the content of the program memory |
|
at |
|
address |
Address |
Numeric variable or constant with the address location |
|
|
CpeekH(0) will return the first byte of the upper 64KB.
Since the M103 has 64K words of code space the LPM nstruction can not access the 64 upper Kbytes.
The CpeekH() function peeks in the upper 64 KB.
This function should be used with the M103 or M128 only.
See also
PEEK , POKE , INP , OUT
Example
'----------------------------------------------------------------------------- |
|
------------ |
: peek.bas |
'name |
|
'copyright |
: (c) 1995-2005, MCS Electronics |
'purpose |
: demonstrates PEEk, POKE, CPEEK, INP and OUT |
'micro |
: Mega48 |
'suited for demo |
: yes |
'commercial addon needed |
: no |
'-----------------------------------------------------------------------------
------------
$regfile = "m48def.dat" |
' specify the used |
|
page -409- |
|
© MCS Electronics, 1995-2007 |
micro |
' used crystal |
$crystal = 4000000 |
|
frequency |
' use baud rate |
$baud = 19200 |
|
$hwstack = 32 |
' default use 32 |
for the hardware stack |
' default use 10 |
$swstack = 10 |
|
for the SW stack |
' default use 40 |
$framesize = 40 |
|
for the frame space |
|
Dim I As Integer , B1 As Byte
'dump internal memory
For I = 0 To 31 |
'only 32 registers |
in AVR |
'get byte from |
B1 = Peek(i) |
|
internal memory |
"; |
Print Hex(b1) ; " |
|
'Poke I , 1 |
'write a value into memory |
Next |
'new line |
'be careful when writing into internal memory !! |
|
'now dump a part ofthe code-memory(program) |
|
For I = 0 To 255 |
'get byte from |
B1 = Cpeek(i) |
|
internal memory |
"; |
Print Hex(b1) ; " |
|
Next
'note that you can not write into codememory!!
Out &H8000 , 1 |
'write 1 into XRAM |
at address 8000 |
'return value from |
B1 = Inp(&H8000) |
|
XRAM |
|
Print B1 |
|
End |
|
CRC8
Action
Returns the CRC8 value of a variable or array.
Syntax
Var = CRC8( source , L)
Remarks
Var |
The variable that is assigned with the CRC8 of variable source. |
Source |
The source variable or first element of the array to get the CRC8 of. |
L |
The number of bytes to check. |
|
|
CRC8 is used in communication protocols to check if there are no transmission errors. The 1wire for example returns a crc byte as the last byte from it’s ID.
The code below shows a VB function of crc8
page -410-
© MCS Electronics, 1995-2007
Function Docrc8(s As String) As Byte Dim j As Byte
Dim k As Byte Dim crc8 As Byte crc8 = 0
For m = 1 To Len(s)
x = Asc(Mid(s, m, 1)) For k = 0 To 7
j = 1 And (x Xor crc8)
crc8 = Fix(crc8 / 2) And &HFF x = Fix(x / 2) And &HFF
If j <> 0 Then
crc8 = crc8 Xor &H8C End If
Next k Next
Docrc8 = crc8 End Function
See also
CHECKSUM , CRC16, CRC32 , TCPCHECKSUM
ASM
The following routine is called from mcs.lib : _CRC8
The routine must be called with Z pointing to the data and R24 must contain the number of bytes to check.
On return, R16 contains the CRC8 value. The used registers are : R16-R19, R25.
;##### X = Crc8(ar(1) , 7) |
|
Ldi R24,$07 ; number of bytes |
|
Ldi R30,$64 |
; address of ar(1) |
Ldi R31,$00 ; load constant in register |
|
Rcall _Crc8 |
; call routine |
Ldi R26,$60 |
; address of X |
St X,R16 |
; store crc8 |
Example
$regfile = "m48def.dat" |
' specify the used |
micro |
' used crystal |
$crystal = 8000000 |
|
frequency |
' use baud rate |
$baud = 19200 |
|
$hwstack = 32 |
' default use 32 |
for the hardware stack |
' default use 10 |
$swstack = 10 |
|
for the SW stack |
' default use 40 |
$framesize = 40 |
|
for the frame space |
|
Config Com1 = Dummy , Synchrone = 0 , Parity = None , Stopbits = 1 , Databits = 8 , Clockpol = 0
page -411-
© MCS Electronics, 1995-2007
Dim Ar(10) As Byte
Dim J As Byte
Ar(1) = 1
Ar(2) = 2
Ar(3) = 3
J = Crc8(ar(1) , 3) |
'calculate value |
which is 216 |
|
Print J |
|
End |
|
CRC16
Action
Returns the CRC16 value of a variable or array.
Syntax
Var = CRC16( source , L)
Remarks
Var |
The variable that is assigned with the CRC16 of variable source. Should be a |
|
word or integer variable. |
Source |
The source variable or first element of the array to get the CRC16 value from. |
L |
The number of bytes to check. |
|
|
CRC16 is used in communication protocols to check if there are no transmission errors. The 1wire for example returns a crc byte as the last byte from it’s ID.
Use CRC8 for the 1wire routines.
There are a lot of different CRC16 routines. There is no real standard since the polynomial will vary from manufacture to manufacture.
The equivalent code in VB is shown below. There are multiple ways to implement it in VB. This is one of them.
VB CRC16 Sample
Private Sub Command1_Click()
Dim ar(10) As Byte
Dim b As Byte
Dim J As Integer
ar(1) = 1 ar(2) = 2 ar(3) = 3
b = Docrc8(ar(), 3) ' call funciton Print b
'calculate value which is 216
page -412-
© MCS Electronics, 1995-2007
J = CRC16(ar(), 3) ' call function
Print J
End Sub
Function Docrc8(ar() As Byte, bts As Byte) As Byte Dim J As Byte
Dim k As Byte Dim crc8 As Byte crc8 = 0
For m = 1 To bts
x = ar(m)
For k = 0 To 7
J = 1 And (x Xor crc8)
crc8 = Fix(crc8 / 2) And &HFF x = Fix(x / 2) And &HFF
If J <> 0 Then
crc8 = crc8 Xor &H8C End If
Next k Next
Docrc8 = crc8 End Function
'*****************************************************************
Public Function CRC16(buf() As Byte, lbuf As Integer) As Integer Dim CRC1 As Long
Dim b As Boolean CRC1 = 0 ' init CRC
For i = 1 To lbuf ' for each byte CRC_MSB = CRC1 \ 256 crc_LSB = CRC1 And 255 CRC_MSB = CRC_MSB Xor buf(i)
CRC1 = (CRC_MSB * 256) + crc_LSB
For J = 0 To 7 Step 1 ' for each bit
CRC1 = shl(CRC1, b)
If b Then CRC1 = CRC1 Xor &H1021
Next J
Next i
CRC16 = CRC1
End Function
'Shift Left function
Function shl(n As Long, ByRef b As Boolean) As Long Dim L As Long
L = n
L = L * 2
If (L > &HFFFF&) Then b = True
Else
b = False End If
shl = L And &HFFFF& End Function
page -413-
© MCS Electronics, 1995-2007
See also
CHECKSUM , CRC8, CRC32 , TCPCHECKSUM
ASM
The following routine is called from mcs.lib : _CRC16
The routine must be called with X pointing to the data. The soft stack–Y must contain the number of bytes to scan.
On return, R16 and R17 contain the CRC16 value. The used registers are : R16-R19, R25.
;##### X = Crc16(ar(1) , 7) |
|
Ldi R24,$07 ; number of bytes |
|
St –y, R24 |
|
Ldi R26,$64 ; address of ar(1) |
|
Ldi R27,$00 ; load constant in register |
|
Rcall _Crc16 |
; call routine |
Ldi R26,$60 |
; address of X |
St X+,R16 ; store crc16 LSB |
|
St X , R17 |
; store CRC16 MSB |
Example
$regfile = "m48def.dat" |
' specify the used |
micro |
' used crystal |
$crystal = 8000000 |
|
frequency |
' use baud rate |
$baud = 19200 |
|
$hwstack = 32 |
' default use 32 |
for the hardware stack |
' default use 10 |
$swstack = 10 |
|
for the SW stack |
' default use 40 |
$framesize = 40 |
|
for the frame space |
|
Config Com1 = Dummy , Synchrone = 0 , Parity = None , Stopbits = 1 , Databits = 8 , Clockpol = 0
Dim Ar(10) As Byte
Dim J As Byte
Dim W As Word
Dim L As Long
Ar(1) = 1
Ar(2) = 2
Ar(3) = 3
J = Crc8(ar(1) , 3) |
'calculate value |
which is 216 |
'24881 |
W = Crc16(ar(1) , 3) |
|
L = Crc32(ar(1) , 3) |
'494976085 |
End
page -414-
© MCS Electronics, 1995-2007
CRC32
Action
Returns the CRC32 value of a variable.
Syntax
Var = CRC32( source , L)
Remarks
Var |
The |
|
LONG variable that is assigned with the CRC32 of variable source. |
Source |
The source variable or first element of the array to get the CRC |
|
32 value from. |
L |
The number of bytes to check. |
|
|
CRC32 is used in communication protocols to check if there are no transmission errors.
See also
CHECKSUM , CRC8, CRC16 , TCPCHECKSUM
Example
$regfile = "m48def.dat" |
' specify the used |
micro |
' used crystal |
$crystal = 8000000 |
|
frequency |
' use baud rate |
$baud = 19200 |
|
$hwstack = 32 |
' default use 32 |
for the hardware stack |
' default use 10 |
$swstack = 10 |
|
for the SW stack |
' default use 40 |
$framesize = 40 |
|
for the frame space |
|
Config Com1 = Dummy , Synchrone = 0 , Parity = None , Stopbits = 1 , Databits = 8 , Clockpol = 0
Dim Ar(10) As Byte
Dim J As Byte
Dim W As Word
Dim L As Long
Ar(1) = 1
Ar(2) = 2
Ar(3) = 3
J = Crc8(ar(1) , 3) |
'calculate value |
which is 216 |
'24881 |
W = Crc16(ar(1) , 3) |
|
L = Crc32(ar(1) , 3) |
'494976085 |
End
page -415-
