Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
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.
UC4F1110EEE
APU
persons inside the room exceeds 10; This will act as an indication that no on shall enter the room whenever the alarm is on.
Enhancement 1 Enhancement 2
UC4F1110EEE
APU
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.
UC4F1110EEE
APU
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.
UC4F1110EEE
APU
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.
UC4F1110EEE
APU
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.
In the recent years LCD, is finding in daily use replacing LEDs which may be single, Seven Segment or Multi Segment LEDs 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.
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.
UC4F1110EEE
APU
The LCD command bits have been summarized in the table below:
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:
UC4F1110EEE
APU
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.
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.
UC4F1110EEE
APU
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.
UC4F1110EEE
APU
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.
UC4F1110EEE
APU
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.
UC4F1110EEE
APU
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.
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.
UC4F1110EEE
APU
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.
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.
UC4F1110EEE
APU
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.
UC4F1110EEE
APU
5. System Flowchart
UC4F1110EEE
APU
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.
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
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 sensors 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 patients 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
UC4F1110EEE
APU
//==================================================================== // configuration
//==================================================================== // define
//==================================================================== #definesw0 #define sw1 #define sw2 #definers #definee #defineled_yellow #define led_white #definelcd_data #definesdata #definetclk RA2 RA3 PORTB RC4 RC3 // SDA // SCL RC0 RC1 RC2 RA0 RA1
UC4F1110EEE
APU
//==================================================================== 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;
//====================================================================
Mohamad Muddassir Ghoorun 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);
UC4F1110EEE
APU
void send_dec(unsigned long data,unsigned char num_dig); void writertc(void); void readrtc(void); // Read RTC
//set all portA as digital I/O //set all PORTA pin as OUTPUT //set all PORTB pin as output //set all PORTC pin as output
led_white=0; led_yellow=0;
UC4F1110EEE //diplay on, cursor off and cursor blink off //function
APU
while(sw0==0)continue; depress
//waiting sw0 to
while(sw0==1) not pressed { if(sw1==1) { lcd_goto(0); LCD and make it blinking send_dec(clkhrs,2); delay(10000); lcd_goto(1);
UC4F1110EEE
APU
send_char(' '); lcd_goto(0); send_char(' '); delay(10000); } if(sw1==0) pressed { while(sw1==0)continue; depress //wait switch1 to //if switch 1 is
//overwrite changed
//wait switch 0 to be
//infinity loop
//if switch 1 is
UC4F1110EEE
APU
lcd_goto(3); 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) pressed { while(sw1==0)continue; depress
//if switch 1 is
//wait switch1 to
//overwrite changed
//wait switch 0 to be
UC4F1110EEE
APU
//infinity loop if
if(sw1==1) pressed { lcd_goto(6); 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) pressed { while(sw1==0)continue; depress
//if switch 1 is
//wait switch1 to
//overwrite changed
UC4F1110EEE
APU
//wait switch 0 to be
if(sw1==1) { lcd_goto(20); 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) pressed { while(sw1==0)continue; depress
//if switch 1 is
//wait switch1 to
if(date<=30) date++;
UC4F1110EEE
APU
//overwrite changed
//wait switch 0 to be
if(sw1==1) { lcd_goto(23); 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) pressed {
//if switch 1 is
APU
while(sw1==0)continue; depress
//overwrite changed
//wait switch 0 to be
if(sw1==1) { lcd_goto(26); value on LCD and make it blinking send_dec(year,2); delay(10000); lcd_goto(27); send_char(' '); lcd_goto(26);
UC4F1110EEE
APU
send_char(' '); delay(10000); } if(sw1==0) pressed { while(sw1==0)continue; depress //wait switch1 to //if switch 1 is
//wait switch 0 to be
UC4F1110EEE
APU
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);
UC4F1110EEE
APU
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(' ');
UC4F1110EEE
APU
send_string("SAT"); delay(10000); lcd_goto(31); send_char(' '); send_char(' '); send_char(' '); delay(10000); } } else switch 1 is pressed { while(sw1==0)continue; to depress if(day>6) value greater than 11 { day=1; //change setday variable to 1 } else { day+=1; //increse day value by 1 } //if day //wait switch1 //if
UC4F1110EEE
APU
//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 delay(10000); lcd_goto(31); send_char(' '); send_char(' '); send_char(' '); delay(10000); } else if(day==3) { lcd_goto(31);
UC4F1110EEE
APU
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(' ');
UC4F1110EEE
APU
send_string("SAT"); delay(10000); lcd_goto(31); send_char(' '); send_char(' '); send_char(' '); delay(10000); } } while(sw0==0)continue; depressed //wait switch 0 to be
//send changed second //send changed minute //send changed hour //send changed day //send changed date //send changed month
i2c_rtc_set_year(year);
Mohamad Muddassir Ghoorun void readrtc(void) { while(1) { led_yellow=1; led_white=0; if(sw0==0) { writertc(); mode } else {
UC4F1110EEE
APU
//reset button
//goto write
clksec=uc_i2c_rtc_get_seconds(); 1 byte seconds clkmin= //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 uc_i2c_rtc_get_minutes();
//read
lcd_goto(0); send_dec(clkhrs,2);
APU
lcd_goto(3); send_dec(clkmin,2);
lcd_goto(5); send_char(0x3A);
//display ':'
lcd_goto(6); send_dec(clksec,2);
if(day==7) { 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");
// display day
UC4F1110EEE
APU
lcd_goto(20); send_dec(date,2);
// display date
lcd_goto(22); send_char(0x2F);
//display '/'
lcd_goto(23); send_dec(month,2);
// display month
lcd_goto(25); send_char(0x2F);
// display '/'
APU
send_dec(year,2);
} } }
//==================================================================== void delay(unsigned long data) { for( ;data>0;data-=1); } void send_config(unsigned char data) { rs=0; config mode lcd_data=data; delay(300); e_pulse(); } void send_char(unsigned char data) { rs=1; write mode lcd_data=data; delay(300); e_pulse(); } //set rs into //clear rs into
Mohamad Muddassir Ghoorun 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;
UC4F1110EEE
APU
while (s && *s)send_char (*s++); } void send_dec(unsigned long data,unsigned char num_dig) {
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); }
UC4F1110EEE
APU
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); } }
//==================include================================= #include<pic.h>
UC4F1110EEE
APU
//==============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) {
PORTA=0; PORTB=0;
UC4F1110EEE
APU
while(1) { configuration(0b00000001); configuration(0b00000010); configuration(0b00000110); configuration(0b00001100); configuration(0b00111000); //clear display at lcd //Lcd Return to home //entry mode-cursor increase 1 //diplay on, cursor off and cursor blink off //function set
lcd_goto(0);
//display character on LCD send_char('#');send_char('W'); send_char('O');send_char('M'); send_char('I'); send_char('R'); send_char('E'); send_char('L'); send_char('C'); send_char('E'); send_char(' '); send_char('S'); send_char('#');
lcd_goto (0);
UC4F1110EEE
APU
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
UC4F1110EEE
APU
//==================================================================== 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(); } //====================================================================
UC4F1110EEE
APU
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)
UC4F1110EEE
APU
send_char(hundred_thousand + 0x30); 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); 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) //0x30 added to become ASCII code
UC4F1110EEE
APU
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); }
int visitor () {
if (RA4==0) {count++;}
UC4F1110EEE
APU