??? 09/14/06 07:35 Read: times |
#124271 - Lots of problems Responding to: ???'s previous message |
Firstly, you have no comments. How are we supposed to know what the code is to do? Please don't believe that since we are highly experienced that we can look at the code and infer exactly what it is to do without spending an inordinate amount of time to actually figure it out. From what I understand from your code, I cannot see how you control the scanning of each row. Are you relying on the value read back from P1 as being what you expect? This is dangerous at best. You should have a ram or register variable that keeps track of the current selected row and use this variable for the loop control and to either lookup the value to write to the port to select the correct row or to select what bit(s) to set/clear. Similarly to you isolating what column is active - how do you limit the loop to the first 4 bits? Again you need a ram or register variable to control this or use a selection (test col 1, test col2,test col 3,test col 4). From these two values (row & col) you combine these to form a button number that you can use to lookup a table for translation. Depending on what instruction you are using, the value read from the port can be either the current port input state or the internal port register. As such, relying on values you have written to a port to be read back to control your program flow is inviting trouble. What happens if two port pins short together? This will give you values you may not expect. I usually only write to output port pins and use a variable to store state information. Since you have an operational LCD, you can use this to output diagnostic information from your code. If you break your keypad code down to smaller sections, you can observe the output values on you LCD and from this determine where your code fails to do what you expect. A simulator is handy in these instances. In programming, probably 90% of time is testing and fixing bugs, with 10% actually spent on coding. Therefore you best get some practice in learning how to debug your code otherwise you'll just be an expensive chair warmer. |