1 Attachment(s)
Problem Keeping PORTD.1 LOW
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?
You cannot use the same pin for keyboard scanning.
Hi there,
You cannot use the pin (portd.1) for any other purpose like a keyboard scanning routine (which you r doing as far as your schematic goes ).
Please take note of the following. Why don't you use the ONA pin on the MAX1672.That is positive edge triggered. By default when a PIC wakes up the pin in an input (tristated). Do the following
1. Turn of the AD and make the pin digital (if it has a muxed analogue in)
2. Set the DATA direction register
3. Throw the value to the port
This will set your circuit kicking till you make the pin high and kill the power supply.
A detailed schematic and complete code would be appreciated.
Regards
Sougata
Just read the datasheets !!!
Hi, Koosa
The reason why is written in the first lines of the max specs ...
Referring your design : Overvoltage on control pins ...
Alain