can't understand something from the D.Lincoln book - bit/byte level instruction/s

desbromilow

New Member
G'Day,

my field desk is working well in the camp accomodation, and I spent the last few days getting a 16x2 LCD (HD44780) to talk to a 18m2.

I used a version of the picaxe sample code I found by googling - it all worked fine once I remembered to insert the R/W connection to ground (cost me 2 days to find it)

Long story short, I did look at some code in the Picaxe book by David Lincoln - second edition, pages 195/196

in the routine called lcdout (page 196) there is this line of code:

pins = outbyte & $F0|2|rs

I've found references in the manuals and books regarding the "&" symbol and it being used as a bitwise AND between outbyte and $F0... but what is the rest of it doing?
Where is the reference I missed which explains it, and any other similar bitwise/bytewise commands?

in the above sample code, rs is a byte variable containing either a 1, or a 0.

many many thanks in advance,
Des
 

nick12ab

Senior Member
These are the list of mathematical functions listed in PICAXE Manual 2:
The mathematical functions supported by all parts are:
+ ; add
- ; subtract
* ; multiply (returns low word of result)
** ; multiply (returns high word of result)
/ ; divide (returns quotient)
// % ; modulus divide (returns remainder)
MAX ; limit value to a maximum value
MIN ; limit value to a minimum value
AND & ; bitwise AND
OR | ; bitwise OR (typed as SHIFT + \ on UK keyboard)
XOR ^ ; bitwise XOR (typed as SHIFT + 6 on UK keyboard)
NAND ; bitwise NAND
NOR ; bitwise NOR
XNOR ^/ ; bitwise XNOR
ANDNOT &/ ; bitwise AND NOT (NB this is not the same as NAND)
ORNOT |/ ; bitwise OR NOT (NB this is not the same as NOR)
So the | means bitwise OR.
 

desbromilow

New Member
THANKS Nick!!!!

Now I understand that it, I'll see if i can rewrite David's code to suit the 18M2. thanks again,
Des
 

g6ejd

Senior Member
outbyte is e.g. a character to be output.
It is ANDed with $F0 or %11110000.

This returns only the four highest bits.
These are assigned to pins 7,6,5 and 4 respectively which drives the data IO of the module. | 2 ‘means OR 2 which makes sure that %00000010 or bit 1 is always high
this sets the clock or latch bit to high. Finally | rs means OR rs ‘where rs is the instruction flag. When rs = 0 it's an instruction input and when rs = 1 a data input

This assumes you have your display wired as per this description.
 
Top