Bartman >lowbyte as one word isn't in the manual. low and byte as separate words are, of course so what section should I be looking in to see this? I'm using the manual for PicBasic downloaded from the site where it can be purchased.
In a word you have 16 bits or 2x8 bits or 2x1 BYTE. LOWBYTE and HIGHBYTE are the 2 separate BYTE
MyWORD = %1111000000001111
MyByte1=MyWORD.HIGHBYTE
MyByte2=MyWORD.LOWBYTE
===========================
MyByte1 will return 11110000 Binary or F0 hex
MyByte2 will return 00001111 Binary or 0F hex
LOW is a function to access PORT pins. LOW will place pins, bits to low level.
LOW PORTA.0 ;will place PORTA RA0 pin to low level
LOW PORTA ;will place all PORTA pins to low level
===================================
RANDOM is a function of PICBASIC who provide you a pseudo-random value in a WORD size variable, 16 bits, range from 0-65525. So if you want to use it in your application, you'll need to use a range from 0-15. In this case you'll need only 1 BYTE to give you range from 1-255, after that reduce the range to 0-15.
SO...
RANDOM MyVar
Range0_255=Myvar.LOWBYTE
Range0_15=Range0_255 & $0F ; logical operation to isolate the 4 Less Significant Bits
ex:
Range0_255 = %10101010
Range0_15=Range0_255 & $0F
Range0_15 will return 1010 Binary , A in hexadecimal, 10 in decimal
Steve
It's not a bug, it's a random feature.
There's no problem, only learning opportunities.
Bookmarks