Please Help with Codelock

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 4.
To post in this forum you must have a registered copy of Flowcode 4 or higher. To sign up for this forum topic please use the "Online Resources" link in the Flowcode Help Menu.

Moderator: Benj

User avatar
acestu
Posts: 1720
Joined: Thu Dec 01, 2011 9:36 pm
Location: Macclesfield UK
Has thanked: 787 times
Been thanked: 226 times
Contact:

Please Help with Codelock

Postby acestu » Thu Feb 16, 2012 11:32 pm

Hi,

I have a flowcode file for a keypad combination lock, it is only 2 digit and I would like to make it 6 digit, I understand the code bad part, the code good part, and the testnumber routine, but I am struggling with the Main part of the flowcode ie the Decision "If keypadnumber = 255 which I am understanding as nothing is pushed on the keypad, so if nothing is pressed then it steps back to a connection point and goes through the process again, however on the last decision it steps back if the decision is no...

I am attaching the file, if anybody could give me some pointers I would be grateful.

Thanks In Advance
Acestu

codelock1 (1).fcf
(15.6 KiB) Downloaded 156 times
Laptop Mac Book Pro i7 retina El Capitan //// Tower/Intel i7-Windows 7 64 Bit, Toshiba i5 Laptop Windows 10
Computers are like air conditioners. They work fine until you start opening windows.

User avatar
medelec35
Valued Contributor
Valued Contributor
Posts: 8600
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2469 times
Been thanked: 3557 times
Contact:

Re: Please Help with Codelock

Postby medelec35 » Fri Feb 17, 2012 12:20 am

I created a 4 digit lock which could expand to 6 easily enough;
It can be found here:
viewtopic.php?f=26&t=7413&p=19253&#p18847

You may find the flowchart in the posted link easier to expand than the one you posted?

Martin
Martin

If you read a post that is useful, please show appreciation by clicking on thumbs up Icon.

User avatar
acestu
Posts: 1720
Joined: Thu Dec 01, 2011 9:36 pm
Location: Macclesfield UK
Has thanked: 787 times
Been thanked: 226 times
Contact:

Re: Please Help with Codelock

Postby acestu » Fri Feb 17, 2012 12:40 am

Thanks Martin,

I will have a look now

cheers
Stuart
Laptop Mac Book Pro i7 retina El Capitan //// Tower/Intel i7-Windows 7 64 Bit, Toshiba i5 Laptop Windows 10
Computers are like air conditioners. They work fine until you start opening windows.

User avatar
acestu
Posts: 1720
Joined: Thu Dec 01, 2011 9:36 pm
Location: Macclesfield UK
Has thanked: 787 times
Been thanked: 226 times
Contact:

Re: Please Help with Codelock

Postby acestu » Fri Feb 17, 2012 12:50 am

That's a bit more complicated Martin, I am hoping to get a solution to mine so that I can understand whats going on really..

Thanks
Stuart
Laptop Mac Book Pro i7 retina El Capitan //// Tower/Intel i7-Windows 7 64 Bit, Toshiba i5 Laptop Windows 10
Computers are like air conditioners. They work fine until you start opening windows.

User avatar
medelec35
Valued Contributor
Valued Contributor
Posts: 8600
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2469 times
Been thanked: 3557 times
Contact:

Re: Please Help with Codelock

Postby medelec35 » Fri Feb 17, 2012 2:47 pm

No problem Stuart,
I have modified the flowchart you have posted by removing decisions and replacing with loops and added two more digits.
I have done this in such a way that there is a repeatable pattern for adding more numbers, which should be a lot easier to follow than flowchart in the posted link.
The way to follow the flowchart is to keep single stepping by pressing F8 key and observing the actions of the flowchart whilst pressing a number on PC keyboard to activate the number of the keypad on the flowchart.

Martin
Attachments
codelock2.fcf
(19 KiB) Downloaded 155 times
Martin

If you read a post that is useful, please show appreciation by clicking on thumbs up Icon.

User avatar
medelec35
Valued Contributor
Valued Contributor
Posts: 8600
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2469 times
Been thanked: 3557 times
Contact:

Re: Please Help with Codelock

Postby medelec35 » Fri Feb 17, 2012 6:32 pm

acestu wrote: however on the last decision it steps back if the decision is no...

