PDA

View Full Version : Playing with binary and let pins command.



Haxby
24-01-2006, 10:33
I have been using the direct Hitachi LCD connection method with the initialisation code as outlined in the picaxe interfacing circuits manual.

It has been working just fine. For those that don't know the hardware setup, essentially, pins 2,3,4,5,6 and 7 are used to send commands to the LCD screen in 4 bit binary mode. Pins 0 and 1 are not required.

The initialisation code as outlined works well but as it uses the "let pins" command, it also affects pins 0 and 1, which are not connected.


As I have other things I want to connect to pins 0 and 1 in my circuit, I wish to ensure that their state does not change. Specifically, I want pin 0 to stay high, and I want pin 1 to stay low no matter what.

The offending lines of code in the initialisation section, and in the wrins and wrchr section are as follows:

let pins = 48
let pins = 32
let pins = 128
let pins = b1 & 240
let pins = b2 & 240

I think that the & character blocks out some of the pins but I am not sure how that works as it is not clear in the basic commands manual. Could someone please shed some light on this?

hippy
24-01-2006, 11:48
Yes, that's exactly the problem. To overcome this it is necessary to recover the pin values before changing them ...

- pins = <i>XYZZY </i>

has to become something like ...

- PEEK $30,bTmp
- bTmp = bTmp &amp; %00000011
- pins = <i>XYZZY </i> &amp; %11111100 | bTmp

If you really do just want the pins to stay high or low then you can force those bits by simple masking and bit setting ...

- pins = b0 &amp; %11111100 | %00000001

In the case of 'pins = b1 &amp; 240', part of that masking is already being done, although it's not immediately obvious because a decimal number has been used ...

- pins = b1 &amp; %11110000 | %00000001

All pin assignements within the LCD routines will need to be edited appropriately. Because the Programming Editor doesn't do 'constant folding' it may be necessary to change any constant value assignments rather than do the masking separately to save code space.

I recommend you take a look at my page on LCD control where overcoming this issue is dealt with ( even if I say so myself ) quite efficiently ...

http://www.hippy.freeserve.co.uk/picaxelc.htm#Using_Output_pins_0_and_1

Haxby
25-01-2006, 02:40
Thanks Hippy,

Is there anywhere where I can look up what the &quot;|&quot; symbol does in:

- pins = b1 &amp; %11110000 | %00000001

Looks like it adds it to %11110000 in the example above but some written indication would be nice. I copied and pasted that character from your answer. How does one get that character with the keyboard?

Regards,
Phil

hippy
25-01-2006, 02:48
The | is an OR, on my keyboard; left of the Z, shifted. You can use the word &quot;OR&quot; as well.