Like a lot of others I am new to this. I wanted to develop a function generator so I designed a development board with a number of external components including a 4x4 matrix keypad. It all electrically is connected correctly and in the program below the flashing LEDs work but I cannot get the 4x4 board to even light up a LED..
I have attached both the schematic and the code I have been working on.
In the end I have set both RB4-7 to INPUTS and RD4-7 to INPUTS. [should they be both inputs???] I am not sure this is OK but it seems to work in MPLAB when using stimulus.
There are weak pullups on PORTB. I am not sure how this ties into the process but there is 5 volts on the each of the pins on the matrix board (EDIT 5 volts on RB4-7 and 1.48volts on pins RD4-7)...
I have no way of know if the 4X4 board is connected properly.
Anyway any help here would be greatly appreciated...
RB4-7 should be input but RD4-7 should be output and initially set high. You then set 1 of the port pins low and read RB4-7 to read one column. You repeat this for each of the row pins to read the complete keypad. I don't have time now to look at the code but will look tomorrow if you are still stuck.
OK I am still having trouble getting this to work. I can get the LEDs to flash however I want but the 4x4 board does not work with the PIC.
Heres what I have done:
1. CHECK THE BASIC CIRCUIT: I am using a zif board to remove the PIC easily. I removed it and then set up a simple circuit (jump wired from 5V to RD4 then jumped a LED from RB4 to GND. 2k2 resistor sits between RB4 and the ROW 1 pin). I wanted to check that when I press a key the LED came on and that there was no shorts. OUTCOME - there is no voltage on the LED until the associated button is pressed.
2. CHECK THE CODE:Gone through my intitial code carefully. (I have uploaded this). I have set RD4-7 high and I do this at the end of the flashing LED routine. This sets up for the interupt on B should a button be pressed.
When Reset this is what I observe on the board.
The LEDs flash.
Press a key nothing happens.
Checked voltages and at PINS RB4-RB7 I have a voltage of 1.33V. This occurs when nothing is pressed and I have no idea why. It simply flashes indicating that the interupt is on all the time...
I then added in the following line.
BCF OPTION_REG, NOT_RBPU ;Enable weak pull-ups
;on port B
This forced the pins RB4-7 to be high. Again nothing happening when I pressed a key.
In conclusion it seems to be CODE and in particular making the interrupt work correctly.....
to make sure that if the interupt did get tripped then it would flash all four LEDs to indicate it had made it to this routine..... it never did... I checked the pins and they are at 5V all the time with the weak pullups.
So is it possible for someone who knows this stuff alot better than me to have a look at the code (and the schematic just in case the design is wrong) and see if they can determine why it wont work on interupt?? There must be something fundamental I have not included.
Same for the other equates. However, in your code you are doing btfss PORTB,RB4 which will do btfss PORTB,16 instead of btfss PORTB,4. So you need to change one or the other.
Maybe you should change it to,
I am getting this logic backwards I think... I thought I was setting RD4-7 high and with a key pressed this would send one of the RB4-7 pins high thus setting off an interrupt. How should this work? it seems I should have it about face with RB4-7 high with a weak pullup and RD4-7low.
If this is the case then how does the interupt work when the RB4-7 pins are already high?
The port B change interrupt happens whenever B4-7 change. If you turn on the WPUs then port B will be high. If you make the port D pins low then when a key is pressed it will make one of the port B pins go low and trigger the interrupt. The interrupt will also happen when you release the key as the port B pin will go back to the high level.
I have programmed the chip and then while working used a multimeter to check RB4-7 and each is sitting at 5V.
Firstly I am having a problem with the debugger on MPLAB. I cannot get the program to interrupt. I dont know why as I have set INTCON GIE and INTCON RBIF to "1" as well as INTCON INTF to "0". I have set stimulus so RB0 is toggled but it wont jump.
I have also changed RB4-7 to be INPUTS and RD4-7 to be outputs.
You are setting RBIF but you should be setting RBIE and clearing RBIF in the interrupt.
Also, you are calling routines from your interrupt that call other routines etc. This is not good, your interrupt is filling the stack and will crash. The stack is only 8 locations deep.
I have added that line and I moved the START routine but it keeps jumping over the call statements.
I have added a jing video to show what it does... it shifts the literal values into w and jumps... also the debugger seems to stop on white space between the lines..
**broken link removed**
I have also added the asm file so you can see the program..
Not sure why its jumping over the call statements..
Kind Regards
Simon
Ignore this post as its actually for another thread