Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Problem with PIC16F877A, infinite loop output voltage 0.6V

Status
Not open for further replies.

khai13

Newbie level 4
Joined
Oct 26, 2019
Messages
6
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
62
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 a moderator:

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
 
  • Like
Reactions: khai13

    khai13

    Points: 2
    Helpful Answer Positive Rating
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.
 

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. :)
 

I used a digital multimeter
 

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?
 

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 - - -

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
 

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.
 

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 , https://www.circuitstoday.com/inter...ZTuTIK7zMMANfs62FdG11SNfOzTSRom2ckUQZHtIx-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

 

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.
 

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
 

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.
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top