Email: Password: Remember Me | Create Account (Free)

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
???
11/24/03 01:11
Read: times


 
#59273 - Reading Port Issue
I'm having a problem reading P2 that I just cannot figure out! The port has 4 switches attached to it, the upper 4 pins are not connected to anything so they always read high. The lower 4 pins read low when turned on.

My code follows, but here is the scenerio.. If I read the switches in the first section, the result is fine and it jumps to just the right place, and executes the code, no problem at all. As soon as it executes the code and goes to another routine that insures it is still in the same mode, it re-reads the switches, masks off the bits as in the beginning, and is coming up with a completely different result causing it to abort and go back to the beginning again!

An example - with the first two switches ON, P2 initially reads as: 11111100. When it gets masked off, it reads 00001100 - 12 decimal, and jumps to the right location. It executes the code, then goes to the section that makes sure it is in the same mode. If I break at that point, I find that it is read P2 as 00011110, or 30 decimal - even after being masked off.

Where am I going wrong??

This works fine:

DIPSWT_mode:
MOV A, P2 ; get the DIP switch value
ANL A, #0FH ; mask to the low 4 bits
MOV B, #3 ; setup the table index * 3
MUL AB ; A = table index
MOV DPTR, #TABLE
JMP @A+DPTR ; jump to and through table
;
TABLE:
LJMP IGNOR ; swt=0 no operation
LJMP IGNOR ; swt=1 no operation
LJMP IGNOR ; swt=2 no operation
LJMP IGNOR ; swt=3 no operation
LJMP IGNOR ; swt=4 no operation
LJMP IGNOR ; swt=5 no operation
LJMP MODE5 ; swt=6 go to mode 5
LJMP IGNOR ; swt=7 no operation
LJMP MODE4 ; swt=8 go to mode 4
LJMP IGNOR ; swt=9 no operation
LJMP MODE3 ; swt=10 go to mode 3
LJMP IGNOR ; swt=11 no operation
LJMP MODE2 ; swt=12 go to mode 2
LJMP IGNOR ; swt=13 no operation
LJMP MODE1 ; swt=14 go to mode 1
LJMP IGNOR ; swt=15 no operation
;

Here is where it goes bad:
(r7 contains the correct decimal value, ie: 12)

LOOP:

MOV R3, A
MOV A, P2
ANL A, #0FH
CLR C
SUBB A, R7
JNZ BACK - always returns here..
MOV A, R3


Why is P2 reading as anything but what it actually is?!?!?


List of 12 messages in thread
TopicAuthorDate
Reading Port Issue            01/01/70 00:00      
   RE: Reading Port Issue            01/01/70 00:00      
      RE: Reading Port Issue            01/01/70 00:00      
         RE: Reading Port Issue            01/01/70 00:00      
   RE: Reading Port Issue            01/01/70 00:00      
   RE: Reading Port Issue            01/01/70 00:00      
      RE: Reading Port Issue            01/01/70 00:00      
   RE: Reading Port Issue            01/01/70 00:00      
   RE: Reading Port Issue            01/01/70 00:00      
   RE: Reading Port Issue            01/01/70 00:00      
   RE: Reading Port Issue            01/01/70 00:00      
   Come back!            01/01/70 00:00      

Back to Subject List