Help... Im writing a code to read the input from a keypad. The problem is if i set this_is_the_section_thats_not_working (near bottom) to here1, the program will work until it reaches here, then because TRISD isnt setup correctly the program will leave the I/O ports is the previous state. If i set this_is_the_section_thats_not_working to here2 the program wont work properly the first time through. It seems to loop in the find_row section - no matter what i set the input ports to. What am I doing wrong? TIA Andrew Scott list p=16F877 #include goto start start inital bcf STATUS,RP1 ;select bank 1 bsf STATUS,RP0 movlw 0x00 movwf TRISB ;setup porta as output here2 bsf STATUS,RP0 movlw 0x78 movwf TRISD ;setup PORTD bcf STATUS,RP0 clrf PORTD here call find_row find_row bsf PORTD,0 ;set scanning code for col1 bsf PORTD,1 ;set scanning code for col2 bsf PORTD,2 ;set scanning code for col3 btfsc PORTD,3 ;goto correct row goto row1s btfsc PORTD,4 goto row2s btfsc PORTD,5 goto row3s btfsc PORTD,6 goto row4s goto find_row ;finds which row the key is in if any row1s bsf STATUS,RP0 ;select bank 0 movlw 0x07 movwf TRISD ;setup PORTD bcf STATUS,RP0 ;select bank 1 row1 call setup_rows btfsc PORTD,0 goto one btfsc PORTD,1 goto two btfsc PORTD,2 goto three goto row1 row2s bsf STATUS,RP0 ;select bank 0 movlw 0x07 movwf TRISD ;setup PORTD bcf STATUS,RP0 ;select bank 1 row2 call setup_rows btfsc PORTD,0 ;goto correct number goto four btfsc PORTD,1 goto five btfsc PORTD,2 goto six goto row2 row3s bsf STATUS,RP0 ;select bank 0 movlw 0x07 movwf TRISD ;setup PORTD bcf STATUS,RP0 ;select bank 1 row3 call setup_rows btfsc PORTD,0 ;goto correct number goto seven btfsc PORTD,1 goto eight btfsc PORTD,2 goto nine goto row3 row4s bsf STATUS,RP0 ;select bank 0 movlw 0x07 movwf TRISD ;setup PORTD bcf STATUS,RP0 ;select bank 1 row4 call setup_rows btfsc PORTD,0 ;goto correct number goto star btfsc PORTD,1 goto zero btfsc PORTD,2 goto hash goto row4 one movlw 0x1 goto found_num two movlw 0x2 goto found_num three movlw 0x3 goto found_num four movlw 0x4 goto found_num five movlw 0x5 goto found_num six movlw 0x6 goto found_num seven movlw 0x7 goto found_num eight movlw 0x8 goto found_num nine movlw 0x9 goto found_num star movlw 0xe goto found_num zero movlw 0x0 goto found_num hash movlw 0xe goto found_num setup_rows ;call debounce clrf PORTD bsf PORTD,3 ;set scan code row1 bsf PORTD,4 ;set scan code row2 bsf PORTD,5 ;set scan code row3 bsf PORTD,6 ;set scan code row4 return found_num movwf PORTB goto this_is_the_section_thats_not_working debounce movlw 0x9a movwf count1 d1 movlw 0x9a movwf count2 d2 decfsz count2,F goto d2 decfsz count1 goto d1 dbend retlw 00 end -- http://www.piclist.com#nomail Going offline? Don't AutoReply us! email listserv@mitvma.mit.edu with SET PICList DIGEST in the body