The following lines of code
disable_Interrupt = 1 ' Latch Interrupt disabled Gosub set_Address Gosub set_Port_pre Dir_ext = 1 ' set Device to sending state Dir_int = 0 ' set µ-Processor to receiving state disable_Interrupt = 0 ' Latch Interrupt enabled byte_Data = Pinc ' read Button/Device from the relevant port disable_Interrupt = 1 Gosub set_Port_post data = Bin(byte_data) byte_button = Right(data , 2) byte_button = Binval(byte_button)
work just fine about a 1000 times. They read the last two bits of an 8bit-latch and return the last two bits (00, 01, 10, or 11). These bits represent the state of two buttons. It potentially reads it from different addresses(devices) specified via a variable byte_adr before these lines in question.
However, about two times within 1000 iterations it goes wrong. While no button is pressed, it returns the button-pressed state. TheH address remains untouched. Has anybody experienced anything similar? I depend on this working 100% rather than only 99.8%.
Thank you so much for any help on this
For completeness sake, here the subroutines:
k_data_in = Bin(byte_adr) For count_Bit = 1 To 4 Step 1 count_Bit_2 = 9 - count_Bit k_data = Mid(k_data_in , count_Bit_2 , 1) K(count_bit) = Val(k_data) Next Adr_ext0 = K(1) ' This is a port connected to the latch communicating the address Adr_ext1 = K(2) Adr_ext2 = K(3) Adr_ext3 = K(4)
Ddrc = &B00000000 ' prepares read-direction of the µ Processor Portc = &B00000000 ' prepares the port
Ddrc = &B11111111 ' prepares read-direction of the µ Processor Portc = &B11111111 ' prepares the port