Hi to all engineers. Iām using 2 four bit encoder. I am making diagnostic routine to check switches if any of 16 position doesnāt match with compare table report as an error. for testing purpose I am using only one table. the rest are off I saved SW1_0 with b'00000000' portb goes to 2 four bit switches g = ground _g_________/___| __g________/___| ___g_______/___| ____g______/___|portb | ___g_______/___| ____g______/___| _____g_____/___| ______g____/___| | when switches are 0 W register is 0 ( z = 1) I saves w in 'junk' so junk should have 0x00 and SW1_0 should have 0x00 value when I use if sw1_0 == junk bsf porta,0 should be equal some how they are not equal what am i doing wrong? ;******************************************************** ;I would like to know on what day PICLIST engineers ; are planing to be in show September 29 or October 1 ;******************************************************** Andre thank you very much LIST P=16C62A #INCLUDE C:\MPLAB\P16C62A.INC START CBLOCK 0X20 SW1_0 ; add one 0x21 ; SW1_1 ; SW1_2 ; SW1_3 ; SW1_4 ; SW1_5 ; SW1_6 ; SW1_7 ; SW1_8 ; SW1_9 ; SW1_A ; SW1_B ; SW1_C ; SW1_E ; SW1_D ; SW1_F ; SW2_0 ; SW2_1 ; SW2_2 ; SW2_3 ; SW2_4 ; SW2_5 ; SW2_6 ; SW2_7 ; SW2_8 ; SW2_9 ; SW2_A ; SW2_B ; SW2_C ; SW2_D ; SW2_E ; SW2_F ; SWITCHES ; SENDREG ; BIT_COUNT COUNT ; is for delay COUNT1 COUNT2 JUNK ; for compare table A9 ENDC ;--------------- PORT EQUATIONS ---------------------- RB0 EQU 0 RB1 EQU 1 RB2 EQU 2 RB3 EQU 3 RB7 EQU 7 ;------------------------------------------------------------ ORG 0X000 ; ORIGIN ;------------------------------------------------------------ CLRF PORTA ; CLEAR PORTA CLRF PORTB ; CLEAR PORTB CLRF PORTC ; CLEAR PORTC BSF STATUS,RP0 ; SWITCH TO BANK 1 MOVLW B'00000100' ; EXCEPT RA3 ALL OUTPUT MOVWF PORTA ; DO IT MOVLW B'11111111' ; INPUTS MOVWF PORTB ; MAKE PORTB INPUT FOR SWITCHES MOVLW B'00000011' ; EXSEPT RC0 AND RC1 ALL OUTPUT MOVWF PORTC ; DO IT BCF STATUS,RP0 ; SWITCH BACK TO BANK 0 CLRF PORTA ; CLEAR PORTA CLRF PORTB ; CLEAR PORTB CLRF PORTC ; CLEAR PORTC ;------------------------------------------------------------ ; MOVLW .100 ; LOAD DECIMAL 10 IN W ; MOVWF BIT_COUNT ; SAVE IT THERE ;------------------- DIAGNOSTIC MODE ----------------------- MOVLW B'00000000' ; load this value to compare with MOVWF SW1_0 ; save it there ; MOVLW B'00000001' ; MOVWF SW1_1 ; MOVLW B'00000010' ; MOVWF SW1_2 ; MOVLW B'00000011' ; MOVWF SW1_3 ; MOVLW B'00000100' ; MOVWF SW1_4 ; MOVLW B'00000101' ; MOVWF SW1_5 ; MOVLW B'00000110' ; MOVWF SW1_6 ; MOVLW B'00000111' ; MOVWF SW1_7 ; MOVLW B'00001000' ; MOVWF SW1_8 ; MOVLW B'00001001' ; MOVWF SW1_9 ; MOVLW B'00001010' ; MOVWF SW1_A ; MOVLW B'00001011' ; MOVWF SW1_B ; MOVLW B'00001100' ; MOVWF SW1_C ; MOVLW B'00001101' ; MOVWF SW1_D ; MOVLW B'00001110' ; MOVWF SW1_E ; MOVLW B'00001111' ; MOVWF SW1_F ; MOVLW B'00000000' ; MOVWF SW2_0 ; MOVLW B'00010000' ; MOVWF SW2_1 ; MOVLW B'00100000' ; MOVWF SW2_2 ; MOVLW B'00110011' ; MOVWF SW2_3 ; MOVLW B'01000000' ; MOVWF SW2_4 ; MOVLW B'01010000' ; MOVWF SW2_5 ; MOVLW B'01100000' ; MOVWF SW2_6 ; MOVLW B'01110000' ; MOVWF SW2_7 ; MOVLW B'10000000' ; MOVWF SW2_8 ; MOVLW B'10010000' ; MOVWF SW2_9 ; MOVLW B'10100000' ; MOVWF SW2_A ; MOVLW B'10110000' ; MOVWF SW2_B ; MOVLW B'11000000' ; MOVWF SW2_C ; MOVLW B'11010000' ; MOVWF SW2_D ; MOVLW B'11100000' ; MOVWF SW2_E ; MOVLW B'11110000' ; MOVWF SW2_F BACK MOVF PORTB,W ; LOAD PORTB IN TO W MOVWF JUNK ; SAVE IT THERE IF SW1_0 == JUNK ; if they are equal BSF PORTA,1 ; then do this ELSE ; otherewize BSF PORTA,0 ; do this ENDIF ; end of if GOTO BACK ; try more ;------------------- DELAY SUBROUTINE ----------------------- DELAY MOVLW .200 ; LOAD DECIMAL 200 TO COUNT MOVWF COUNT1 ; SAVE IT THERE D1 MOVLW .200 ; LOAD AN OTHER 200 MOVWF COUNT2 ; SAVE IT THERE D2 DECFSZ COUNT2,F ; DECRIMENT COUNT2 GOTO D2 ; IF NOT JUMP DECFSZ COUNT1,F ; DECRIMENT COUNT1 GOTO D1 ; IF NOT JUMP RETURN END