Вы находитесь на странице: 1из 11

MICROPROCESSOR SYSTEMS LABORATORY 5

(ECE515)

EXPERIMENT 5

GENERAL PURPOSE INPUT /OUTPUT (GPIO) HARDWARE INTERFACE


KEYPAD, SEVEN SEGMENT AND LCD DISPLAY

OBJECTIVES

1. To write and compile programs using Keil uVision4


2. To run programs using NUVOTON NUC140 development board
3. To write program for hardware interface using GPIO – Keypad, Seven-Segment and
LCD display

Software: Keil uVision4


Devices on NUC140: Keypad, Seven-segment and LCD display.

TASK 1:

Design a door security system which required a user to enter 3-number password using
keypad. First, the LCD display displays the welcome message and ask user to enter
password. If the password entered is correct, the LCD display will display “Access
granted” and seven segment will count down from “9” to “0” to allow the user to enter and
after that the door will locked again. And if the password is incorrect, the LCD display will
display “Access denied” and the door will not be opened.

1 2 3
4 5 6
7 8 9
PROCEDURES

1. Design a programming flowchart to perform the task given above.


2. Based on the flowchart, write, run and test your program using NUC140 development
board.

RESULTS

start

Lcd display
“WELCOME HOME”
“ENTER PASSWORD”

INPUT
“ENTER PASSWORD”

CHECK NO
DOOR LOCK PASSWORD Lcd display
“Access denied”

YES

Lcd display
“Access granted”
7-segments
contdown

YES CHECK NO
COUNTDOWN
I=0?
PROGRAM CODE

#include <stdio.h>

#include "NUC1xx.h"

#include "Driver\DrvSYS.h"

#include "Driver\DrvGPIO.h"

#include "Seven_Segment.h"

#include "ScanKey.h"

#include "LCD_Driver.h"

/* initialize constant */

uint8_t temp,password1,password2,password3,password4,i;

/* delay subroutine program */

void delay_loop(void)

uint32_t i,j;

for(i=0;i<3;i++)

for(j=0;j<300000;j++);

/* Scan keypad subroutine program */

void Scan_keypad(void)

DrvGPIO_SetBit(E_GPA, 0); //All pins are set

DrvGPIO_SetBit(E_GPA, 1);

DrvGPIO_SetBit(E_GPA, 2);

DrvGPIO_SetBit(E_GPA, 3);

DrvGPIO_SetBit(E_GPA, 4);

DrvGPIO_SetBit(E_GPA, 5);

DrvGPIO_ClrBit(E_GPA,3);

if(DrvGPIO_GetBit(E_GPA,2)==0)

{
temp = 1;

if(DrvGPIO_GetBit(E_GPA,1)==0)

temp = 2;

if(DrvGPIO_GetBit(E_GPA,0)==0)

temp = 3;

DrvGPIO_SetBit(E_GPA,3);

DrvGPIO_ClrBit(E_GPA,4);

DrvGPIO_SetBit(E_GPA, 5);

if(DrvGPIO_GetBit(E_GPA,2)==0)

temp = 4;

if(DrvGPIO_GetBit(E_GPA,1)==0)

temp = 5;

if(DrvGPIO_GetBit(E_GPA,0)==0)

temp = 6;

DrvGPIO_SetBit(E_GPA,4);

DrvGPIO_ClrBit(E_GPA,5);

if(DrvGPIO_GetBit(E_GPA,2)==0)

temp = 7;

}
if(DrvGPIO_GetBit(E_GPA,1)==0)

temp = 8;

if(DrvGPIO_GetBit(E_GPA,0)==0)

temp = 9;

/* main program*/

int main(void)

/* Unlock the protected registers */

UNLOCKREG();

/* Enable the 12MHz oscillator oscillation */

DrvSYS_SetOscCtrl(E_SYS_XTL12M, 1);

/* HCLK clock source. 0: external 12MHz; 4:internal 22MHz RC oscillator */

DrvSYS_SelectHCLKSource(0);

/*lock the protected registers */

LOCKREG();

/* Initialize GPA3 - GPA5 as output and GPA0 - GPA3 as intput */

DrvGPIO_Open(E_GPA, 0, E_IO_QUASI); //COLUMN1

DrvGPIO_Open(E_GPA, 1, E_IO_QUASI); //COLUMN2

DrvGPIO_Open(E_GPA, 2, E_IO_QUASI); //COLUMN3

DrvGPIO_Open(E_GPA, 3, E_IO_QUASI); //ROW1

