24hr timer: coding for and applying to a circuit

by:CAI YI JIE     2019-09-26
This is a school project we do to master programming chips, use different boards and coding.
In this project, I will use Flowcode (
Software for making programs for US)
Program the picture and make the LCD display clock to calculate the seconds, minutes and hours accurately, while the relay acts as a \"marker\" that marks passing through every second \".
Since I\'m fresh with using Flowcode, it\'s not as neat as I thought it would be, but this project is amazing to help me understand the main principles of programming and building circuits.
I\'m trying to make it as easy to understand as possible and tell you how to use Flowcode, so even if you\'re new (like I was)
You have a good understanding of what is and where.
You can download Flowcode for free from their website and play a game about yourself.
I hope this note will not be too difficult to understand and I will try to answer if you have any questions in the comments.
Now, there is no further ado to get us :)1.
When you load Flowcode select New Project for the first time, this will provide you with a list of options for which chip to program for, the chip in my photo is 16F1937, but you chose any one that you have 2 chips.
This will start a new project for you, but you want to make sure your chip is visible when you are here (
For reference only)
As well as your 2D dashboard panel, because here you can enable it3 by clicking view to interact with all analog inputs and outputs you choose to put on your picbling.
By going to the output switch on the top bar and clicking on the LCD, select the LCD output to be printed for our timer.
This will provide LCD for our 2D dashboard panel 4.
Right-click the LCD to bring up the list of properties and connect our LCD to portb5.
In order to make our program less confusing, I put my code in a macro, but for simplicity, you can put the LCD settings directly into our program line by doing the following6.
Insert component macro (
On the sidebar, drag it between our start and end sequences.
Double-click on it, it should pop up a property macro box, in the component list, click the small plus sign next to the LCD to expand the list, and select the Start command.
Press OK, this is the component command to start the LCD 7.
Insert another component macro below, this time select the component as the LCD \"clear\", which will remove any previous content on our LCD 8.
Insert the component macro under the previous component and select the component as the LCD \"curve\", which will show the parameters that can be changed at the bottom, we want to set x to 0, y is set to 0.
This outlines where our numbers and letters will be printed on the LCD.
Insert the component macro below again and select the component as the LCD \"print string \".
In the parameters section, we want to change the expression to hours minutes seconds with quotation marks (i. e. “ “)
Around the expression seen in the step nines image.
This is our LCD top line setup ready to use.
On the left side, drag a calculation under the LCD settings and double-click to display the calculation properties.
This is where we set it up so the clock starts from scratch. 11.
We do this by making new \"variables\" for each hour, minute, and second.
The initial value of each variable should be 0, click OK and set the variable as shown in the red box in step 1212.
Select the variable \"hr\" in the calculation box and write \"hrs = 0\", then press enter to get the following line, select the \"min\" variable and write \"mins = 0\" press enter to get the line below, then enter \"secs = 0\" as shown in blue outline box 13.
Drag a loop from the left sidebar into the circuit under your previous work, which will keep the clock on timing 14.
Insert the calculation into the loop and calculate our number of seconds by inserting the calculation box \'secs = Secs 1\' 15.
Drag the output box from the left sidebar below the calculation and we will set the output to the relay we will connect to the pic16 port.
Clicking on the output will pop up \"property output\", here we set the variable to 2 (
This will open the second relay on our relay board and the click on and off of the relay will simulate the ticking of the clock per second)17.
To simulate the trunk in our program, insert the LED array output and make sure to go to the properties menu to connect it to the PORTC-
Our relays will be connected to our pic18.
The next step is to display the meter for seconds on the bottom line of the LCD display.
By inserting the component macro and setting the \"cursor\" on the x-axis to 10, the setting on the y-axis to 1, this will display the meter for several seconds in the displayed red box.
My LCD display is 16 wide 2 low and reads 0,0 from the top left and 15,119 from the bottom right.
Insert the delay from the left sidebar below the LCD cursor, and then double-click it to display the properties.
Set the delay value to 1 second.
This is our second timer. 20.
The next stage is to print our seconds onto the LCD, which is done by inserting the component macro, selecting \"print number\" from the menu and setting our expression to \"seconds\" 21
In order to turn off the relay in time and let it check again in the next second, we put the 0 output into the PORTC by inserting the output and setting the variable to 022.
Now enter a delay of 10 ms to allow the relay time to be turned on and off in the circuit.
There is no delay, there is not enough time for the off signal to register in the circuit to turn off the relay.
This is achieved by inserting the delay and setting the time property to 10ms23.
Time to make a decision so that when your seconds counter reaches 60 it will add a minute to your clock and reset to zero, this is done by inserting a decision and setting it to if\'secs = 60\' 24.
Then insert the following in this decision;
The calculation of inserting secs = 0 inserts the component macro into the position of the LCD cursor (x:10, y:1)
Insert a component macro on the LCD that prints the string code (
So it doesn\'t print anything because it adds a minute)
Now insert a calculation for minutes to start counting: Mins = Mins 1 insert the component macro into the position of the LCD cursor (x:6, y:1)
This will calculate the number of minutes below, and set the number of minutes read out on the LCD ininsert on the LCD. If it\'s hard for you to remember how to perform the previous steps, the print on the LCD will go back and look at the previous stages that break it down a bit more.
This stage is basically the same as the last one, but is modified to calculate minutes instead of seconds.
Time to make a decision so that when your minutes counter reaches 60 it will add an hour to your clock and reset to zero, this is done by inserting a decision and setting it to if \'mins\' = 60\' 26.
Start counting hours can be done by inserting the calculation of mins = 0 on the LCD cursor (x:6, y:1)
Insert a component macro on the LCD that prints the string code (
So it doesn\'t print anything because it adds an hour)
Insert the calculation immediately so that the number of minutes starts counting: Hrs = Hrs 1 insert the component macro into the position of the LCD cursor (x:1, y:1)
This will calculate the following hours, in which you set the number of hours read out on a component macro on the LCD that prints the number of hours back to look at the previous stage, these stages will break it down more.
Now, what happens once you reach 24 hours?
Well, I want my clock to go back to zero and stay zero (
But you can easily modify it with a little bit of ingenuity)
Because it is more like a 24-hour timer than the actual clock.
If \"hrs = 24\" 28, a decision with parameters is inserted.
If you want a 24 hour timer like me then: insert a loop and once the circuit goes through the loop for 24 hours it will stay at 00:00:00 mins = 0, secs = 0 insert a call component macro on the LCD that will clear the bottom line (Y:1)
Insert a call component macro that outputs the \"00\" string on the LCD (
00 space 00 space)29.
Now, the best way to make sure your program works is to run your simulation at each stage and see how it works.
You can do this by pressing the play button at the top of the taskbar and then pressing stop while you\'re happy.
Here I run it all the time and after watching it for 24 hours it has turned to 0 as per my requirement for it 30.
To plug the program written into the chip, plug the PIC into the computer via a USB cable, and then power on the PIC.
Click the \"compile to chip\" button, which will pop up another window in the Flowcode \"compiler message\" waiting for it to show that it is done, it will send your program to your chip to make your motherboard work perfectly, but is this the end of programming, simple?
Now is the time to crack the hardware.
Required parts: screwdriver usb cable (
From PIC to USB, my USB cable is standard printer)
Power Unit (
Insert your photo and power it)
The components I\'m using are all part of the matrix set we\'re using at work, and the pic I\'m using contains the 16F1937 microchip.
This is the picture of the tray we got with our photos, I have boxed the components we need so you know what you are looking at in the rest of this tutorial. 31.
First, insert the trunk into portc32.
Now insert your LCD board into portb3.
Plug your PIC into the USB cable on the computer side and PIC end34.
Use a screwdriver to insert the power unit of the PIC wiring to loosen and tighten the screw on the top of the pin, as long as it is copper and the length is appropriate, it doesn\'t matter which wire you use (
To illustrate the location of the wire connection, I checked my picture with the corresponding color line 35.
Connect the 14 V wire on the PIC to the V on the relay board, which will power the relay (see brown wire)36.
Connecting wires from GND (ground)
On the GND photo on the trunk board (see red wire)37.
Connect the wire of V on the PIC to the V on the LCD board (see white wire)
Once your photo is assembled and your program is installed on your chip, it should calculate for a few seconds, minutes and hours perfectly as a 24 hour timer, once timed out, set to 0.
Because my current relay is also ticking every second like a real clock!
Interesting projects are much easier than I thought.
I have attached the Flowcode document I used to make a 24 hour timer so you can modify it, look at it, or play it yourself.
It is perfectly combined with my photo, so fingers crossed it will transition for your photo.
I also attached Powerpoint for all the steps in this tutorial so you can have breakfast leftovers when needed.
Custom message
Chat Online 编辑模式下无法使用
Chat Online inputting...