labexcercise_2
TRANSCRIPT
-
8/13/2019 LabExcercise_2
1/10
Miguel Alejandro Alvarado Vzquez A01222725 Microcontrollers
Rodrigo Navarro Romero A01221761 Prof.Diego Villa
Diego Alejandro Cerda Contreras A01222445 14/09/2011
MicrocontrollersLab Exercise 2
Keypad and LCD display
Introduction
In this second exercise, the challenge was to build from scratch a driver for a keypad andto use a LCD to display text on it. The objective was to develop a prototype that simulates the
behavior of a microwave using the two modules mentioned before.
The hardware was very easy; we just have some small problems that we fixed quickly. Here is the
hardware diagram that we used to implement the hardware:
Hardware Diagram
For the second lab exercise we had to design the operation of a microwave oven, we also
needed to implement a driver for a matrix keypad. We made two functions, one function to
control the keypad and to return the value we got from it, and the other to just send one time the
desired number just once. For the microwave oven we made just one single function to control the
uC
PIC18F4620
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
4VCC
VCC
VCC VCC
VCC
5V
C1
15pF
C215F
C5
100nF
C6
100nF
10k
K1
1 2 3 A
4 5 6 B
7 8 9 C
* 0 # D
470 X4
X410k
LCD
VSS1
VDD2
ADJ3
RD4
WR5
A06
D07
D18
D29
D310
D411
D512
D613
D714
CS15
RST16
DOFF17
NC18
BL-A19
BL-K20
2.2k
VCC5V
15
VCC5V
10k
RST
CS
RD
WR
A0
RD
WR
10k
VCC
RST
CS
A0
Dip
LED
Dip
J1
LED 100
LED1
200
LED2
100
LED3
-
8/13/2019 LabExcercise_2
2/10
-
8/13/2019 LabExcercise_2
3/10
the display of the numbers in the lcd screen and also because we could check if the time was a
valid number or not. To set a time we check if the input received from the button is a number, if it
is was, we shifted the values in the array to the left and then setting the input value in the less
significant index of the value. If the input is a letter we simply setup a predefined time. If the input
was the star then we assumed the user wanted to cancel the input so we just set the time to
zeros. Finally if the input was the pound sign we know that the user wants to start, so first we
checked if the time is bigger than 0000, if not we set the time at 30s. After that we set the variable
telling the microwave oven is on to 1.
The first thing we do if the microwave oven is on is checking if the time is a valid input,
that means a time lower than 1 hour and with less than 60 seconds, if time is invalid we correct it.
Then we check if we received as an input from the keypad, if we received one we check if the
input was a star, if it was we simply set the count to zero and put the microwave off. If the input
was the pound sign we ad 30 seconds to the count, if the input was any other button we simply
ignore it. If the oven door is open at any time, it enters a cycle that does nothing but keeping the
heart beat LED blinking. The only way to leave that cycle is to close the door and pressing thepound button, so that the count would start from it left it off, or by pressing the star button
making the countdown go to zero.
Every second we decrease a number in the countdown, decreasing a number is a little
complicated because we have to make special conditions because the second bit goes from 0 to 6
and so does the zero bit.
No matter if the microwave oven is working or not, we have to display the time on screen,
so after both ifs we print Time Left: followed by the number in the time array in index 0, in index
1, :, in index 2 and in index 3.
When the time is finished, we put the microwave oven as not working and call the buzzer
method.
The buzzer methods counts to 30 seconds, it makes a buzzer ring every time that number
is overflowed, if the door is opened at any time, it leaves the cycle and returns to the microwave
oven functionality function.
While implementing the microwave oven we found many difficulties. The most important
ones were difficulties from getting the inputs from the keypad, mainly because sometimes we
needed a value to be recorded as input only one time, but in other functions we needed a
continuous input. To solve this we implemented another method in the keypad driver so that it
could return an input as a pulse or as a continuous function.
The more difficult issue we had was to implement the heartbeat LED, to do this we
standardized all the delays in the method. We refreshed the screen every .5 seconds, so we had to
make the rest of the delays in the function to add up to .5 seconds, so every time the screen is
refreshed we could toggle the heart beat LED.
-
8/13/2019 LabExcercise_2
4/10
Also we werent able to control the time accurately due to the overhead our functions
had. We tried with the oscilloscope and by comparing our countdown with a real chronometer to
check if we had an accurate approximation to a 1 second count in the microwave oven
implementation.
Conclusions:
Rodrigo Navarro Romero: With this lab exercise I learned how to implement many debug
techniques such as printing 0xff at an output port if any condition was met, in order to check if the
program operated correctly, other debug technique I learned to implement was to make bigger
delays, so that you can check all the functionality of the program step by step. I also founded out
that no matter how deep you check the software in order to find issues, you can still have really
silly mistakes in hardware, which are very simple to solve, but very hard to find.
Diego Alejandro Cerda Contreras: Every time I get more and more excited about microcontroller
applications, now I can see that there is no limit about the implementation you can reach using
this kind of technology. I realize that using somebodys code is a quick fix for our problems, for
instance, in this case the LCD driver, but I can say that our Keyboard implementation was difficult
to develop, we had a lot of issues trying to get a proper functionalities, I discover that the using of
simple code tricks to debug is very helpful, I also found that we have very other benefits when
programing the keyboard driver, also more control of it, and of course more customization.
Miguel Alejandro Alvarado Vzquez:Again for me this was a very interesting Lab Exercise because
of the introduction of a keypad and a LCD. At the beginning we focused on the development of the
keypad driver and it was good until we start getting problems. One of the issues that we had with
the keypad was very annoying because we couldnt fix it, so we decide to change the way the
keypad driver was working. With this problem I found that sometimes the best solutions is the
easiest way. Also at the beginning we have some basic hardware problems that were fixed with no
effort.
For the part of the LCD I hadnt written text on it (only images). So I needed to learn on how to
print a string on it but at the end it was no so difficult. In general working with the LCD is not
difficult the problems that we encounter were hardware problems and that the LCD sometimes
doesnt respond very well.
In this exercise I learned that you must pay attention on what are you doing, because if the logic is
wrong, the program will not function properly and you will think that its a hardware issue, of
course this happened to us and because of that, we lost a lot of time until we finally found that it
was a software problem.
-
8/13/2019 LabExcercise_2
5/10
-
8/13/2019 LabExcercise_2
6/10
Keypad_Value
Buttons == Las_Value
If(No_Repetition)
Yes
No_Repetition=1
No
No_Retition=0
Return_Value =Buttons
Yes
Return_Value = 0xffNo
Last_Value=ButtonsRetunr
Return_Value
Diagram for Keypad_Valuefuction.
-
8/13/2019 LabExcercise_2
7/10
LCD_Microwave
Microwave OnIs time an invalid
number
Keypad_Input is
a number?NoYes
Keypad_Input is a
predefined time?
Keypad_Input is
the cancel button
Keypad_input is
the start button
NO
NO
NO
Time= Time
-
8/13/2019 LabExcercise_2
8/10
Buzzer
K=0
L=0
Is K==1?
Is K==29
NO
Is the door
opened
NO
Delay ms (200)
L++
Is L==4?
Heart beat LED
L=0
K++
YES
Ring the buzzer.
K=0
NO
K=32
L=8
Is k< 30 Exit functionNOYES
YES
YES
YES
NO
Diagram of the Buzzer function.
-
8/13/2019 LabExcercise_2
9/10
.5Hz Frequency of the Heart Beat LED.
.5Hz Frequency of the Heart Beat LED
-
8/13/2019 LabExcercise_2
10/10
Hardware Implementation.
Final Prototype.