![](../images/horizontal_rule.jpg)
Code
Pseudo Code: Source Code (zip): |
Diagrams: Support Code (zip): |
KeyPad Pseudo Code: State Machine
;#include <p16f690.inc>
;config (use internal osc)
;define variables
;
;*********************************************************
;*********************************************************
;Main program code
;Initialize
;config ANSEL registers
;config TRIS registers
;clear all variables
;clear PORTA
;clear PORTC
;set the state to Num0
;*********************************************************
;Main Loop
;set COL1 high
;save PORTC values
;check to see if any ROWs are set
;if a ROW is set skip to save value, else continue
;
;set COL2 high
;save PORTC values
;check to see if any ROWs are set
;if a ROW is set skip to save value, else continue
;
;set COL3 high
;save PORTC values
;check to see if any ROWs are set
;if a ROW is set skip to save value, else continue
;
;set COL4 high
;save PORTC values
;check to see if any ROWs are set
;if a ROW is set skip to save value, else continue
;
;goto main loop
;
;*********************************************************
:Save Value
;save new value
;check if new value equals old value
;if true, goto Good Read, else continue
;
;save new as old
;return to the beginning main loop
;*********************************************************
;Good Read
;set red LED
;call state machine
;call check buttons
;clear red LED
;return to the beginning of main loop
;*********************************************************
;*********************************************************
State machine
;check for ‘star’
;if true, clear all registers, set Num0 state, and return, else continue
;*********************************************************
STATE_Num0
;check state
;check for ‘two’
;if not, set state to Num0 and return, else continue
;set state to next state
;
;return
;
;*********************************************************
STATE_Num1
;check state
;check for ‘one’
;if not, set state to Num0 and return, else continue
;set state to next state
;
;return
;
;*********************************************************
STATE_Num2
;check state
;check for ‘eight’
;if not, set state to Num0 and return, else continue
;set state to next state
;
;return
;
;*********************************************************
STATE_Num3
;check state
;check for ‘C’
;if not, set state to Num0 and return, else continue
;set state to next state
;
;return
;
;*********************************************************
STATE_NumDone
;check state
;check for ‘pound’
;if not, set state to Num0 and return, else continue
;set state to next state
;
;set green LED (gets cleared when ‘star’ is pressed)
;
;return
;
;*********************************************************
;*********************************************************
;Check Buttons
;set COL1 high
;save PORTC values
;check to see if any ROWs are set
;if all ROWs are clear continue, else goto ‘Check Buttons’
;
;set COL2 high
;save PORTC values
;check to see if any ROWs are set
;if all ROWs are clear continue, else goto ‘Check Buttons’
;
;set COL3 high
;save PORTC values
;check to see if any ROWs are set
;if all ROWs are clear continue, else goto ‘Check Buttons’
;
;set COL4 high
;save PORTC values
;check to see if any ROWs are set
;if all ROWs are clear continue, else goto ‘Check Buttons’
;return
;
;*********************************************************
;*********************************************************
END