Académique Documents
Professionnel Documents
Culture Documents
Electronic Lock Boris Barreto Anthony Cappetto Stephen Kwon Nahom Tewolde
Overall Design
- Enable Interrupts (for Debug) - Loop Through main.c - Get key inputs (From keypad.asm) - Constantly check inputs until a good one is found - Enter appropriate function - Perform appropriate function (ASM or C)
This is the overall design for what the program will be doing constantly, in simple terms.
main.c
Initialize all variables (including char[6] vInput, and int vCount, num) //Function definitions (pseudocode for each function in future slides) For (;;)
While (vCount != 100)
input = keypad_debounce(1000); // This is not vInput, this is just one character If (inputvalid == true)
vInput[vCount--] = input; ++num; CheckInput(vInput, num);
Else
Do nothing (Loop and check again)
If (vCount == 0) (If it reached the end of its input and its still not a valid code, restart it)
Clear vInput[]; vCount = 5;
keypad.asm
Push registers used onto the stack If (PTAD has been set up) branch endif Else set up PTAD DO
Output each row code // Starting from Row3 Read each col code (col[j]) for every row While (I > 0) // Where I is row[i]
Else // KeyPressed
Check if the key pressed is valid If (valid)
Load b with appropriate ascii value for button pressed Pull variables Return clearB Pull variables Return
spin.asm
// Controls the motor just as in labs: XREF Direction,Speed Push registers to stack Sequence: DC.B (Stepping Sequence) LDY with Direction (To check it to see which direction to go in) LDX Sequence LDY Speed (Not sure how to control speed yet, my lab seven isnt able to go fast yet. If CW
LDAA 1,X LDAA 1,X+
Keypad_debounce(int bouncelength)
getkey = hex_key_scan(); Count = bouncelength/2; While (count between 0 and bouncelength) Delay Newkey = hex_key_scan(); If (newkey = getkey)
Increment count
Else
Decrement count
If (vCount = 2)
if (((vInput*5+ <= 9 && vInput*5+ >= 0) || (vInput*5+ >= A && vInput*5+ <= D)) && (vInput[4] == # || vInput*4+ == *)) // Invalid Input Clear vInput; vCount = 5; num = 0;
ETC (Check all the commands one by one, and run the appropriate command.) Commands to be included are: Lock, DisplayUnlockCodes, OpenProgrammingMode (This might have CloseProgrammingModeInside it to check for when to close), Unlock, EraseCode) // Notice no Debug, this is on the interrupt, so it will happen without being checked.
Lock
Direction = 1 (CW) Speed = (90 times a minute) spin(); Clear vInput[]; num = 0; // Restore the input to its original state (POR) vCount = 5;
OpenProgrammingMode // Im still not sure how to implement this one. Need to test ideas
Variables used which are defined in main:
char vUnlockCodes[9] Unsigned int vCodesnum (Starting at 0); LCDPutString (FULL);
If (vCodesnum == 9)
If ((vInput*3+ >= 0 && vInput*3+ <= 9) && vInput*2+ >= 0 && vInput*2+ <= 9) && (vInput*1+ >= 0 && vInput*1+ <= 9))
// Valid Number Sequence vInput[3] = vUnlockCodes[vCodesnum++]; LCDPut vInput[2] = vUnlockCodes[vCodesnum++]; LCDPut vInput[1] = vUnlockCodes[vCodesnum++]; LCDPut
Else
Unlock
Check the numbers input (from vInput[3-1]) with the numbers in vUnlockCodes[8-6,5-3,2-0]. If (Any Match in the three numbers)
Unlock LCDPut (OK)
Else
DontUnlock LCDPut(NOTVALID)
EraseCode
LCDPut(ERASED); Clear vUnlockCodes[]; Reset vCodesNum = 0;
Debug
PTT_PT7 = 1; LCDPut(DEBUG); While (PB1 == 1) DELAY While (POT is Range 1 && PB1 == 1)
Direction = CCW Spin(); Delay Direction = CCW Spin(); Delay Direction = Stopped Spin(); Delay