digital clock with visitor counter
Post on 16-Apr-2015
150 Views
Preview:
DESCRIPTION
TRANSCRIPT
DIGITAL CLOCK AND VISITOR COUNTER USING A MICROPROCESSOR OR MICROCONTROLLER [Type the document subtitle] The objective of this assignment is to design and construct a prototype for a Digital Clock and Visitor Counter using a low cost microprocessor or microcontroller. Mohamad Muddassir Ghoorun 12/24/2012
Mohamad Muddassir Ghoorun UC4F1110EEE APU
1. Introduction:
This project Digital Clock and Visitor Counter is a reliable circuit that takes over the task of
displaying the digital clock and visitors count. When somebody enters into the room then the
sensor at the entrance is triggered and the counter is incremented by one and when any one
leaves the room then the sensor at the exit is triggered and the counter is decremented by one.
Thus, the total number of persons inside the room can be calculated. The
microprocessor/microcontroller does the above job. It receives the signals from the sensors,
and this signal is operated under the control of software which is stored in RAM/ ROM.
2. Objectives:
The objective of this assignment is to design and construct a prototype for a Digital Clock and
Visitor Counter using a low cost microprocessor or microcontroller. The block diagram of such a
system is shown in Figure 1.
Mohamad Muddassir Ghoorun UC4F1110EEE APU
Figure 1: Block diagram of digital clock and visitor counter
3. Explanation of proposed system:
In order to progressively solve this assignment, the proposed system first is going to be
divided in two parts: First one being the clock part and the second one, the visitor counter.
Furthermore, two new enhancements is going to be made to the system for further
improvement. The clock is not only going to display only time in hours, minutes and seconds
but also the date, month and year 1 information which could also be changed in case. Also,
there is going to be an alarm system 2 which would be activated as soon as the number of
persons inside the room exceeds 10; This will act as an indication that no on shall enter the
room whenever the alarm is on.
1 Enhancement 1
2 Enhancement 2
Mohamad Muddassir Ghoorun UC4F1110EEE APU
3.1. Investigation on material/component selection
A. Microcontroller
(i) 8051 microcontroller:
A microcontroller is an economical computer built on a chip to carry out a specific task. The
most commonly used set of microcontrollers belong to the 8051 family. The 8051 can be
programmed in either embedded C programming or assembly depending on the user. The
block diagram of the 8051 is shown in figure 2.
Figure 2: Block diagram of 8051
Mohamad Muddassir Ghoorun UC4F1110EEE APU
(ii) AT89S52
AT89S52 is one of the family MCS-51/52 equipped with an internal 8 Kbyte Flash EPROM
(Erasable and Programmable Read Only Memory), which allows memory to be reprogrammed.
It is a low-power, high-performance CMOS 8-bit microcontroller using Atmel high-density,
nonvolatile memory technology and is compatible with the industry-standard 80C51 instruction
set and pin out. On-chip flash allows the program memory to be reprogrammed in-system or by a
conventional nonvolatile memory programmer. This powerful microcontroller is suitable for
many embedded control applications.
Figure 3: AT89S052 Block Diagram
Mohamad Muddassir Ghoorun UC4F1110EEE APU
(iii) PIC 16F877A
The PIC 16F877A is one of the most popular PIC in the industry and it is both very powerful and
easy to use at the same time. PIC16F877A has inbuilt analog to digital converters unlike the
8051, more ROM and RAM amongst others and thus more appropriate to use for the proposed
model. Though not going to be used, PIC16F877A has other inbuilt features such as
capture/compare/PWM peripherals, 3 timers, 2 comparators, and a universal synchronous
asynchronous receiver transmitter (USART). The PIC can be programmed on MPLAB IDE and
design can easily be simulated and viewed on Proteus software. The programmer kit can be
brought and the embedded c program downloaded into the microchip using the SK40C and the
USB ICSP PIC programmer namely UIC00B. Both the block diagram and pin diagram of PIC
16F877A are available in figure 4and 5 respectively.
Figure 4: PIC16F877A block diagram
Mohamad Muddassir Ghoorun UC4F1110EEE APU
Figure 5: Pin diagram of PIC16F877A
As seen above some pins have dual or more than 2 functions. In order to use these functions,
refer to the datasheet attached in the appendix. This is mainly done through programming the
pins and enabling the other functions of that specific pin.
B. Liquid crystal display screen
In the recent years LCD, is finding in daily use replacing LED‟s which may be single, Seven
Segment or Multi Segment LED‟s because of declining pricing of LCD and ability to display
numbers, characters and graphics. Another advantage of LCD is the incorporation of refreshing
controller in the LCD for relieving the CPU of the task of refreshing LCD. LM 016L is a 16 * 2
character LCD. This means that it can display 16 characters on one line and that it has the
capacity to display on two different lines.
Mohamad Muddassir Ghoorun UC4F1110EEE APU
The LCD can be configured in two modes: parallel (8 bits) or nibble mode (4 bits). LCD
in 4 bits means that we are using only 4 lines of the data bus of a port of a microcontroller. We
can use it if the number of pins is limited to our application. However, in this project since we
have sufficient pins and are more towards speed of transmission of data to the LCD, we will
make use of the parallel mode. Each pin of the LCD screen is shown in the figure 6.
Figure 6: 16*2 LCD
Mohamad Muddassir Ghoorun UC4F1110EEE APU
The LCD command bits have been summarized in the table below:
Table 1: Command bit of LCD
C. Pushbutton:
The pushbutton has been used during simulation instead of infrared sensors to sense whether a
person comes in or goes out and is placed at the door. It works the same way as an infrared
sensor or an SPDT switch and the coding for all of them are similar. There are two ways of
connecting pushbuttons to a microcontroller/PIC. They are as shown in figure 7 and figure 8:
Mohamad Muddassir Ghoorun UC4F1110EEE APU
Figure 7: Pushbutton connected in pull down configuration
In the pull down configuration, microcontroller pin is connected to ground level through
a resistor (Logic 0). When the switch is pressed, microcontroller pin is connected to Vcc (logic
1). When switch is released, level goes back to level „0‟.
Figure 8: Pushbutton connected in pull up configuration
In the pull up configuration, microcontroller pin is connected to Vcc through a resistor
(Logic „1‟) before switch is pressed. When switch is pressed, it is connected to ground (logic
„0‟). When switch is released, level goes back to level „1‟.
Mohamad Muddassir Ghoorun UC4F1110EEE APU
D. DS1307 Real time clock (RTC)
The DS1307 serial real-time clock (RTC) is a lowpower, full binary-coded decimal (BCD)
clock/calendar plus 56 bytes of NV SRAM chip as shown in figure 9. Address and data are
transferred serially through an I2C, bidirectional bus. The clock/calendar provides seconds,
minutes, hours, day, date, month, and year information. The end of the month date is
automatically adjusted for months with fewer than 31 days, including corrections for leap year.
The clock operates in either the 24-hour or 12-hour format with AM/PM indicator. The DS1307
has a built-in power-sense circuit that detects power failures and automatically switches to the
backup supply. Timekeeping operation continues while the part operates from the backup supply.
Figure 9: DS1307 RTC
Mohamad Muddassir Ghoorun UC4F1110EEE APU
4. Simulation of each block of the system
Figure 10: Simulation part for clock (hour, minutes, and seconds) and enhancement 1 (Date, month, and year)
The DS1307 clock as can be seen from the simulation results is said to be operating in the 24
hour format. It is connected to the microcontroller through pins RC3 and RC4. Three switches
connected in the pull up configurations are connected to pins RC0, RC1, and RC2 respectively.
The first one to the left is to move the pointer across the hour minutes, seconds, date, month, and
year as we normally do on normal clock in houses. The second or middle switch is to increment
the value at which the pointer is pointing. In this way, we can change all the parameters
displayed on the LCD. Switch 3 and the other two LEDs connected to port A are optional and
have been added only in case of any further enhancement or for future purposes if one wants to
improve the system.
Mohamad Muddassir Ghoorun UC4F1110EEE APU
Figure 11: Welcoming message for visitor count part
Since putting all the design in one is going to be cumbersome due to the numerous amount of
wire lines and other components, the unused pins from the clock part has been noted down and
visitor count part has been thus designed using only the free pins as can be seen from figure 11.
The second LCD is connected to PORTD and the switches 1 and 2, act the same way as an
infrared sensor placed nect to the door to sense incoming or outgoing people. “Visitor count
part” starts with a welcoming message then starts to display the number of persons inside the
room furthermore, as said before for enhancement 2, an alarm circuit (simulated as LED) has
also been included in the design when the number of people inside the room is greater or equal to
10.
Mohamad Muddassir Ghoorun UC4F1110EEE APU
Figure 12: Visitor part initial stage
As can be seen from figure 12, when the system starts, the number of visitors is 0 and the alarm
circuit (simulated as LED) is off.
Figure 13: Someone enter the room
Whenever anyone enters the room, they pass through the infrared sensors which causes input at
switch 1 to go to 0 which is then fed to the PIC through pin RA4. As such, the number of visitors
is immediately incremented as displayed on the LCD as shown in figure 13. Also note that alarm
circuit (simulated as LED) remains in an off state as number of visitors is less than 10 persons.
Mohamad Muddassir Ghoorun UC4F1110EEE APU
Figure 14: Second person enters the room
If a second person enters the room, the previous count of the number of visitors is incremented to
2 and alarm circuit (simulated as LED) still remains in an off state.
Figure 14: Counting when someone leaves the room
When someone leaves the room, the infrared is again intercepted but this time at the exit door.
This causes pin RA5 to go low (0), and number of visitors count is immediately decremented and
displayed on the LCD as shown in figure 14.
Mohamad Muddassir Ghoorun UC4F1110EEE APU
Figure 15: System at visitor count of 10
When the number of visitors or people inside the room is greater or equal to 10, this triggers the
alarm circuit to go to state 1. The alarm circuit has been simulated as a LED and as seen from
figure 15 goes to logic level 1 which therefore confirm the successful implementation of the
second enhancement. This will in turn inform any person that the room is full and that they will
have to wait until one or more people leave the room.
Mohamad Muddassir Ghoorun UC4F1110EEE APU
5. System Flowchart
Figure 16: Flowchart for clock part
Mohamad Muddassir Ghoorun UC4F1110EEE APU
Figure 17: Flowchart for visitor counter part
6. Discussion
In such this project to design and construct a prototype for an automatic clock with a visitor
counter system using low cost microcontroller. It needs to have the understanding the idea of the
project and then arrange this idea in the form of agenda and working on implementing it on
sequential stages. The beginning of this project was by collecting the necessary information from
different resources that could help in the accomplishment of this project.
Mohamad Muddassir Ghoorun UC4F1110EEE APU
Hardware and software that this project needs to be done was the focusing topic. For the hard
ware part selecting weather microcontroller or microprocessor was the main issue. PIC16F877A
microcontroller was the suitable option for implementing it in the executing this project. This
microcontroller need it some other hardware to be working with in order to does it task. For
software part C language was the suitable option to be dealing with. That it is considered a high
level language so that it is easy to be understood comparing to the assembly language, which
classified as low level language. For other hard ware part infrared sensor (simulated as
pushbutton for better convenience of simulation process), and DS1307 RTC clock were not
problem in the selection process.
As for the enhancement part, two extra features were added to the design and was successfully
simulated:
Date, Month and Year
Alarm circuitry to inform that number of visitors is greater or equal to 10
Thus, the main objectives of this assignment have been accomplished along with more than one
enhancement done to the system. Personally speaking, this project can be made more
professional by making use of RFID technology instead of infrared sensors at the sides of the
entrance and exit doors. By doing so, we may be able to come up with an actual system which
might be able to be marketed and implemented in the industry if not done yet.
7. Conclusion
For this project automatic clock with a visitor counter system, the final results were
satisfactory and effective. Proteus software is one of the important factors for accomplish this
project. To have a licensed version of this software will be helpful for providing the whole
software library tools in order to simulate such this project and get an accrue result. Having
knowledge about the technologies related to any project that could be making is very
Mohamad Muddassir Ghoorun UC4F1110EEE APU
important factor. That could be done by joining different work shop that many companies are
providing it. In addition to that, having a contact with lectures or senior students of the
particular engineering field could be helpful too in the achievement of such a project.
The advantages that could be found for this project are low cost and easy to be used in
different application high quality of performance. For the disadvantages, it can be noted that
the visitor counter can be used only when one single person cuts the rays of the sensor hence
it cannot be used when two person cross simultaneously.
By enhancing this circuit by adding the possibility option of many persons can be cut the
sensor‟s rays, it can be implemented in useful applications. By modifying this circuit and
using two relays it can be achieved a task of opening and closing the door This project is also
useful to be work in medicine industry, at patient‟s rooms and surgery sections especially in
the emergency situation it is necessary to be able to be manage the number of persons who
should be present in the room.
REFERENCES
Mohamad Muddassir Ghoorun UC4F1110EEE APU
1. C Program for Clock part
//====================================================================
// Project description :Display time, day, date, month and year by using
// DS 1307 real time clock chip and LCD display.The
// time and calender can be changeed by pressing
//push button.
// include
//====================================================================
#include <pic.h>
#include "i2c.h"
#include "i2c_rtc.h"
//====================================================================
// configuration
//====================================================================
__CONFIG ( 0x3F32 );
//====================================================================
// define
//====================================================================
#definesw0 RC0
#define sw1 RC1
#define sw2 RC2
#definers RA0
#definee RA1
#defineled_yellow RA2
#define led_white RA3
#definelcd_data PORTB
#definesdata RC4 // SDA
#definetclk RC3 // SCL
Mohamad Muddassir Ghoorun UC4F1110EEE APU
//====================================================================
// global variable
//====================================================================
unsigned char step=0;
unsigned char store=0;
unsigned char clksec=0;
unsigned char clkmin=0;
unsigned char clkhrs=0;
unsigned char day=0;
unsigned char date=0;
unsigned char month=0;
unsigned char year=0;
unsigned char secondh=0;
unsigned char secondl=0;
unsigned char minutesh=0;
unsigned char minutesl=0;
unsigned char hourh=0;
unsigned char hourl=0;
unsigned char dateh=0;
unsigned char datel=0;
unsigned char monthh=0;
unsigned char monthl=0;
unsigned char yearh=0;
unsigned char yearl=0;
//====================================================================
// function prototype
//====================================================================
Mohamad Muddassir Ghoorun UC4F1110EEE APU
void delay(unsigned long data);
void send_config(unsigned char data);
void send_char(unsigned char data);
void e_pulse(void);
void lcd_goto(unsigned char data);
void lcd_clr(void);
void send_string(const char *s);
void send_dec(unsigned long data,unsigned char num_dig);
void writertc(void);
void readrtc(void); // Read RTC
//====================================================================
// main function
//====================================================================
void main(void)
{
i2c_initialize();
i2c_rtc_initialize();
unsigned char i;
ADCON1 = 0b00000110; //set all portA as digital I/O
TRISA = 0b00000000; //set all PORTA pin as OUTPUT
TRISB = 0b00000000; //set all PORTB pin as output
TRISC = 0b00011111; //set all PORTC pin as output
led_white=0; //led white off
led_yellow=0; //led yellow off
send_config(0b00000001); //clear display at lcd
send_config(0b00000010); //Lcd Return to home
send_config(0b00000110); //entry mode-cursor increase 1
Mohamad Muddassir Ghoorun UC4F1110EEE APU
send_config(0b00001100); //diplay on, cursor off and cursor blink off
send_config(0b00111000); //function
readrtc();
}
//====================================================================
// Write to RTC function
//====================================================================
void writertc(void)
{
led_yellow=0; //led yellow off
led_white=1; //led white on
while(sw0==0)continue; //waiting sw0 to
depress
// SET HOUR
===========================================================
while(sw0==1) //infinity loop if switch0 is
not pressed
{
if(sw1==1) //if switch 1 is not pressed
{
lcd_goto(0); //maintain current hour value on
LCD and make it blinking
send_dec(clkhrs,2);
delay(10000);
lcd_goto(1);
Mohamad Muddassir Ghoorun UC4F1110EEE APU
send_char(' ');
lcd_goto(0);
send_char(' ');
delay(10000);
}
if(sw1==0) //if switch 1 is
pressed
{
while(sw1==0)continue; //wait switch1 to
depress
if(clkhrs<=22)clkhrs++;
else clkhrs=0;
}
}
lcd_goto(0); //overwrite changed
hour value on LCD
send_dec(clkhrs,2);
while(sw0==0)continue; //wait switch 0 to be
depressed
// SET MINUTES
====================================================================
while(sw0==1) //infinity loop
if switch0 is not pressed
{
if(sw1==1) //if switch 1 is
not pressed
Mohamad Muddassir Ghoorun UC4F1110EEE APU
{
lcd_goto(3); //maintain current minute
value on LCD and make it blinking
send_dec(clkmin,2);
delay(10000);
lcd_goto(4);
send_char(' ');
lcd_goto(3);
send_char(' ');
delay(10000);
}
if(sw1==0) //if switch 1 is
pressed
{
while(sw1==0)continue; //wait switch1 to
depress
if(clkmin<=58) clkmin++;
else clkmin=0;
}
}
lcd_goto(3); //overwrite changed
minute value on LCD
send_dec(clkmin,2);
while(sw0==0)continue; //wait switch 0 to be
depressed
// SET SECONDS
===============================================================
Mohamad Muddassir Ghoorun UC4F1110EEE APU
while(sw0==1) //infinity loop if
switch0 is not pressed
{
if(sw1==1) //if switch 1 is not
pressed
{
lcd_goto(6); //maintain current minute
value on LCD and make it blinking
send_dec(clksec,2);
delay(10000);
lcd_goto(7);
send_char(' ');
lcd_goto(6);
send_char(' ');
delay(10000);
}
if(sw1==0) //if switch 1 is
pressed
{
while(sw1==0)continue; //wait switch1 to
depress
if(clksec<=58) clksec++;
else clksec=0;
}
}
lcd_goto(6); //overwrite changed
second value on LCD
Mohamad Muddassir Ghoorun UC4F1110EEE APU
send_dec(clksec,2);
while(sw0==0)continue; //wait switch 0 to be
depressed
// SET DATE =========================================
while(sw0==1) //infinity loop if switch0 is
not pressed
{
if(sw1==1) //if switch 1 is not pressed
{
lcd_goto(20); //maintain current date value
on LCD and make it blinking
send_dec(date,2);
delay(10000);
lcd_goto(21);
send_char(' ');
lcd_goto(20);
send_char(' ');
delay(10000);
}
if(sw1==0) //if switch 1 is
pressed
{
while(sw1==0)continue; //wait switch1 to
depress
if(date<=30) date++;
Mohamad Muddassir Ghoorun UC4F1110EEE APU
else date=1;
}
}
lcd_goto(20); //overwrite changed
date value on LCD
send_dec(date,2);
while(sw0==0)continue; //wait switch 0 to be
depressed
// SET MONTH ==========================================
while(sw0==1) //infinity loop if switch0 is
not pressed
{
if(sw1==1) //if switch 1 is not pressed
{
lcd_goto(23); //maintain current month
value on LCD and make it blinking
send_dec(month,2);
delay(10000);
lcd_goto(24);
send_char(' ');
lcd_goto(23);
send_char(' ');
delay(10000);
}
if(sw1==0) //if switch 1 is
pressed
{
Mohamad Muddassir Ghoorun UC4F1110EEE APU
while(sw1==0)continue; //wait switch1 to
depress
if(month<=11) month++;
else month=1;
}
}
lcd_goto(23); //overwrite changed
month value on LCD
send_dec(month,2);
while(sw0==0)continue; //wait switch 0 to be
depressed
// SET YEAR
=====================================================================
while(sw0==1) //infinity loop if switch0 is
not pressed
{
if(sw1==1) //if switch 1 is not pressed
{
lcd_goto(26); //maintain current month
value on LCD and make it blinking
send_dec(year,2);
delay(10000);
lcd_goto(27);
send_char(' ');
lcd_goto(26);
Mohamad Muddassir Ghoorun UC4F1110EEE APU
send_char(' ');
delay(10000);
}
if(sw1==0) //if switch 1 is
pressed
{
while(sw1==0)continue; //wait switch1 to
depress
if(year<=99) year++;
else year=0;
}
}
lcd_goto(26); //overwrite changed year
value on LCD
send_dec(year,2);
while(sw0==0)continue; //wait switch 0 to be
depressed
// SET DAY
=====================================================================
while(sw0==1) //infinity loop if switch0 is not
pressed
{
if(sw1==1) //if switch 1 is not pressed
{
if(day==7) //maintain current day value on LCD
and make it blinking
Mohamad Muddassir Ghoorun UC4F1110EEE APU
{
lcd_goto(31);
send_string("SUN");
delay(10000);
lcd_goto(31);
send_char(' ');
send_char(' ');
send_char(' ');
delay(10000);
}
else if(day==1)
{
lcd_goto(31);
send_string("MON");
delay(10000);
lcd_goto(31);
send_char(' ');
send_char(' ');
send_char(' ');
delay(10000);
}
else if(day==2)
{
lcd_goto(31);
send_string("TUE");
delay(10000);
lcd_goto(31);
send_char(' ');
send_char(' ');
send_char(' ');
delay(10000);
Mohamad Muddassir Ghoorun UC4F1110EEE APU
}
else if(day==3)
{
lcd_goto(31);
send_string("WED");
delay(10000);
lcd_goto(31);
send_char(' ');
send_char(' ');
send_char(' ');
delay(10000);
}
else if(day==4)
{
lcd_goto(31);
send_string("THU");
delay(10000);
lcd_goto(31);
send_char(' ');
send_char(' ');
send_char(' ');
delay(10000);
}
else if(day==5)
{
lcd_goto(31);
send_string("FRI");
delay(10000);
lcd_goto(31);
send_char(' ');
send_char(' ');
Mohamad Muddassir Ghoorun UC4F1110EEE APU
send_char(' ');
delay(10000);
}
else if(day==6)
{
lcd_goto(31);
send_string("SAT");
delay(10000);
lcd_goto(31);
send_char(' ');
send_char(' ');
send_char(' ');
delay(10000);
}
}
else //if
switch 1 is pressed
{
while(sw1==0)continue; //wait switch1
to depress
if(day>6) //if day
value greater than 11
{
day=1;
//change setday variable to 1
}
else
{
day+=1;
//increse day value by 1
}
Mohamad Muddassir Ghoorun UC4F1110EEE APU
}
}
if(sw1==0)
{
if(day==7)
//overwrite changed day value on LCD
{
lcd_goto(31);
send_string("SUN");
delay(10000);
lcd_goto(31);
send_char(' ');
send_char(' ');
send_char(' ');
delay(10000);
}
else if(day==1)
{
lcd_goto(31);
send_string("MON");
delay(10000);
lcd_goto(31);
send_char(' ');
send_char(' ');
send_char(' ');
delay(10000);
}
else if(day==2)
{
lcd_goto(31);
send_string("TUE");
Mohamad Muddassir Ghoorun UC4F1110EEE APU
delay(10000);
lcd_goto(31);
send_char(' ');
send_char(' ');
send_char(' ');
delay(10000);
}
else if(day==3)
{
lcd_goto(31);
send_string("WED");
}
else if(day==4)
{
lcd_goto(31);
send_string("THU");
delay(10000);
lcd_goto(31);
send_char(' ');
send_char(' ');
send_char(' ');
delay(10000);
}
else if(day==5)
{
lcd_goto(31);
send_string("FRI");
delay(10000);
lcd_goto(31);
send_char(' ');
send_char(' ');
Mohamad Muddassir Ghoorun UC4F1110EEE APU
send_char(' ');
delay(10000);
}
else if(day==6)
{
lcd_goto(31);
send_string("SAT");
delay(10000);
lcd_goto(31);
send_char(' ');
send_char(' ');
send_char(' ');
delay(10000);
}
}
while(sw0==0)continue; //wait switch 0 to be
depressed
i2c_rtc_set_seconds(clksec); //send changed second
i2c_rtc_set_minutes(clkmin); //send changed minute
i2c_rtc_set_hours(clkhrs); //send changed hour
i2c_rtc_set_day(day); //send changed day
i2c_rtc_set_date(date); //send changed date
i2c_rtc_set_month(month); //send changed month
i2c_rtc_set_year(year); //send changed year
}
//====================================================================
// Read RTC function
Mohamad Muddassir Ghoorun UC4F1110EEE APU
void readrtc(void)
{
while(1)
{
led_yellow=1;
led_white=0;
if(sw0==0) //reset button
{
writertc(); //goto write
mode
}
else
{
clksec=uc_i2c_rtc_get_seconds(); //read
1 byte seconds
clkmin= uc_i2c_rtc_get_minutes();
//read 1 byte min
clkhrs=uc_i2c_rtc_get_hours();
//read 1 byte hrs
day=uc_i2c_rtc_get_day();
//read 1 byte day
date=uc_i2c_rtc_get_date();
//read 1 byte date
month=uc_i2c_rtc_get_month();
//read 1 byte month
year=uc_i2c_rtc_get_year();
//read 1 byte year
lcd_goto(0);
send_dec(clkhrs,2);
Mohamad Muddassir Ghoorun UC4F1110EEE APU
lcd_goto(2); //display ':'
send_char(0x3A);
lcd_goto(3);
send_dec(clkmin,2);
lcd_goto(5); //display ':'
send_char(0x3A);
lcd_goto(6);
send_dec(clksec,2);
if(day==7) // display day
{
lcd_goto(31);
send_string("SUN");
}
else if(day==1)
{
lcd_goto(31);
send_string("MON");
}
else if(day==2)
{
lcd_goto(31);
send_string("TUE");
}
else if(day==3)
{
lcd_goto(31);
send_string("WED");
Mohamad Muddassir Ghoorun UC4F1110EEE APU
}
else if(day==4)
{
lcd_goto(31);
send_string("THU");
}
else if(day==5)
{
lcd_goto(31);
send_string("FRI");
}
else if(day==6)
{
lcd_goto(31);
send_string("SAT");
}
lcd_goto(20); // display date
send_dec(date,2);
lcd_goto(22); //display '/'
send_char(0x2F);
lcd_goto(23); // display month
send_dec(month,2);
lcd_goto(25); // display '/'
send_char(0x2F);
Mohamad Muddassir Ghoorun UC4F1110EEE APU
lcd_goto(26); // display year
send_dec(year,2);
}
}
}
//====================================================================
// LCD functions
//====================================================================
void delay(unsigned long data)
{
for( ;data>0;data-=1);
}
void send_config(unsigned char data)
{
rs=0; //clear rs into
config mode
lcd_data=data;
delay(300);
e_pulse();
}
void send_char(unsigned char data)
{
rs=1; //set rs into
write mode
lcd_data=data;
delay(300);
e_pulse();
}
Mohamad Muddassir Ghoorun UC4F1110EEE APU
void e_pulse(void)
{
e=1;
delay(300);
e=0;
delay(300);
}
void lcd_goto(unsigned char data)
{
if(data<16)
{
send_config(0x80+data);
}
else
{
data=data-20;
send_config(0xc0+data);
}
}
void lcd_clr(void)
{
send_config(0x01);
delay(350);
}
void send_string(const char *s)
{
unsigned char i=0;
while (s && *s)send_char (*s++);
}
void send_dec(unsigned long data,unsigned char num_dig)
{
Mohamad Muddassir Ghoorun UC4F1110EEE APU
if(num_dig>=10)
{
data=data%10000000000;
send_char(data/1000000000+0x30);
}
if(num_dig>=9)
{
data=data%1000000000;
send_char(data/100000000+0x30);
}
if(num_dig>=8)
{
data=data%100000000;
send_char(data/10000000+0x30);
}
if(num_dig>=7)
{
data=data%10000000;
send_char(data/1000000+0x30);
}
if(num_dig>=6)
{
data=data%1000000;
send_char(data/100000+0x30);
}
if(num_dig>=5)
{
data=data%100000;
send_char(data/10000+0x30);
}
Mohamad Muddassir Ghoorun UC4F1110EEE APU
if(num_dig>=4)
{
data=data%10000;
send_char(data/1000+0x30);
}
if(num_dig>=3)
{
data=data%1000;
send_char(data/100+0x30);
}
if(num_dig>=2)
{
data=data%100;
send_char(data/10+0x30);
}
if(num_dig>=1)
{
data=data%10;
send_char(data+0x30);
}
}
2. C program for visitor count part
//==================include=================================
#include<pic.h>
//===============configuration==============================
__CONFIG (0x3F32);
Mohamad Muddassir Ghoorun UC4F1110EEE APU
//===============define IO port=============================
#define lcd PORTD
#define RS RC5
#define E RC6
//==============FUNCTION PROTOTYPE=========================
void e_pulse(void);
void delay(unsigned short i);
void send_char(unsigned char data);
void configuration(unsigned char data);
void lcd_goto(unsigned char data);
void lcd_clr(void);
void dis_num(unsigned long data);
void increment(unsigned long data);
int visitor ();
int visitorless();
int count=0;
//====================MAIN================================
void main(void)
{
TRISA = 0b11111111; //Set pin RA1 to RA4 as input for
press button switch
TRISC=0b00000000; //configure PORTC as output
TRISD= 0b00000000;
int xx;
PORTA=0;
PORTB=0;
Mohamad Muddassir Ghoorun UC4F1110EEE APU
PORTC=0;
while(1)
{
configuration(0b00000001); //clear display at lcd
configuration(0b00000010); //Lcd Return to home
configuration(0b00000110); //entry mode-cursor increase 1
configuration(0b00001100); //diplay on, cursor off and cursor blink off
configuration(0b00111000); //function set
lcd_goto(0); //cursor start from beginning
//display character on LCD
send_char('#');send_char('W'); send_char('E'); send_char('L'); send_char('C');
send_char('O');send_char('M'); send_char('E'); send_char(' '); send_char('S');
send_char('I'); send_char('R'); send_char('#');
//====================================================================
while(1) //infinity loop
{
lcd_goto(1);
delay(1000000);
delay(1000000);
delay(1000000);
delay(1000000);
delay(1000000);
delay(1000000);
delay(1000000);
lcd_goto (0);
Mohamad Muddassir Ghoorun UC4F1110EEE APU
send_char('N');
send_char('0');
send_char(' ');
send_char('O');
send_char('f');
send_char(' ');
send_char('V');
send_char('i');
send_char('s');
send_char('i');
send_char('t');
send_char('o');
send_char('r');
send_char('s');
send_char('=');
xx= visitor();
lcd_goto (25);
dis_num (xx);
if (xx-10>=0){RC0=1;}
}
//====================================================================
}
}
//==================subroutine LCD setting
void configuration(unsigned char data)
{
RS=0;
lcd=data;
Mohamad Muddassir Ghoorun UC4F1110EEE APU
delay(500);
e_pulse();
}
//====================================================================
void e_pulse(void)
{
E=1;
delay(500);
E=0;
delay(500);
}
//====================================================================
void send_char(unsigned char data)
{
RS=1;
lcd=data;
delay(500);
e_pulse();
}
//====================================================================
void lcd_goto(unsigned char data)
{
if(data<16)
{
configuration(0x80+data);
}
else
{
data=data-20;
configuration(0xc0+data);
Mohamad Muddassir Ghoorun UC4F1110EEE APU
}
}
//====================================================================
void lcd_clr(void)
{
RS=0;
configuration(0x01);
delay(600);
}
//==================================================================
void dis_num(unsigned long data)
{
unsigned char hundred_thousand;
unsigned char ten_thousand;
unsigned char thousand;
unsigned char hundred;
unsigned char tenth;
hundred_thousand = data/100000;
data = data % 100000;
ten_thousand = data/10000;
data = data % 10000;
thousand = data / 1000;
data = data % 1000;
hundred = data / 100;
data = data % 100;
tenth = data / 10;
data = data % 10;
if(hundred_thousand>0)
Mohamad Muddassir Ghoorun UC4F1110EEE APU
{
send_char(hundred_thousand + 0x30); //0x30 added to become ASCII code
send_char(ten_thousand + 0x30);
send_char(thousand + 0x30);
send_char(hundred + 0x30);
send_char(tenth + 0x30);
send_char(data + 0x30);
}
else if(ten_thousand>0)
{
send_char(ten_thousand + 0x30); //0x30 added to become ASCII code
send_char(thousand + 0x30);
send_char(hundred + 0x30);
send_char(tenth + 0x30);
send_char(data + 0x30);
}
else if(thousand>0)
{
send_char(thousand + 0x30); //0x30 added to become ASCII code
send_char(hundred + 0x30);
send_char(tenth + 0x30);
send_char(data + 0x30);
}
else if(hundred>0)
{
send_char(hundred + 0x30); //0x30 added to become ASCII code
send_char(tenth + 0x30);
send_char(data + 0x30);
}
else if(tenth>0)
Mohamad Muddassir Ghoorun UC4F1110EEE APU
{
send_char(tenth + 0x30); //0x30 added to become ASCII code
send_char(data + 0x30);
}
else send_char(data + 0x30); //0x30 added to become ASCII code
}
//====================================================================
void increment(unsigned long data)
{
unsigned short j;
for(j=10;j>0;j--)
{ lcd_goto(32);
data=data+1;
dis_num(data);
delay(10000);
}
}
//==================subroutine DELAY===============================
void delay(unsigned short i)
{
for(;i>0;i--);
}
//==================================================================
int visitor ()
{
if (RA4==0)
{count++;}
Mohamad Muddassir Ghoorun UC4F1110EEE APU
return count;
}
//==================================================================
int visitorless()
{
if ( RA5==1)
{count--;
return count;
}
}
top related