Here's one idea/Henrik.Code:Temp VAR BYTE If TimerRunning = 1 THEN If (PortA.2 = 1) OR (PortA.3 = 1) THEN Temp = PortA & %11111100 PortA = Temp + DIM ENDIF ENDIF
Here's one idea/Henrik.Code:Temp VAR BYTE If TimerRunning = 1 THEN If (PortA.2 = 1) OR (PortA.3 = 1) THEN Temp = PortA & %11111100 PortA = Temp + DIM ENDIF ENDIF
Henrik I see what you are doing but wouldnt this create an issue with the higher bits? For instance if I am understanding correctly, the higher bits are always at 1, which would indicate a high, which in the program would stop and reset the timer. If I were to make them 0 in the loop, they would never change to 1 when the switch was closed. Switches are on bits 4, 5, 6 and 7.
Hi,
No, the high bits are not always 'at 1'.
When doing a bitwise AND both "inputs" must be true for the "output" to be true. Thus Temp = PortA & %11111100 will do a 'copy' of PortA except the two LSB's will be forced to zero. All the other bits will be left as they are when PortA is read.
Besides, it doesn't really matter what you write to the port/pins which are configured as inputs. If, for example, PortA.5 is an input and you write '1' to it it will still read the actual state that whatever is connected to it drives it to - which isn't neccesarily '1'. If you look at the schematic for the I/O pins you'll see that the output driver for the pin is disabled when TRIS is set (ie. pin is made an input). If it wasn't it would short out whatever drives the pin to either Vdd or Vss.
/Henrik.
Bookmarks