Hi Picers
I am designing a project to switch my circuit on with a membrane keypad using a MAX1672 (see attached drawing) with a PIC16F877 @ 20MHz.
The ONB Pin on the MAX1672, is by default HIGH, to keep the circuit off, if I press the ON button on my keypad it should switch it ON and then in my code I would put PORTD.1 LOW to keep it on, but this does not work.
When I press the ON button it switch the circuit on, but when I release the button it switch it off again, so my PORTD.1 is not kept LOW.
I have asked someone on the microchip mailing list if this is a bug, and this is what he has said:
<hr>
<i>
No, it's not a bug. Read-modify-write is just how the chip works:
When you do a BSF 0x30, 3 the chip does like this:
1) Read the value at register 0x30 in the ALU.
2) Change the value of bit 3 (set)
3) write back the modified value to register 0x30.
But when a read of a port register takes place, the pin voltage is read, instead of the internal value written to the port. If you have a pullup on the pin, and set it LOW, when you read the pin's value you will get HIGH, because the pullup resistor is forcing it HIGH.
So, for BSF PORTD,3, the chip does like this:
A) Read the pins of PORTD in the ALU;
B) Modify the value of bit 3 (set)
C) Write back the modified value to register 0x30.
See? you need to buffer to avoid reading the pins in a r-m-w.
Eventually they changed the PORT circuitry in the 16bits PICs, to include another register, called LATD, which does the same thing as our PORTD_BUFFER above.
</i>
<hr>
Is there a solution for this in PICBASIC?
Bookmarks