0% found this document useful (0 votes)
14 views7 pages

Lab 2

Uploaded by

Mariam Ayman
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views7 pages

Lab 2

Uploaded by

Mariam Ayman
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

Lab 3: LCD screen and counter

In this Lab we will step through creating a simple counter, and displaying that value
on an LCD display.
In this Lab you will be introduced to a new flowchart command; the component
macro.A component macro is how we interface with the more complex components
in Flowcode.
For simple things like switches and LEDs we can use inputs and outputs.
However, if we want to talk to an LCD screen we may need to execute a series of
commands back and forth.
Create a new flowchart with the correct microcontroller selected and add an LCD
(Generic, 20 x 4) screen to the 2D simulation panel.
With the LCD screen added to the simulation panel you should check its;

connection BL0061 BL0086

Data 0 PortB0 PortD0

Data 1 PortB1 PortD1

Data 2 PortB2 PortD2

Data 3 PortB3 PortD3

Register Select PortB4 PortD4

Enable PortB5 PortD5

We will now quickly progress through a few steps where we are doing familiar
coding.

1. Create a variable called 'Counter' of type byte, and initialize it to zero.


a. To create a variable, click on the Variables icon (1) Project Explorer
and click the down arrow (2) next to 'Variables' click 'Add new' (3).
b. The 'Edit variable name' window will appear. There are 4 sections we
should fill out.
c. Here we’ve called our variable Counter. Note you cannot have spaces
in variable names.
d. We have initialized our variable to zero to ensure no old values remain
in memory
e. We are selecting this as a type 'byte', therefore it can save any value
between 0-255.
2. Place a while(1) loop into your flowchart
3. Place a calculation box within this while(1) loop, and increment the variable
counter using a calculation command

Counter = Counter + 1

4. Place a 1 second delay after the calculation box


If we were to run this program now it would simply count up from 0-255.
Since we are using a variable type of Byte for 'Counter' it will reach 255 and roll back
around to zero where it will continue counting again.
Despite having a counter we do not yet have a method of displaying this information
on the LCD screen.
We will now introduce component macros.
Add a component macro to the very start of your flowchart, above the while(1) loop,
as seen below;

Open its configuration properties, as usual, by double clicking on the component


macro. You will see the box below.
Press the + button next to the LCD_4x20 component to access the available
component macros. Once opened you will see a list of all component macros
available for the LCD screen.These are all pre-written sub routines, developed by
Matrix, to assist you with using the LCD screen.
The first we want to use is 'Start'. Scroll down the list, select Start and press 'OK'.

Alternatively, within Project Explorer select 'Components' icon


Press the + button next to the LCD_4x20 component to access the available
component macros.
The Start component macro can be dragged to the correct position.

The Start routine is required to initialize the LCD screen, so that the microcontroller
knows it exists, and sets up timing routines etc.
With the screen initialized we need two more component macros.
The first is to display the value of the variable ‘counter’ on the LCD screen.
Add another component macro within the while(1) loop, directly above the calculation
box.
Configure it to be a ‘PrintNumber’ macro, however, you will notice that there is a
parameter box that you must now fill in, called ‘Number’.
Here we must write the name of our variable; Counter.
Each time this command is now executed it will display whatever value we currently
have saved in counter.
There is one final component macro we need. We want our value of Counter to
always be displayed in the top left corner (X,Y position; 0,0).
Currently our program will write the value of Counter on the LCD screen, however,
the cursor will move each time we write a value and we will end up with something
like below;

What we need to do is clear the LCD screen each time we write a new value.
Luckily for us executing a clear screen routine also moves the cursor position back to
(0,0). Add another component macro above the PrintNumber macro, and configure it
to ‘Clear’.
We have now finished third lab.
You should first test your program is right by comparing it to the code listing below.
Simulate, before downloading to hardware to check it's worked as expected.
Did you know?
The BL0114 combo board has small slide switches used to turn
the LCD screen and the 7SEG LCD screen on and off.
Make sure that this switch in in the ‘on’ position for the LCD
screen when using the display.

You might also like