Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Flowchart

Status
Not open for further replies.

gregmcc

Member
I'm busy writing a asm program for the 16f877 and have a question or two on the flowchart logic I'm using.

Its a bit difficult without a diagram but here goes.

Its for a combination lock with a few fancy features.

I'm using a interrupt which increments counters which is used to keep track of the date/time.

1) When the main prog starts I write the date/time on the lcd.
2) If key pressed check if its the # key.
3) If not # then save key and goto 1
4) If # pressed then check if code is *1
5) if not *1, then check if code matches passord, do some stuff, goto 1
6) If *1 then goto change password routine.
7) goto 1

Now my question - everything is working fine but when I press *1 and go to the password change routine I then do another loop to read in old password and new password. While in this loop I read the keypad for old and new password.

If for example someone enters the password change routine by mistake and then doesnt go any further its stuck in a loop. The date/time on the LCD won't get updated.

What the best method to exit this routine if its never completed - much like a timout reached then goto 1

I thought about using another timer - if it reaches 30 secs then goto 1
Is there an easier way?


Hope this kinda makes sense :D
 
gregmcc said:
What the best method to exit this routine if its never completed - much like a timout reached then goto 1
IMHO the best way is to use WDT (watchdog timer) ... Set you WDT to some value and reset it outside the loop. If prog spend too much time (more then what you set as WDT) the pic will reset and you will start all over.

As for the "time/data" there are cheep RTC modules you can attach to pic via i2c or spi.. battery backed up RTC like this one you can built for few $$
https://www.electro-tech-online.com/custompdfs/2008/04/rtc_board_schematic.pdf
it uses PCF8583P Clock/calendar with 240 × 8-bit RAM
https://www.ortodoxism.ro/datasheets/philips/PCF8583P.pdf
 
Thanks - I'll have a look at the WDT

I've had a look at RTC's - they aren't that cheap here. :( I don't need it to be that accurate and with a bit of trial and error I've got it only losing a second or two a month.
 
gregmcc said:
Thanks - I'll have a look at the WDT
You can for example clear WDT in your interrupt routine, so if your clock is not updated in time, you reset the pic ... pay attention that when WDT is not cleared in defined time, the pic will reboot - so I hope you store the "current time" somewhere else (afaik reseting the pic will reset all your variables to initial values)


gregmcc said:
I've had a look at RTC's - they aren't that cheap here. :( I don't need it to be that accurate and with a bit of trial and error I've got it only losing a second or two a month.
Can't help you there, except mikroe ship "parts" all around the globe .. you can order prebuilt module **broken link removed** for 16$ (donno about "shipping cost from europe to afrika") tho
 
The best way to fix this problem is to write an update LCD routine and call it in your get password routine. You could use it as the delay for the debounce.

Mike.
 
Pommie - thanks. Didnt think about that. Might be easier than me fiddling with the wdt and then breaking everything :)
 
Complete design architecture shift. Stop thinking about an "enter password" routine. Instead consider your device as operating in different "states".

IDLE - PASSWORD - OTHER

There can also be secondary state machines running (one that tracks progress of an input string).

Events will move you from one state to another
A. KEYPRESS Event
B. Timeout Event

Eg. On a KEYPRESS event:
if STATE = IDLE : STATE = PASSWORD ENTRY
CHARCOUNT = 1

if STATE = PASSWORD_ENTRY:
if KEY = #
do something
else
Store Key
CHARCOUNT+=1


(overly simplistic view, you have to hande all events in each state)

Your main loop spins waiting for events and then changes state as required.
If there is no event it drops to the default - update the LCD (or other)

This way your "Get String" (or GetInput etc) is common between all states that input data.

Yep.. hard without pictures, but I hope that made sense.
 
Last edited:
LabRat said:
Complete design architecture shift. Stop thinking about a "enter password" routine entirely, and consider "states".

IDLE - PASSWORD - OTHER
There are sub-states to some of these - GETSTRING - (tracks number of characters read into your tempbuffer)

Events will move you from one state to another
A. KEYPRESS Event
B. Timeout Event

Your main loop spins waiting for events and then changes state as required.
If there is no event it drops to the default - update the LCD (or other)

This way your "Get String" (or GetInput etc) is common between all states that input data. When you get an EVENT-# routine, you check what state were in, and call the appropriate handler, which looks at the "input string" buffer and acts accordingly.

Yep.. hard without pictures, but I hope that made sense.

I think my solution was simpler. :confused:

Mike.
 
Agreed.. but only if you wanted the timeout to take you back to the "reset" state. If you wanted to timeout back to some other state, the WDT wouldn't be too usefull.

Just different options available.
 
Last edited:
You may try to use a Micro with built in RTCC. Look into 24F family.
 
gregmcc said:
If for example someone enters the password change routine by mistake and then doesnt go any further its stuck in a loop. The date/time on the LCD won't get updated.

What the best method to exit this routine if its never completed - much like a timout reached then goto 1

I thought about using another timer - if it reaches 30 secs then goto 1
Is there an easier way?

Ya Mikes (Pommie) answer will suits you.You could use the LCD Display routine as the debouncing delay.

Hope the time base is using interrupts so it will update the time automatically.So after *1 enters you have to call LCD Display & Key Check routine & match the two passwords.

If need a timeout I would simply add a delay loop next after the key check routine.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top