Oh yes in answer to your question, the reason it steps back when decision is no is because you have to release a key before it carries on to the next part.
Summed up:

1) Flowchart waits for a key to be pressed.

2) When key is pressed it's assigned to a variable.

3) Flowchart waits for key to be released, then displays assigned variable on LCD

4) Flowchart waits for a key to be pressed.

5) When key is pressed it's assigned to a variable

6 )Flowchart waits for key to be released, then displays assigned variable on LCD: This stage is what you was asking about.
Reason it does this is because without the waiting for key to be released, the reading and assigning to each variable will be so quick, the same number will always be assigned to both variables.

7) Number test routine is carried out.
Hope this answers your question

martin
Last edited by medelec35 on Fri Feb 17, 2012 7:47 pm, edited 1 time in total.
These users thanked the author medelec35 for the post:
acestu (Fri Feb 17, 2012 7:10 pm)
Rating: 5%
 
Martin

If you read a post that is useful, please show appreciation by clicking on thumbs up Icon.

User avatar
acestu
Posts: 1720
Joined: Thu Dec 01, 2011 9:36 pm
Location: Macclesfield UK
Has thanked: 787 times
Been thanked: 226 times
Contact:

Re: Please Help with Codelock

Postby acestu » Fri Feb 17, 2012 7:09 pm

Thanks Martin, I don't know what we would do without you...


cheers
stuart
Laptop Mac Book Pro i7 retina El Capitan //// Tower/Intel i7-Windows 7 64 Bit, Toshiba i5 Laptop Windows 10
Computers are like air conditioners. They work fine until you start opening windows.

User avatar
acestu
Posts: 1720
Joined: Thu Dec 01, 2011 9:36 pm
Location: Macclesfield UK
Has thanked: 787 times
Been thanked: 226 times
Contact:

Re: Please Help with Codelock

Postby acestu » Fri Feb 17, 2012 7:34 pm

Hi Martin,

that code is just the job, but now that I want to build it,
how do I know what crystal to use with it, because it is not specified in the chip information...

Also, I know that this is probably a bit ambitious, but is there an easy way to make the lcd light up as soon as any button is pressed and then go off after a timed period ?

Thanks
Stuart
Laptop Mac Book Pro i7 retina El Capitan //// Tower/Intel i7-Windows 7 64 Bit, Toshiba i5 Laptop Windows 10
Computers are like air conditioners. They work fine until you start opening windows.

User avatar
medelec35
Valued Contributor
Valued Contributor
Posts: 8600
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2469 times
Been thanked: 3557 times
Contact:

Re: Please Help with Codelock

Postby medelec35 » Fri Feb 17, 2012 9:59 pm

acestu wrote:Hi Martin,

that code is just the job, but now that I want to build it,
how do I know what crystal to use with it, because it is not specified in the chip information...

Hi Stuart,
Those decisions you need to make for yourself.
First workout how many i/p's and o/p's you require. then decide on the way the oscillator is driven. E.g external crystal, internal precision etc. Unless you require vey high speed for PWM or uart etc I would aim from about 4MHz to 20MHz. For instance I use 16F883 a lot and I use its internal osc running at 4 MHz (to save power only, otherwise I would use 8Mhz int osc) This saves on external components e.g crystal and associated caps. It's osc tolerance is 2% which is good enough for driving LCD.
You can have a look two different project selectors from microchip:
viewtopic.php?f=29&t=8040&p=22201#p22195.
Once you have decided the speed and type of oscillator you need to set up flowchart with the required settings.
If I was you then I would look here:
viewtopic.php?f=26&t=6936
and checkout this page:
http://www.matrixmultimedia.com/lc_index.php?p=7
Also there are excellent free on-line courses here:
http://www.matrixmultimedia.com/lc_index.php?p=24

There are lots of resources and information available on these forums and on the learning centre. Its well worth putting in the effort.

