+ Post New Thread
Results 1 to 12 of 12
  1. #1
    Newbie level 4
    Points: 41, Level: 1

    Join Date
    Oct 2019
    Posts
    6
    Helped
    0 / 0
    Points
    41
    Level
    1

    Problem with PIC16F877A, infinite loop output voltage 0.6V

    Hi
    i have a problem i hope you could help me. :)
    im interfacing a 4x4 keypad with an lcd for password detection
    my pic16f877a pic have a infinite loop while waiting for an input
    causing my i/o port's output voltage to be only 0.7V
    can u tell me how to solve the output voltage problem, its at PORTD

    *call keypad_data is a routine that returns 0 when what_button is d'16'


    following code:
    Code ASM - [expand]
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    
    begin
    call scan_keypad                ;if no input pressed, w= 16, what_button=16
    call keypad_data                 ;if w=16, return w=0
    xorlw 00H                     ;if w=0 , status Z become 1
    btfsc status,z                ;if Z=1, no button pressed keep looping
    goto begin
     
    scan_keypad                 ;subroutine
    movf what_button,w 
     
    bsf PORTD,0 ;scan first column of keys
    btfsc PORTC,2 ;has the * key been pressed? if yes then
    movlw d'14' ; copy *(14) into w , not then skip
    btfsc PORTC,3 ;has the 7 key been pressed? if yes then
    movlw d'07' ; copy 7 into w , not then skip
    btfsc PORTC,4 ;has the 4 key been pressed? if yes then
    movlw d'04' ; copy 4 into w , not then skip
    btfsc PORTC,5 ;has the 1 key been pressed? if yes then
    movlw d'01' ; copy 1 into w , not then skip
    bcf PORTD,0 ;finished scanning first column
    ...
    if no keypad is pressed movlw d'16'
    movf what_button,w
    return
    Last edited by BradtheRad; 27th October 2019 at 04:43. Reason: Added code formatted window

    •   AltAdvertisement

        
       

  2. #2
    Advanced Member level 1
    Points: 2,366, Level: 11

    Join Date
    Jan 2019
    Posts
    436
    Helped
    111 / 111
    Points
    2,366
    Level
    11

    Re: Problem with PIC16F877A, infinite loop output voltage 0.6V

    are you reading port C or port D?

    can you use an interrupt instead of a loop?
    any key press causes an interrupt and the interrupt routine evaluates which key was pressed


    1 members found this post helpful.

  3. #3
    Super Moderator
    Points: 82,003, Level: 69
    Achievements:
    7 years registered
    Awards:
    2nd Helpful Member
    betwixt's Avatar
    Join Date
    Jul 2009
    Location
    Aberdyfi, West Wales, UK
    Posts
    13,446
    Helped
    4487 / 4487
    Points
    82,003
    Level
    69

    Re: Problem with PIC16F877A, infinite loop output voltage 0.6V

    How are you measuring 0.7V?
    If the routine is in a loop and you are measuring with anything except an oscilloscope you will at best only see the average of the high/low logic levels.

    Brian.
    PLEASE - no friends requests or private emails, I simply don't have time to reply to them all.
    It's better to share your questions and answers on Edaboard so we can all benefit from each others experiences.



    •   AltAdvertisement

        
       

  4. #4
    Newbie level 4
    Points: 41, Level: 1

    Join Date
    Oct 2019
    Posts
    6
    Helped
    0 / 0
    Points
    41
    Level
    1

    Re: Problem with PIC16F877A, infinite loop output voltage 0.6V

    My 4x4 keypad must receive a high digital input of 1 which is PORTD,
    and reading the output of the keypad is PORTC
    problem is with PORTD outputing only 0.7V

    Thanks for the recommendation, i will look into interrupts. :)



    •   AltAdvertisement

        
       

  5. #5
    Newbie level 4
    Points: 41, Level: 1

    Join Date
    Oct 2019
    Posts
    6
    Helped
    0 / 0
    Points
    41
    Level
    1

    Re: Problem with PIC16F877A, infinite loop output voltage 0.6V

    I used a digital multimeter



  6. #6
    Super Moderator
    Points: 261,937, Level: 100
    Awards:
    1st Helpful Member

    Join Date
    Jan 2008
    Location
    Bochum, Germany
    Posts
    45,781
    Helped
    13913 / 13913
    Points
    261,937
    Level
    100

    Re: Problem with PIC16F877A, infinite loop output voltage 0.6V

    Do you have a programming adapter capable of in-circuit debugging (e.g. ICD3, PICkit, evaluation board with embedded programmer)? Why not single step the code and check levels with multimeter?



  7. #7
    Newbie level 4
    Points: 41, Level: 1

    Join Date
    Oct 2019
    Posts
    6
    Helped
    0 / 0
    Points
    41
    Level
    1

    Re: Problem with PIC16F877A, infinite loop output voltage 0.6V

    Im using pickit3
    I single step the code and the output voltage is 4.8V which is normal
    I guess the problem is the infinite loop haha...

    - - - Updated - - -

    Quote Originally Posted by wwfeldman View Post
    are you reading port C or port D?

    can you use an interrupt instead of a loop?
    any key press causes an interrupt and the interrupt routine evaluates which key was pressed
    Hi can you give me an example of how to write an the interrupt? and which port should i use?
    To receive input from my 4x4 keypad i need 4 inputs



  8. #8
    Super Moderator
    Points: 82,003, Level: 69
    Achievements:
    7 years registered
    Awards:
    2nd Helpful Member
    betwixt's Avatar
    Join Date
    Jul 2009
    Location
    Aberdyfi, West Wales, UK
    Posts
    13,446
    Helped
    4487 / 4487
    Points
    82,003
    Level
    69

    Re: Problem with PIC16F877A, infinite loop output voltage 0.6V

    16F877A has interrupt on change on, I think, PORTB. All you do is set up the interrupt register, write an ISR routine, read the port so it has a starting value then enable the interrupt. When any bit on the port changes, your program automatically jumps to the ISR and at the end of the ISR it resumes your previous program flow.

    Quite possibly your present problem is not setting the port bits to inputs and output directions properly. We need to see full code to be sure.

    I'm on vacation at the moment and have no data sheets with me to help with exact ISR and IOC settings.

    Brian.
    PLEASE - no friends requests or private emails, I simply don't have time to reply to them all.
    It's better to share your questions and answers on Edaboard so we can all benefit from each others experiences.



  9. #9
    Newbie level 4
    Points: 41, Level: 1

    Join Date
    Oct 2019
    Posts
    6
    Helped
    0 / 0
    Points
    41
    Level
    1

    Re: Problem with PIC16F877A, infinite loop output voltage 0.6V

    Thanks everyone for their suggestions, but i think my code just doesnt work.
    When i press the * key, infinite amount of * displays out on the LCD
    Does anyone know how to solve the problem
    My way of scanning is refered on this website , http://www.circuitstoday.com/interfa...2ckUQZHtIx-V-g


    Code ASM - [expand]
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    
    call enable 
       call write1                     ;writes pwd:
       here
     
       call scan_n_input
       
       goto here
     
    scan_n_input
           
        movlw b'00111100'
        movwf PORTC
        movlw b'00001111'
        movwf PORTD
        bcf PORTC,2                   ;scan first column of keys
        btfsc PORTD,0                  ;has the * key been pressed? if yes then
        call enable
        call writestar                 ;write *
        
       return



  10. #10
    Super Moderator
    Points: 82,003, Level: 69
    Achievements:
    7 years registered
    Awards:
    2nd Helpful Member
    betwixt's Avatar
    Join Date
    Jul 2009
    Location
    Aberdyfi, West Wales, UK
    Posts
    13,446
    Helped
    4487 / 4487
    Points
    82,003
    Level
    69

    Re: Problem with PIC16F877A, infinite loop output voltage 0.6V

    Being honest, I can't see any similarity between your code and the one in the link.
    The method (not using interrupts) is to drive each column high with the others low in sequence and look for a high on any of the rows. When a high is seen at the row inputs, which key it was can be deduced from the high column at the time and which row it connected to. For example, send 0001, 0010, 0100, 1000 to the columns and see what comes back on the rows.
    Note that you can invert all the levels or swap rows with columns and it will still work.

    Brian.
    PLEASE - no friends requests or private emails, I simply don't have time to reply to them all.
    It's better to share your questions and answers on Edaboard so we can all benefit from each others experiences.



    •   AltAdvertisement

        
       

  11. #11
    Advanced Member level 4
    Points: 7,900, Level: 21

    Join Date
    Jan 2015
    Posts
    1,108
    Helped
    348 / 348
    Points
    7,900
    Level
    21

    Re: Problem with PIC16F877A, infinite loop output voltage 0.6V

    Looking at the last 3 instructions in your post #9 (before the 'return' that is) and without knowing what happens in the 'enable' and 'writestar' functions, it seems to me that you always call the 'writestar' function no matter what state of Port D bit 0. Is that why you get an infinite number of '*' characters?
    Susan



  12. #12
    Member level 3
    Points: 804, Level: 6

    Join Date
    Jun 2017
    Location
    near the sea
    Posts
    60
    Helped
    13 / 13
    Points
    804
    Level
    6

    Re: Problem with PIC16F877A, infinite loop output voltage 0.6V

    Assuming your first bit of code is actually complete (unlike the second) I don't see you have enabled PORTD as outputs at any point so I am not surprised you cannot see any output BUT also measuring with a DVM is hopeless if they are dynamic outputs! Write a program that does nothing but set the output then you can use your DVM.



--[[ ]]--