- Joined
- Jul 4, 2009
- Messages
- 16,532
- Helped
- 5,157
- Reputation
- 10,347
- Reaction score
- 5,214
- Trophy points
- 1,393
- Location
- Aberdyfi, West Wales, UK
- Activity points
- 139,785
That is a massive jump ahead - well done !!
It might actually work at the moment but I'm not going to try it !
A few minor points, these are not mistakes, just suggestions to make the code clearer and easier to debug:
1. instead of allocating all the variable addresses yourself, consider using the 'cblock' directive. It makes it less likely to make mistakes, especially if you add more variables later. Change:
to
The assembler will allocate the numbers by itself and if you need to add an extra variable, just put it between the cblock and endc statements and all the numbers will magically adjust accordingly.
2. You use 'BTFSC h'03',2 ;Check Zero Bit' several times, this is correct but not easy to read because you need to remember that h'03' means the STATUS register and '2' is the Zero bit. Instead, use the register and bit names so it becomes 'BTFSC STATUS,Z' it's much easier to understand. Just like you gave names (aliases) to the pin names, if you look in the 'p16F84A.inc' file you will find the registers and all the bit number have been given names too.
The #include directive simply means "put all the code in the include file right here", you could do exactly the same by copying the contents of the file into your program but why bother when its all done for you.
3. Some of the code is duplicated, whenever you see more than a few lines being used over and over again, put them in a subroutine and call them every time they are needed.
Other than that it looks pretty good. You have mastered the look-up tables nicely and noticed that you can't actually reach the first entry, it just has to be there to keep the others in the right place. I'm not sure you are setting the column scan quite right, are you putting the '1' on only one column at a time?
Now a hint of a bug for you to hunt down. Sometimes you have to imagine a total idiot (me perhaps!) is going to use your device and think what might happen if they try to hold several keys down at once. Think of the resulting value on the row inputs and what might happen in the look-up tables.
Brian.
It might actually work at the moment but I'm not going to try it !
A few minor points, these are not mistakes, just suggestions to make the code clearer and easier to debug:
1. instead of allocating all the variable addresses yourself, consider using the 'cblock' directive. It makes it less likely to make mistakes, especially if you add more variables later. Change:
Code:
w_temp EQU 0x0C ; variable used for context saving
status_temp EQU 0x0D ; variable used for context saving
Del1 EQU 0x0E
Del2 EQU 0x0F
LCD EQU 0x10
Print EQU 0x11
Display EQU 0x12
Home EQU 0x13
Code:
cblock 0x0C
w_temp ; variable used for context saving
status_temp ; variable used for context saving
Del1
Del2
LCD
Print
Display
Home
endc
2. You use 'BTFSC h'03',2 ;Check Zero Bit' several times, this is correct but not easy to read because you need to remember that h'03' means the STATUS register and '2' is the Zero bit. Instead, use the register and bit names so it becomes 'BTFSC STATUS,Z' it's much easier to understand. Just like you gave names (aliases) to the pin names, if you look in the 'p16F84A.inc' file you will find the registers and all the bit number have been given names too.
The #include directive simply means "put all the code in the include file right here", you could do exactly the same by copying the contents of the file into your program but why bother when its all done for you.
3. Some of the code is duplicated, whenever you see more than a few lines being used over and over again, put them in a subroutine and call them every time they are needed.
Other than that it looks pretty good. You have mastered the look-up tables nicely and noticed that you can't actually reach the first entry, it just has to be there to keep the others in the right place. I'm not sure you are setting the column scan quite right, are you putting the '1' on only one column at a time?
Now a hint of a bug for you to hunt down. Sometimes you have to imagine a total idiot (me perhaps!) is going to use your device and think what might happen if they try to hold several keys down at once. Think of the resulting value on the row inputs and what might happen in the look-up tables.
Brian.