[quote="acestu"
Also, I know that this is probably a bit ambitious, but is there an easy way to make the lcd light up as soon as any button is pressed and then go off after a timed period ?
[/quote]

I have implemented that function since its more difficult for me to explain than to alter a flowchart in practice.
I have set the time for 10 seconds, but that is adjustable from 1 to 255 seconds.
Variable to alter is located in the Timer0_Tick Macro.

From the macro name you can guess I have used timer0 :lol:

There are plenty of information on timer interrupts around the forum.

I have also removed the EEPROM and RS232 as you are not currently using them.

Martin
Attachments
codelock2.fcf
Added LCD Backlight time out.
(17.62 KiB) Downloaded 157 times
These users thanked the author medelec35 for the post:
acestu (Fri Feb 17, 2012 10:38 pm)
Rating: 5%
 
Martin

If you read a post that is useful, please show appreciation by clicking on thumbs up Icon.

User avatar
acestu
Posts: 1720
Joined: Thu Dec 01, 2011 9:36 pm
Location: Macclesfield UK
Has thanked: 787 times
Been thanked: 226 times
Contact:

Re: Please Help with Codelock

Postby acestu » Fri Feb 17, 2012 10:38 pm

Thanks for your time Martin, I have tried the code that you have posted but when I run it the backlight comes on straight away and stays on, is there a way of just having the backlight on and starting the timer when any key is pressed and then going off after the timed period ?

Also thanks for the info on the resources....

cheers
Stuart
Laptop Mac Book Pro i7 retina El Capitan //// Tower/Intel i7-Windows 7 64 Bit, Toshiba i5 Laptop Windows 10
Computers are like air conditioners. They work fine until you start opening windows.

User avatar
medelec35
Valued Contributor
Valued Contributor
Posts: 8600
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2469 times
Been thanked: 3557 times
Contact:

Re: Please Help with Codelock

Postby medelec35 » Fri Feb 17, 2012 11:29 pm

Ah yes I forgot to say...
The simulator does not run in real time.
If you look in Timer0_Tick Macro. you will see a decision branch ....Seconds>9
That means if you compiled to chip then it ran with an oscillator speed of 19.66MHz then the back light will only stay on for 9 seconds.
Since simulator is running much much much slower, then simulated time will be far greater.

For Flowcode demonstration purposes if you just change 'Count>=75' to 'Count>=2'
and 'Seconds>9' to Seconds>2

then you can see it is simulating a bit better.

However if you ran the above settings on hardware then light will only say on for 1/75 * 2 * 2 = 53ms

Martin
These users thanked the author medelec35 for the post:
acestu (Fri Feb 17, 2012 11:52 pm)
Rating: 5%
 
Martin

If you read a post that is useful, please show appreciation by clicking on thumbs up Icon.

User avatar
acestu
Posts: 1720
Joined: Thu Dec 01, 2011 9:36 pm
Location: Macclesfield UK
Has thanked: 787 times
Been thanked: 226 times
Contact:

Re: Please Help with Codelock

Postby acestu » Fri Feb 17, 2012 11:52 pm

Hi Martin,

I will take your word for it and try a build this weekend, I have found some interesting stuff on the forums, I found a door lock with temp gauge that shows you how to wire up your keypad with resisters, I don't like the matrix youtube videos because they are in standard definition and I just cannot see the text, and unfortunately most of them are not narrated so newbies like me don't know what is going on, I have made a suggestion in one of the forums that somebody do them in HD, I would do some myself if I understood Flowcode like you, because making video tutorials is something that I am good at. Maybe in a few years when I have hopefully learnt something LOL.

Thanks again Martin
Stuart
Laptop Mac Book Pro i7 retina El Capitan //// Tower/Intel i7-Windows 7 64 Bit, Toshiba i5 Laptop Windows 10
Computers are like air conditioners. They work fine until you start opening windows.

User avatar
medelec35
Valued Contributor
Valued Contributor
Posts: 8600
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2469 times
Been thanked: 3557 times
Contact:

Re: Please Help with Codelock

Postby medelec35 » Sat Feb 18, 2012 12:11 am

No problem.

acestu wrote:when I run it the backlight comes on straight away and stays on


placed 'LCD_Backlight = 1
Seconds = 0'

At the beginning, so when power is first applied the back light will be on so you can see the display at the beginning.
If you don't want that to happen then you can remove the 1st occurrence, so back light stays off, until a key is pressed

As for learning the on-line tutorial would be the ideal place to start to learn about Flowcode.

Good luck with the building at the weekend.
Do you know what chip your going to use?

Martin
Martin

If you read a post that is useful, please show appreciation by clicking on thumbs up Icon.

User avatar
acestu
Posts: 1720
Joined: Thu Dec 01, 2011 9:36 pm
Location: Macclesfield UK
Has thanked: 787 times
Been thanked: 226 times
Contact:

Re: Please Help with Codelock

Postby acestu » Sat Feb 18, 2012 2:38 am

Hi Martin,

I am not sure which chip to use yet, I have a few different ones here now, yes the online tutorials would be great if they were produced better, I got one of those breadboard power supplies from hong kong aswell about £4.00 with usb on it really cheap. I got a new S/H external weatherproof keypad off ebay for £6.00, I will have to make something for the lcd to go in though otherwise it will get wet.

cheers
Stuart
Laptop Mac Book Pro i7 retina El Capitan //// Tower/Intel i7-Windows 7 64 Bit, Toshiba i5 Laptop Windows 10
Computers are like air conditioners. They work fine until you start opening windows.

User avatar
medelec35
Valued Contributor
Valued Contributor
Posts: 8600
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2469 times
Been thanked: 3557 times
Contact:

Re: Please Help with Codelock

Postby medelec35 » Sat Feb 18, 2012 6:48 pm

acestu wrote: yes the online tutorials would be great if they were produced better

I was thinking the free full on-line course would be better to start with:
http://www.matrixmultimedia.com/lc_index.php?p=24
Introduction to Microcontrollers is a great course for learning Flowcode.

Martin
Martin

If you read a post that is useful, please show appreciation by clicking on thumbs up Icon.

User avatar
acestu
Posts: 1720
Joined: Thu Dec 01, 2011 9:36 pm
Location: Macclesfield UK
Has thanked: 787 times
Been thanked: 226 times
Contact:

Re: Please Help with Codelock

Postby acestu » Sun Feb 19, 2012 6:09 pm

Hi Martin,

I have a Pic16F870 that I am going to use, also I am posting a screen grab of my chip properties to see if you think they are right if you don't mind..

screen_2012-02-19 17.07.29.jpg
screen_2012-02-19 17.07.29.jpg (155.27 KiB) Viewed 7162 times


Thanks
Stuart
Laptop Mac Book Pro i7 retina El Capitan //// Tower/Intel i7-Windows 7 64 Bit, Toshiba i5 Laptop Windows 10
Computers are like air conditioners. They work fine until you start opening windows.

User avatar
medelec35
Valued Contributor
Valued Contributor
Posts: 8600
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2469 times
Been thanked: 3557 times
Contact:

Re: Please Help with Codelock

Postby medelec35 » Sun Feb 19, 2012 7:20 pm

Hi Stuart,
looks correct, but It depends on the oscillator frequency you are going to use. If below 4MHz then select XT instead of HS
I don't believe 16F870 has an internal oscillator, so you will need a resonator (probably best way to go) or a crystal with the two matching caps.
If you want a chip that has same number of pins but a precision internal oscillator and two PWM channels then 18F883 is a good choice.

Martin
Martin

If you read a post that is useful, please show appreciation by clicking on thumbs up Icon.

User avatar
acestu
Posts: 1720
Joined: Thu Dec 01, 2011 9:36 pm
Location: Macclesfield UK
Has thanked: 787 times
Been thanked: 226 times
Contact:

Re: Please Help with Codelock

Postby acestu » Sun Feb 19, 2012 7:40 pm

Thanks Martin,

Yes I think I have a 4 mhz crystal here, I am going to program the chip now then with my pickit3, I want to use the keypad that I got off ebay but I need to know if Ican connect directly to the pic pins or do I have to put resisters on the leads..

Cheers
Stuart
Laptop Mac Book Pro i7 retina El Capitan //// Tower/Intel i7-Windows 7 64 Bit, Toshiba i5 Laptop Windows 10
Computers are like air conditioners. They work fine until you start opening windows.

User avatar
medelec35
Valued Contributor
Valued Contributor
Posts: 8600
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2469 times
Been thanked: 3557 times
Contact:

Re: Please Help with Codelock

Postby medelec35 » Sun Feb 19, 2012 8:34 pm

You will need to use the resistors. Best way is wire keypad the same as it is on the data sheet:
http://www.matrixmultimedia.com/datashe ... 4-30-1.pdf
Martin

If you read a post that is useful, please show appreciation by clicking on thumbs up Icon.

User avatar
acestu
Posts: 1720
Joined: Thu Dec 01, 2011 9:36 pm
Location: Macclesfield UK
Has thanked: 787 times
Been thanked: 226 times
Contact:

Re: Please Help with Codelock

Postby acestu » Sun Feb 19, 2012 9:57 pm

I have just built the circuit on a breadboard and guess what ?, yes the LCD backlight works, unfortunately that's all.

I don't know whats gone wrong but it should keep me busy, I think there is something that I am missing on all my pic circuits because none of them have worked yet...

:(

Lock.jpg
Lock.jpg (121 KiB) Viewed 7151 times


Cheers
Stuart
Laptop Mac Book Pro i7 retina El Capitan //// Tower/Intel i7-Windows 7 64 Bit, Toshiba i5 Laptop Windows 10
Computers are like air conditioners. They work fine until you start opening windows.

User avatar
medelec35
Valued Contributor
Valued Contributor
Posts: 8600
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2469 times
Been thanked: 3557 times
Contact:

Re: Please Help with Codelock

Postby medelec35 » Sun Feb 19, 2012 10:24 pm

If you post the flowchart you used, since you would have changed it for your new target device.
Also if you could post a full circuit diagram I can take a look at it for you.
I am assuming even with back light on you get no characters displaying on LCD?
How long does back light stay on for after pressing a Key?
Martin

If you read a post that is useful, please show appreciation by clicking on thumbs up Icon.

User avatar
acestu
Posts: 1720
Joined: Thu Dec 01, 2011 9:36 pm
Location: Macclesfield UK
Has thanked: 787 times
Been thanked: 226 times
Contact:

Re: Please Help with Codelock

Postby acestu » Sun Feb 19, 2012 10:34 pm

Hi Martin, I will do a circuit diagram for you, but for now i can post the flowcode that I have altered, the backlight comes on as soon as you apply power, with no text on it.

I have searched hi and lo on the internet for the PIC 18F883 that you suggested but no sign of one anywhere. I couldn't even find it on the Microchip site.

Stucodelock.fcf
(19.44 KiB) Downloaded 125 times


Thanks
Stuart
Laptop Mac Book Pro i7 retina El Capitan //// Tower/Intel i7-Windows 7 64 Bit, Toshiba i5 Laptop Windows 10
Computers are like air conditioners. They work fine until you start opening windows.

User avatar
medelec35
Valued Contributor
Valued Contributor
Posts: 8600
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2469 times
Been thanked: 3557 times
Contact:

Re: Please Help with Codelock

Postby medelec35 » Sun Feb 19, 2012 10:39 pm

acestu wrote:I have searched hi and lo on the internet for the PIC 18F883 that you suggested but no sign of one anywhere.

Oops sorry that is a typo, it should be 16F883. :oops:
Martin

If you read a post that is useful, please show appreciation by clicking on thumbs up Icon.

User avatar
acestu
Posts: 1720
Joined: Thu Dec 01, 2011 9:36 pm
Location: Macclesfield UK
Has thanked: 787 times
Been thanked: 226 times
Contact:

Re: Please Help with Codelock

Postby acestu » Sun Feb 19, 2012 10:48 pm

Ahh, no probs, I have found lots of them now, going to do a wiring diagram now...

thanks
Stuart
Laptop Mac Book Pro i7 retina El Capitan //// Tower/Intel i7-Windows 7 64 Bit, Toshiba i5 Laptop Windows 10
Computers are like air conditioners. They work fine until you start opening windows.

User avatar
medelec35
Valued Contributor
Valued Contributor
Posts: 8600
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2469 times
Been thanked: 3557 times
Contact:

Re: Please Help with Codelock

Postby medelec35 » Sun Feb 19, 2012 10:51 pm

If you are using a 4MHz crystal, then you need to change target speed from 19660800Hz to 4000000Hz
You don't really need to have Flash program write enabled either, since you are not using using software to write to flash, only using a programmer.

Good thing about 16F883 is the internal oscillator is precise enough to drive LCD at 4 or 8MHz.
Last edited by medelec35 on Sun Feb 19, 2012 11:47 pm, edited 1 time in total.
Martin

If you read a post that is useful, please show appreciation by clicking on thumbs up Icon.