-
HANOI UNIVERSITY OF SCIENCE AND TECHNOLOGY
Department of Electronics and Telecommunication
====o0o====
REPORT
MICROPROCESSOR
PROJECT: INDOOR DEVICE
CONTROLLER CIRCUIT
Group: 03 APEEE2 20132
ng Hng Anh
Thanh Tng
Trn Hng Hi
L Kh Linh
20111105
20112133
20111021
20111779
Instructor: ASSOC PROF. DR. PHM NGC NAM
Hanoi, 6/2014
-
Microprocessor report 2014
2
HANOI UNIVERSITY OF SCIENCE AND TECHNOLOGY
Department of Electronics and Telecommunication
====o0o====
REPORT
MICROPROCESSOR
PROJECT: INDOOR DEVICE
CONTROLLER CIRCUIT
Group: 03 APEEE2 20132
ng Hng Anh
Thanh Tng
Trn Hng Hi
L Kh Linh
20111105
20112133
20111021
20111779
Instructor: ASSOC PROF. DR. PHM NGC NAM
Hanoi, 6/2014
-
Microprocessor report 2014
3
Evaluation Criteria Score
0. Total Score 10.0
1. Minus
1.1. No product
1.2. No hardware report
1.3. Lack of function: Sign in from keypad
1.4. Lack of function: Display password/Sign in status on
LCD
1.5. Lack of function: Warnning when sign in wrong 2 times
1.6. Lack of function: Changing password
1.7. Lack of function: Display date, time on LCD
1.8. Lack of function: Alarm turn off LED
1.9. Lack of function: Auto turn on/off LED depend on light
intensity
1.10. Lack of function: Display temperater on 7 segments
1.11. PCB have no name of group
1.12. A sparsely report/lack of content (name of
project/group/content/ requirement of procject/plan/block
diagram/code)
2. Bonus
2.1. Beautiful PCB and smart order of components
2.2. Function have a good reaction (sensibility, speed of
calcultion, display)
2.3. Function: Using house model to demo system
2.4. Function: Auto turn on LED when peole enter the room by
using 2.5. infared sensor
2.6. Having other function
2.7. Code includes ASM code
2.8. Easy to use (large keypad, clear note, simple
operation)
2.9. Clear presentation, answered speciality questions
TOTAL:
-
Microprocessor report 2014
4
CONTENT
CONTENT
..................................................................................................................
4
LIST OF IMAGES
......................................................................................................
5
LIST OF TABLES
......................................................................................................
5
PREFACE
...................................................................................................................
6
I. Project disription
...................................................................................................
7
II. System design
......................................................................................................
16
III. Conclusion
...........................................................................................................
28
REFERENCE
............................................................................................................
28
APPENDIX A: MEMBERS
.....................................................................................
28
APPENDIX B: CODE
..............................................................................................
30
APPENDIX C: USER GUIDE
.................................................................................
38
-
Microprocessor report 2014
5
LIST OF IMAGES
Figure 1. Block diagram of system
Figure 2. Plan and work distribution
Figure 3. Keypad block
Figure 4. Light sensor block
Figure 5. LM35
Figure 6. Temperature sensor block
Figure 7. Temperature display block
Figure 8. Display block
Figure 9. Clock block
Figure 10. Alarm block
Figure 11. Microcontroller block
Figure 12. Source block
Figure 13. Schematic on Proteus
Figure 14. Schematic on Altium
Figure 15. System layout
Figure 16. Final product
Figure 17. Group 3
LIST OF TABLES
Table 1. System blocks and components
Table 2. Components cost
-
Microprocessor report 2014
6
PREFACE
We have used traditional keys and locks for centuries; they have
helped
human a lot in protecting their properties. However, the keys
can easily be stolen;
anyone with the stolen keys can open doors and access buildings.
To avoid that
disadvantage, we introduce our secure electronic lock which is
based on a
microcontroller of PIC 16f series. Our locks user interface
contains a keypad, a
LCD, a 7-segment LED and an indicating LED. This I/O interface
allows the
users to enter the password to unlock the door, change the
password, check the
temperature, check or change the date and time, and set-up the
sleeping time for
the lamp.As digital technology has evolved dramatically in
recent years, devices
like this lock have become cheaper and more reliable than ever.
Thus, it can
clearly be seen that houses equipped with digital door locks
would soon lead the
trend of the future residency.
-
Microprocessor report 2014
7
I. Project discription
1.1 Functional requirements
IDLE STATE
o Activated when the lock is not in used
o The LCD displays the current date and time. The first line
displays the
date with the format Month Date, Year. The second line displays
the
time in the format HH:MM:SS and in the 24-hour system.
o Password must be entered before using any function of the
lock.
UNLOCK FUNCTION
o The user presses the Unlock button to activate the door
unlocking
function.
o The LCD displays Enter Password: and offers the user enough
space
to enter the password through the number keys from number 0
to
number 9.
o The password contains 8 characters and the characters are in
numbers
only to reduce the complexity when the user wants to get
indoor.
o After finish entering the password, the user presses the OK
key to
confirm his password. If the password is correct, the GREEN LED
is
turned on and the LCD displays Correct Password on the first
line
and Welcome home on the second line for 5 seconds before
returning
to idle state displaying date and time. If the password is not
correct, the
lock notifies the user by displaying Wrong Password on the first
line
and Try again on the second line for 3 seconds, then return to
the
enter password stage. If the user continues to enter a wrong
password,
the alarm is activated, the RED LED is turned on and all the
keys are
disabled for 15 seconds. After that, the lock returns to idle
state and
displays date and time.
MENU KEY: The user presses the Menu key to go through the list
of
available additional functions. Each time the key is pressed,
the LCD
-
Microprocessor report 2014
8
displays the next function. When the last function is reached,
the next thing
to be displayed is the first function. Each function are
displayed on the
LCD:
o Change Password (1st line) 1/4 (2nd line)
o Change DateTime (1st line) 2/4 (2nd line)
o Setup Timer (1st line) 3/4 (2nd line)
o Reset Timer (1st line) 4/4 (2nd line)
The user presses the OK key when any function is displayed to
activate
that function.
CHANGE PASSWORD FUNCTION
o When the Change password function is activated, the lock asks
for
the old password. The LCD display Old password? (1st line)
and
leave the second line for entering the old password.
o Finishing entering the old password, the user presses OK to
confirm.
o If that was a wrong password, the LCD displays Wrong
Password
(1st line) and Enter again (2nd line) for 3 seconds before
return to the
enter password stage.
o If the password is incorrectly typed twice, the alarm is
activated, the
RED LED is turned on, the LCD displays Warning!! and the
keypad
is disabled for 15 seconds before getting back to the idle
state
displaying date and time.
o If the old password is correctly entered, the lock asks for
the new
password by displaying on the LCD New password? (1st line) and
the
second line for entering the new password.
o After the user presses OK to confirm the new password, the
lock asks
the user to confirm the new password by entering again. LCD
displays
Please reenter.
o If the user reenters correctly, the LCD displays Success! for
3
seconds before getting back to idle state. If the user reenters
incorrectly,
the LCD displays Mismatch! for 3 seconds and the lock gets back
to
-
Microprocessor report 2014
9
the idle state.
CHANGE DATE-TIME FUNCTION
o When the Change Date function is activated, the lock asks for
the
new date. The LCD display Enter new date (1st line) and
yyyy/mm/dd (2nd line). As the user starts to enter the date, the
format
on the second line disappears. The lock automatically adds the /
after
the user enters the year and month.
o Finishing entering the date, the user presses OK to
confirm.
o The lock then asks for the new time by displaying on the LCD
New
time? (1st line) and hh/mm/ss (2nd line).As the user starts to
enter
the time, the format on the second line disappears. The lock
automatically adds the / after the user enters the hour and
minute.
o Finishing entering the time, the user presses OK to
confirm.
o The lock displays on the LCD Done! (1st line) for 3 seconds
then
returns to idle state.
SLEEP TIMER FUNCTION
o When the Setup timer function is activated, the lock asks for
the
amount of time the user wants to set.
o The LCD display Enter sleep time (1st line) and hh/mm/ss
(2nd
line). As the user starts to enter the date, the format on the
second line
disappears. The lock automatically adds the / after the user
enters the
year and month.
o Finishing entering the sleep, the user presses OK to confirm.
The lock
then turns on the indoor light and returns to idle state.
o After the time entered passes, the lock automatically turns
off the
indoor light.
RESET TIMER FUNCTION
o When the Reset timer function is activated, if the time is not
already
set up, the LCD displays Timer not set. If the time is already
set, the
-
Microprocessor report 2014
10
LCD display Are you sure? (1st line) and OK to confirm (2nd
line).
o If the user presses OK, the setup timer cancels the sleep time
and the
lock returns to idle state.
OTHER FUNCTIONS
o At any point in using the lock, the user can press the Return
button on
the keypad to cancels whatever he is doing and return the lock
to idle
state.
o The lock displays the temperature by using 4 7-segment LEDs.
The first
two is for the value of the temperature. The third is for the
degree
sign and the fourth is for displaying C.
o Depending on the natural light around. If the surrounding
environment
is bright enough, the outdoor light is turned off. If the
surrounding
environment is dark, the outdoor light is turned on.
1.2 Nonfunctional requirements
Use the PIC 16F series.
Use the sticky keypad.
Use light sensor to determine the light intensity of the
room.
Use temperature sensor to determine the temperature of the
room.
Code includes both ASM code and C code.
PCB has group name and members.
Circuit is compact, components are arranged logically.
User interface has to be nice and friendly.
The device costs no more than 150.000VND
The measurements of the device is no bigger than: 210 297
(mm)
Use LEDs to represent the indoor light and outdoor light.
-
Microprocessor report 2014
11
1.3 Block diagram of system
Microcontroller
Keypad Light SensorTemperature
Sensor
LCD7-
segment LEDs
Indoor LED
Outdoor LED
AlarmRed/
Green LEDs
Source
Figure 1. Block diagram of system
-
Microprocessor report 2014
12
Blocks Components
Keypad Sticky 4x4 keypad
LCD 16x2 LCD
Temperature Sensor LM35
Light Sensor Photo-resistor CDS
12MM
Microcontroller PIC 16f877a
Alarm Buzzer 3V
9.5MMx12MM
LEDs 7-segment LED 0.8
Anode, 5 mm LEDs
Clock DS1307
Source 9V battery
Table 1. System blocks and components
-
Microprocessor report 2014
13
Table 2. Components cost
Components Cost (VND)
Sticky 4x4 keypad 10.000
16x2 LCD 60.000
Photo-resistor CDS 12MM 2.000
74HC595 4.000
Microcontroller PIC 16f877a 65.000
Buzzer 3V 9.5MMx12MM 5.000
7-segment LED 0.8 Anode, 5 mm LEDs 4x2.500
DS1307 3.000
Resistors 4.000
9V battery 12.000
-
Microprocessor report 2014
14
1.4 Plan and work distribution
-
Microprocessor report 2014
15
Figure 2. Plan and work distribution
-
Microprocessor report 2014
16
II. System Design
2.1 Keypad block
Figure 3. Keypad block
Keypad consists of 4 columns and 4 rows, and whenever the user
taps one button,
the column and the row corresponding to that button are shorted.
For example, if
button 7 is pressed, its corresponding column and row (col1 and
rowA) are
shorted, if a button 0" is picked, col2 and rowD are shorted,
and so on. To detect
whether which input is pressed, a microcontroller uses a method
called Scanning.
The columns here are set as outputs and row as inputs (or vice
versa).
-
Microprocessor report 2014
17
2.2 Light sensor block
Figure 4. Light sensor block
-
Microprocessor report 2014
18
2.3 Temperature sensor and temperature display block
For the purpose of measuring the temperature of the environment,
LM35 is used
as temperature sensor. The construction of LM35:
Figure 5. LM35
LM35 has 3 legs: 1 for U, 1 for Ground and 1 for output. This
sensor interfaces
with PIC follow the path LM35 - > ADC - > Microcontroller.
We have the equation
that performs the relationship between the temperature of the
environment and the
output voltage of ADC
U =
Where,
U is the output voltage
T is the temperature of the environment
K is the coefficient of LM35, often 10mV/1C
-
Microprocessor report 2014
19
Figure 6. Temperature sensor block
In our circuit Vcc=5V
Display temperature by using 7-segment LEDS:
For the porpose transform information from Pic to 7 led segments
we use 74595
LED-7 Segment will be used to display the temperature with the
help of IC
74HC595. 74HC595 is a shift register chip which connected in
serial for input and
parallel for output. The main benefit is saving pins of the
microcontroller
(maximum is 3 pins). To do that, pin Q7 of the previous IC will
connect with pin
DATA (pin 14) of the following IC. By that method, we can expand
the number of
pins of microcontroller as much as we would like to.
-
Microprocessor report 2014
20
Figure 7. Temperature display block
-
Microprocessor report 2014
21
2.4 Display block
Figure 8. Display block
The LCD would be used in 4-bit mode thus pin D0, D1, D2, D3 are
not needed and
connected to the ground.
The variable resistor sets the contrast for the display.
The 1k resistor sets the intensity of the backlight of the
display.
2.5 Clock block
Figure 9. Clock block
The two 4.7k resistors are pull-up resistors for the I2C
pins
-
Microprocessor report 2014
22
2.6 Alarm block
Figure 10. Alarm block
-
Microprocessor report 2014
23
2.7 Microcontroller block
Figure 11. Microcontroller block
Switch S1 is used as the reset button.
Switch S2 is used to implement the external interrupt which
enables the keypad
-
Microprocessor report 2014
24
2.8 Source block
Figure 12. Source block
We ues IC LM7805 to convert 12V to 5V.
-
Microprocessor report 2014
25
2.9 Schematic
Figure 13. Shematic on Proteus
Figure 14. Schematic on Altium
-
Microprocessor report 2014
26
2.10 System Layout
Figure 15. System layout
-
Microprocessor report 2014
27
2.11 Final product
Figure 16. Final product
-
Microprocessor report 2014
28
III. CONCLUSION
Reference
K54 Teaching Assistants weekly instructions
Datasheets of : PIC 16F877a, 74HC595, DS1307, Anot common 7
segments,
LCD 16x2 (HD44780U Controller/Driver)
APPENDIX A: THE CONTRIBUTION OF EACH
MEMBER
A.1. ng Hng Anh
Coding LCD library; designing display block; coding the date
time, password
functions; assembling code and schematic; participating in PCB
designing and
soldering process; editing the report.
A.2. Thanh Tng
Coding keypad library; designing keypad block; assembling code
and schematic;
main PCB designer; participating in soldering process; editing
the report.
A.3.Trn Hng Hi
Coding DS1307 library; designing clock block and light sensor
block; assembling
code and schematic; participating in PCB designing; main
solderer; editing the
report.
A.4.L Kh Linh
Coding temperature sensor library; designing temperature sensor
and temperature
display block; assembling code and schematic; participating in
PCB designing and
soldering process; main report editer.
-
Microprocessor report 2014
29
Figure 17. Group 3
-
Microprocessor report 2014
30
APPENDIX B: SOFTWARE CODE
//Main
#include
#device *=16 adc=10
#fuses HS,NOWDT,NOLVP,NODEBUG,PUT,NOBROWNOUT
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#use i2c(Master,fast,sda=PIN_A1,scl=PIN_A0)
#use delay(clock=20000000)
#use fast_io(d)
#use fast_io(c)
#use fast_io(b)
#use fast_io(a)
int1 enable_keypad=0;
#int_ext
void enableKeypad()
{
enable_keypad=1;
}
//Time is initalized here
full_time initTime()
{
full_time time;
time.year = 12;
time.month = 2;
time.day = 6;
time.date = 28;
time.hour = 23;
time.minute = 59;
time.second = 57;
return time;
}
void main()
{
set_tris_D(0xF0);
set_tris_C(0x00);
set_tris_B(0x01);
set_tris_A(0x01);
setup_adc_ports(AN0);
setup_adc(ADC_CLOCK_INTERNAL);
set_adc_channel(0);
output_low(PIN_B1);
LCDinit();
LCDclear();
LCDformatSetup();
delay_ms(2);
time = initTime();
-
Microprocessor report 2014
31
DS1307init(time);
sleep_time.hour=-1;
int16 TEMPERATURE;
ext_int_edge(H_TO_L);
enable_interrupts(int_ext);
enable_interrupts(GLOBAL);
while(TRUE)
{
resetState();
if (enable_keypad)
{
LCDclear();
LCDgotoXY(1,1);
str="Keypad";
LCDwriteStr(str);
LCDgotoXY(2,1);
str="Activated!";
LCDwriteStr(str);
while (true){
scanButton(state);delay_ms(50);
if (state[0] == 0){
if ((state[1]==3) && (state[2]==7))
{
delay_ms(200);
succ=1;
unLock(succ);
if (!succ) menu();
break;
}
else if ((state[1]==3) && (state[2]==4))
{
toggleLed();
break;
}
else if ((state[1]==1) && (state[2]==7))
{
delay_ms(200);
unLock(succ);
break;
}
}
}
enable_keypad=0;
LCDclear();
LCDgotoXY(1,1);
str="Keypad";
LCDwriteStr(str);
LCDgotoXY(2,1);
str="Deactivated!";
LCDwriteStr(str);
delay_ms(500);
LCDclear();
}
time = DS1307read();
turnOffLed(sleep_time.hour,sleep_time.minute,sleep_time.second);
LCDformatSetup();
sendTimeToLCD(time);
TEMPERATURE=UPDATE_TEMPERATURE();
PUSH_TO_LED(TEMPERATURE);
}
-
Microprocessor report 2014
32
}
=================================================================================
//Function for unlocking by entering password
void unLock(int1 *succ)
{
int count=0;
int8 wrong_try=0;
int i;
int1 pass_match=1, complete=0;
char entered_pass[8];
int star_code[8]={0,0,1,0,1,0,1,0};
succ=1;
while (!complete)
{
pass_match=1;
count=0;
unLockSetup();
while (count
-
Microprocessor report 2014
33
}
LCDclear();
}
}
=================================================================================
//Function for changing password
void changePassword()
{
int count=0;
int i;
int1 pass_match=1, complete=0;
char entered_pass[8];
char reentered_pass[8];
while (!complete)
{
pass_match=1;
count=0;
changePassSetup();
while (count
-
Microprocessor report 2014
34
else if ((state[1]==1) && (state[2]==6))
{reentered_pass[count]='6';}
else if ((state[1]==0) && (state[2]==4))
{reentered_pass[count]='1';}
else if ((state[1]==0) && (state[2]==5))
{reentered_pass[count]='2';}
else if ((state[1]==0) && (state[2]==6))
{reentered_pass[count]='3';}
else if ((state[1]==0) && (state[2]==7)) {
LCDclear();
LCDcursor(0,0);return;}
count+=1;
LCDwrite(star_code);
}
resetState();
delay_ms(600);
}
for (i=0;i
-
Microprocessor report 2014
35
=================================================================================
//Function for setting sleeptime
void setUpSleepTime()
{
int count=0;
int entered;
sleepTimeSetup();
while (count
-
Microprocessor report 2014
36
=================================================================================
//Function for scanning the keypad
void scanButton(int* state)
{
int i,j;
for (i=0;i
-
Microprocessor report 2014
37
=================================================================================
//Function for initializing the LCD
void LCDinit()
{
int i;
int init_array[3][10]={
{0,0,0,0,1,0,1,0,0,0},
{0,0,0,0,0,0,1,1,0,0},
{0,0,0,0,0,0,0,1,1,0}
};
output_high(E);
output_bit(RS,0);
output_bit(RW,0);
output_bit(D7,0);
output_bit(D6,0);
output_bit(D5,1);
output_bit(D4,0);
output_low(E);
delay_ms(100);
for (i=0;i
-
Microprocessor report 2014
38
incorrectly 3 times
=================================================================================
//Change password library
void changePassSetup() // Function for setting the changing
password screen
void confirm() // Function for confirming the password
=================================================================================
//DS1307 library
full_time DS1307read() //Function for reading the date and time
from DS1307
int toBCD (int num) //Function for converting a interger num
into a BCD
int toBIN (int num) //Function for converting a integer num into
binary
=================================================================================
//LCD library
void LCDformatSetup() //Function for setting up the format of
LCD
void LCDgotoXY(int x,y) //Function for jumping to a position
(x,y) on the LCD
void LCDwriteStr(char* str) //Function for writing a str onto
the LCD
void LCDclear() //Function for clearing the LCD
void LCDcursor(int on,int blink) //Function for controlling the
cursor: enable
and blink
=================================================================================
//Keypad library
void voltageLow(int8 index) //Function for setting low voltage
to a row
int1 isLow(int8 index) //Function for checking if a row is
pulled low
APPENDIX C: USER GUIDE
To use the keypad, push the active keypad button.
When keypad is activated:
o Press B to active the unlock function. Then enter password (8
numbers)
to unlock.
o Press * to toggle the indoor LED.
o Press D to enter the functions menu by entering the password.
Scroll
through the menu by pressing D. Choose the desired function by
pressing
#.
o When a function is activated, only use the number keys to
enter required
information (time, password) or press A to cancel.