DrvGPIO_Open(E_GPA, 4, E_IO_QUASI); //ROW2

DrvGPIO_Open(E_GPA, 5, E_IO_QUASI); //ROW3

DrvGPIO_Open(E_GPB, 11, E_IO_OUTPUT); //BUZZER

DrvGPIO_Open(E_GPC, 12, E_IO_OUTPUT); //LED5

DrvGPIO_Open(E_GPC, 13, E_IO_OUTPUT); //LED6

DrvGPIO_Open(E_GPC, 14, E_IO_OUTPUT); //LED7


DrvGPIO_Open(E_GPC, 15, E_IO_OUTPUT); //LED8

DrvGPIO_Open(E_GPB, 11, E_IO_OUTPUT); //BUZZER

DrvGPIO_Open(E_GPA, 12, E_IO_OUTPUT); //RGB LED BLUE

DrvGPIO_Open(E_GPA, 13, E_IO_OUTPUT); //RGB LED GREEN

DrvGPIO_Open(E_GPA, 12, E_IO_OUTPUT); //RGB LED RED

DrvGPIO_Open(E_GPB, 15, E_IO_INPUT); //SWITC

Initial_pannel(); //call initial pannel function

clr_all_pannal();

print_lcd(0, "Welcome Home");

print_lcd(1, "Enter Password");

while (1)

Initial_pannel(); //call initial pannel function

clr_all_pannal();

print_lcd(0, "WELCOME HOME");

print_lcd(1, "ENTER PASSWORD");

while (temp==0)

Scan_keypad();

password1=temp;

// call subroutine to output keypad pressed to seven-segment

close_seven_segment();

delay_loop();

print_lcd(2, "*");

temp=0;

while (temp==0)

Scan_keypad();

password2=temp;
// call subroutine to output keypad pressed to seven-segment

close_seven_segment();

print_lcd(2, "**");

delay_loop();

temp=0;

while (temp==0)

Scan_keypad();

password3=temp;

// call subroutine to output keypad pressed to seven-segment

close_seven_segment();

print_lcd(2, "***");

delay_loop();

temp=0;

while (temp==0)

Scan_keypad();

password4=temp;

// call subroutine to output keypad pressed to seven-segment

close_seven_segment();

print_lcd(2, "****");

delay_loop();

temp=0;

if (password1==3){

if (password2==6){

if (password3==9){

if (password4==1){
Initial_pannel(); //call initial pannel function

clr_all_pannal();

print_lcd(0, "Access Granted,");

for (i=9;i<10;i--){

close_seven_segment();

show_seven_segment(0,i);

show_seven_segment(1,i);

show_seven_segment(2,i);

show_seven_segment(3,i);

delay_loop();

else{

Initial_pannel(); //call initial pannel function

clr_all_pannal();

print_lcd(0, "Access Denied");

delay_loop();

DrvGPIO_ClrBit(E_GPB, 11);

delay_loop();

DrvGPIO_SetBit(E_GPB, 11);

}
RESULT ON THE BOARD NOUVOTON NUC 140

figure 1: LCD display on Nouvoton

Figure 2: LCD and 8-segments Display


Figure 3: LCD display
DISCUSSION

In this project the student was asking to do the home security using nouvoton board.
The requirement for this project as in task given above. The student need to design and also
sketch the flowchart for easy went to write the coding. In result the flowchart 1 is the represent
to the flow for home security. After the sketching the flowchart the writing coding is begin.
The coding of this program using closed loop with while (1). For the coding always repeating
because it uses the keypad and always waiting the input from user. In writing the coding the
compulsory coding need to add such include and declare all the integer uses in the program. In
this program the input from user as a password need to be enter is 3. The statement use in this
code is if and else statement for the all three passwords to be enter from the user. if the password
entered is the same to the password has been set in the code the LCD will display the “Access
Granted” for the door open. After the door open then the 8-segment will count down then
display on the 8-segments. After the countdown has finished then the door will automatically
lock. The LCD will display back the welcome. But if the entered the password was wrong the
LCD will display “Access Denied”. Then the LCD will display back the “ welcome and entered
the passwords”. The result test on the nouvoton is recoded in the result in figure 1, figure 2 and
figure3.

CONCLUSION

As a conclusion, by doing the experiment five, the student learns on how to sketch the flowchart
for an application stated to write the coding. The student also leans on how to write the coding
and also student lean on how to implement the coding into the nouvoton board. The not only
write the coding but also know how to interface another input and output that have on the
nouvoton boards. After write the coding the student need to downloads the coding into the
board.