We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
The sample L51_BANK.A51 module uses the following code to determine the current bank:
?B_BANK&N: MOV A,?B_CURRENTBANK ANL A,#?B_MASK CJNE A,#BANK&N,XLABEL ; etc...
?B_BANK&N: CLR A ORL A, ?B_CURRENTBANK ANL A,#?B_MASK CJNE A,#BANK&N,XLABEL ; etc...
If that's the case, then it's necessary to store a copy of the current bank somewhere else. But, back to my original point, is the L51_BANK code incorrect?
Seems so. In fact, if current loading of P1 is not so much (for example, if 74N244/245 buffer used) then it is still correct because you will read value from pin same as from latch. Anyway, some MCU have different input/output schemes and reading from pin which previously was set to 0, does not guarantee same value back. Yeah, seems it is error really. Good days!
The bank switching code has been working and stable for a long, long time for a lot of developers (several thousand). What device are you using where it doesn't work? Jon
Hi, here is from Atmel Microcontroller Data Book: Read-Modify-Write instructions are directed to the latch rather than the pin in order to avoid misinterpreting the voltage level at the pin. For example, a port bit might be used to drive the base of a transistor. When a 1 is written to the bit, the transistor is turned on. If the CPU then reads the same port pin at the pin rather than the latch, it will read the base voltage of the transistor and interpret it as 0. Reading the latch than the pin will return the correct value of 1. For here, this means that you will read wrong value from the port1 if somebody uses address buffer assembled with transistors. Be sure, I checked this note on real devices and found the voltage about 1.5...2V --- most MCU recognize it as logical 0. So the question is not that is works for long time, the fact is that this way is wrong and may (potentialy!) cause an error.
You mean bipolar transistors in TTL devices shouldn't be used.... CMOS devices also use transistors.... :)
I was investigating this as a potential cause of a problem I was having. It turned out to be hardware. Thanks for the replies. Plus it sounds like it would be one hell of a subtle bug if your bank-switch hardware / port setup meant that it was possible to read the "wrong" value.