Sei sulla pagina 1di 10

Miguel Alejandro Alvarado Vzquez A01222725 Rodrigo Navarro Romero A01221761 Diego Alejandro Cerda Contreras A01222445 Microcontrollers

Lab Exercise 2 Keypad and LCD display Introduction

Microcontrollers Prof.Diego Villa 14/09/2011

In this second exercise, the challenge was to build from scratch a driver for a keypad and to 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:
K1

1
VCC 10k LED3 100 LED2 15F C2 4 uC 200 VCC
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21

2 5 8 0

3 6 9 #

A B C D

5V

470 X4

4 7 *
10k X4

VCC

C1

CS A0 Dip LED RD WR
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20

2.2k

5V VCC LED 100

15pF WR

RD

LED1

LCD
VSS VDD ADJ RD WR A0 D0 D1 D2 D3 D4 D5 D6 D7 CS RST DOFF NC BL-A BL-K

PIC18F4620 RST 10k

A0

Dip VCC VCC VCC

CS

C6 100nF

C5 100nF

J1

RST 10k 15

5V VCC
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

time and the logic operation of the microwave oven. It received as inputs the keypad and also a switch representing the door of the microwave oven. It outputted the time in a four char vector, so the lcd display could print it and a LED representing the oven being on or off. We also made another function in order to implement the buzzer and the time between when the time has finished and when the user opens the door. We implemented the keypad driver with a very simple function actually; we made two for cycles, one inside the other. The first cycle would control the row count, while the second cycle would control the column count. We sent a 1 through every row one at a time, then we started reading from each one of the columns in order to detect if any button in that row had been pressed. If nothing was read we sent the 1 in the next row and started reading from the columns again, if we detected that one button had been pressed we checked again and verified that the input was the same, if it is equal the second time, we return the value in the matrix index related with the number of row and column where the input was detected. We a made a four by four matrix that contained all the numbers and letters from the keypad, the method would return the value contained in the matrix in the index Column_Count, Row Count. If no input was detected we simple returned 0xff, so that another function could interpret this as nothing being pressed. While implementing this method we found many difficulties and issues. First we had to design what method was more efficient, we first thought in using mathematic operations in order to know what value to return, but we had problems with designing an algorithm that could return the values in the last row *,0 and # because they didnt obey any patron according to the other buttons. After deciding to implement the array, we found out the first issues while trying to get an input from the buttons, we had issues as silly as not grounding the pins correctly, that we didnt send other pins to zero and due to the fact that we put the elements in the array upside down, but those problems were easily found and solved, on the other hand we had many troubles trying to avoid an input to be recorded more than once. We werent able to avoid the buttons in rows 2, 3 and 4 to be recorded many times, after more than 8 hours we founded out that the problem was there was that an if condition was always true, so the value would always blink . We decided that the simplest way to solve our problem was to leave that method returning the value as long as the button is pressed. But we implemented another method that received the input from the first one and checks if the input is the same as the last one it received, if its different, it returns the input value, otherwise it returns 0xff. We found really useful this implementation when designing the microwave oven because there were times in which we needed an input to be received only once, and also times in which we needed the input to be received as long as the button was pressed, so we could combine booth methods and make things a lot easier. To implement the functionality of the microwave oven, we decided to make a function that first checks if the oven is working or not, if not it waits until a time is entered and the start button has been pressed. The time variable is an array because that way we could easily control

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 the pound 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.

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.

Anexes:
Read Button

Row_Count

Column_Count Check the input again YES Is an input received?

NO YES Is Column_Count lower than 4?

Are the inputs the same

NO

YES

YES

NO

Ret_Value = Value stored in the matrix in the index [row][column]

Ret_value=0xff

Is Row_Count lower than 4? Return Ret_Value NO

Ret_Value = 0xff

Diagram for Keypad functionality.

Keypad_Value

Buttons == Las_Value

No No_Retition=0

Yes No_Repetition=1

If(No_Repetition)

No

Return_Value = 0xff

Yes

Return_Value = Buttons

Last_Value=Buttons

Retunr Return_Value

Diagram for Keypad_Valuefuction.

LCD_Microwave

Correct the value

YES

Is time an invalid number

Yes

Microwave On

No

Keypad_Input is a number? NO

YES

Time= Time <1 + Keypad_input

NO Is Keypad_Input Cancel NO

Time = 0000 Microwave oven is OFF

YES

Keypad_Input is a predefined time?

YES

Time=predefined time

NO Is keypad_Input start and Plus_30 equals 0

Time=Time+30 Plus_30=1

YES

Keypad_Input is the cancel button

YES

Time=0000

YES

NO

Is the input start or cancel

YES

Is the door opened NO

NO

NO Decrease time NO Is time zero

Keypad_input is the start button

YES

Is time bigger than 0000 YES

NO

YES Microwave Oven is off, call the buzzer function

Time=30s

Microwave is ON

Diagram of Microwave functionality.

Buzzer K=0 L=0

Ring the buzzer.

YES

Is K==1?

NO

K=0

YES

Is K==29

NO

Delay ms (200) L++

K=32 L=8

YES

Is the door opened

NO

Is L==4?

YES NO Heart beat LED L=0 K++

YES

Is k< 30

NO

Exit function

Diagram of the Buzzer function.

.5Hz Frequency of the Heart Beat LED.

.5Hz Frequency of the Heart Beat LED

Hardware Implementation.

Final Prototype.

Potrebbero piacerti anche