Report Project Stopwatch

  • Uploaded by: Mr Predator
  • 0
  • 0
  • November 2019
  • PDF

This document was uploaded by user and they confirmed that they have the permission to share it. If you are author or own the copyright of this book, please report to us by using this DMCA report form. Report DMCA


Overview

Download & View Report Project Stopwatch as PDF for free.

More details

  • Words: 2,793
  • Pages: 21
Universiti Teknologi Mara Shah Alam Faculty of Electrical Engineering Microprocessor Application (ECE 611) Report Project Title: Stopwatch Timer Using Microcontroller Members of Group: Mohd Zharif Bin Othman (2006874765) Azman Bin Ahmad Alwi@ Luai (2006686724) Nurul Huzaimi Bin Mohd Basir (2006686406) Ahmad Azka Bin Hj Mohd Zain (2006686484)

Lecturer’s Name: En. Mohd Uzir Bin Kamaluddin

1.0 Objective (1) (2) (3) (4)

To learn and develop knowledge in designing the application by using the microcontroller. To learn how to write an assembly language and combining with the hardware To learn how to calculate the delay in programming to design the stopwatch program To study how the microprocessor can be embed with LCD display.

2.0 System Description Hardware

In this mini project, the component that has been used is PIC16F84A, switches, resistor, resonator, and LCD. The port A of PIC16F84A is connected to the switches while the port B is connected to LCD. When the switch is turn on, the PIC16F84A will detect the input and with the software that have been programmed earlier in the PIC will detect the switch is ON. With the software programmed earlier the PIC will embed with LCD to show the operation. The LCD will display the output that is the stop watch timer. The switches are use for start, stop and reset button.

Software This project uses the low level language. This PIC uses the external clock from the ceramic resonator 4MHz. Each instruction line will be executed in 1µs. The software that is programmed will check or detect whether the start button is pressed or not. If the switch is on the stopwatch ignition will start counting with the delay 0.1 seconds that was programmed. Then the software will detect whether the stop button is pressed or not. If the stop button is pressed the software is programmed to stop the counting. This software is also programmed to detect reset button. The software will go to initial program where it initialized the input and output port and also the LCD.

3.0 Scope The scope of this project is to design and implement a stop watch. A stopwatch is a handheld timepiece designed to measure the amount of time elapsed from a particular time when activated to when the piece is deactivated. The program of stopwatch was used the assembly language and implement to the hardware. The stopwatch in this project is controlled by three buttons. Pressing the first button start the timer running, the second button is stop the timer running and the third is reset the timer running. This stopwatch is available which, due to their crystal oscillator or resonator timing element. It is because are much more accurate than mechanical timepieces. The result is shown on LCD when push the button. 4.0 Hardware Design 1. Component used Voltage regulator  LM7805 used to produce limited voltage supplied to PIC. This is important because the PIC will burn out if the supply voltage more than 5.5 volt.

Output Ground

Input

Figure 1: voltage regulator Resistor  Use resistor of 1 kΩ to bias the switch in order to have voltage drop as input signals to PIC.

Tolerance Brown = 1

Red = 2 Black = 0 Figure 2: Resistor

Switch  Use switch which will control the connectivity of input whether to produce 0 volt or 5 volt.  This switch is turned ON when pressed and OFF when not pushed.

Figure 3: The Push button switch

Resonator  Two type of resonator available in market. That is crystal resonator and ceramic. Figure 4 will shows the ceramic resonator of 4MHz used as main clock to PIC.

Pin 15 of PIC

Ground

Pin 16 of PIC

Figure 4: Resonator PIC  Use PIC16F84A to burn into the assembled program which will process the whole system of stop watch.

Figure 5: The PIC16F84A

LCD  Use LCD of 8 bit input to show the process of stop watch done by PIC.  It will show current operation such as start, running and stop.

Figure 6: Liquid Crystal Display

Schematic Diagram

Figure 7: The Schematic Diagram

HARDWARE DEVELOPMENT

PRINTED CIRCUIT BOARD CONSTRUCTION

Printed circuit board is used extensively in all types of electronic equipment. It’s has helped in producing smaller and more reliable electronic equipment. A printed circuit board serves two basic functions. It provides both the mounting space for the component and connects them together.

The simplest type of printed circuit board is the single side board. It consists of a thin conductive foil cladding on one side of a rigid non-conductive laminate. Component is positioned on the insulator side of the board. Lead access holes are drilled through both the laminate material and conductive foil for each component lead. These lead are passed through holes and then they are bent and soldered to the foil and excess lead is trimmed. The foil cladding is previously processed into conductive path to provide the required wiring for working circuit.

PLANNING AND LAYOUT

To start laying out the circuit, schematic diagram of the circuit, physical size of the component and the printed circuit board have to be used. The schematic was drawn by using the AUTOCAD software.

Figure 8: The circuit on the PCB

5.0 SOFTWARE DESIGN The low level and high level language can be use in order to program the PIC. Both of the method has an advantage and disadvantage. The assembly language is the one of the example low level language and the C programming and Pic Basic Pro is the example of the high level language. This project is using the low level language because the following factor: i) ii)

The size program cannot exceed 1K (PIC 16F84A) Easy to design the delay calculation

The software that needed to write the assembly language is MPLAB Integrated Development Environment (IDE), provided by Microchip. The advantage by using this method is the measurement of the time can be calculated. This PIC use the external clock from the ceramic resonator 4MHz. Each instruction line will be executed in 1µs. This microcontroller will embed with the liquid crystal display (LCD) to show the operation. The LCD has an own microprocessor like HD44780 produce by Hitachi. Therefore, the initialization needs to be done in order to make the LCD functionally. The timing diagram, command control code and instruction set of the LCD will attach in the appendix A. The program will be start by initialize the input, output port and LCD. Then, the program will be waiting until user press the START button. Once the Start button pressed, the program will be count 0.1 seconds. Every time, the program will check weather Stop button is press or not. Once the Stop button is pressed, user is having a choice whether want to continue run the stopwatch or reset it to start again the stopwatch. The figure 10 shows the flow chart of the program stopwatch. The full program is shown in appendix C. The most important is the creating delay part. The microcontroller executed each instruction very fast. Therefore, we need to scale down the speed by put the external oscillator beside PIC microcontroller. By using 4MHz ceramic resonator, each 1 cycle instruction will be executed in 1µs. By using MPLAB IDE, we can observe the time executed by microcontroller by using stopwatch function in MPLAB. This can be obtain by choose DebuggerStopwatch in MPLAB software. The figure 9 show the time elapsed and total instruction by microcontroller. This function is very useful to create the good delay in programming.

Figure 9: Time executed by microcontroller

The Flowchart

Start

Initialize output, input port and LCD 2 No

Is the START button pressed? 3

Yes Count increase

Delay 0.1s

Is the STOP button pressed? No Count = 10?

second increase

No

second = 59 Yes minute increase

No

minute = 59 Yes End

Yes

1

1

Is the RESET button pressed?

Yes

2

No No

Is the START button pressed?

Yes

3

Figure 10: The flowchart of the stopwatch program 6.0 Testing This project involves the hardware and software, which must be working properly. In order to test the circuit and software in right condition, we must test it by simple software and observed is it true or have an error. By using MPLAB IDE that use to write the simple software and also to use to check whether the port is receive the desired code or not. The Appendix B is shown the simple assembly language for the testing purpose. The LEDs is used to indicate ‘1’ or ‘0’ at the port. The MPLAB is very useful to run the assembly language because we can check the content of port, special function register during simulation. Then we can compare with the output of the hardware. The LEDs will indicate the value at the port B and A. ON mean ‘1’ and OFF mean ‘0’ at the port. After confirm the hardware produce the right output, the project stopwatch can be precede.

Figure 11: Show the result for testing hardware with simple software

7.0 Result

Figure 12: 12 Show result to LCD Before starting the stop watch. Look at first and second line of LCD which representing operation and timer respectively.

Figure 13:: Show the result when press the start button Run state of the stop watch. Look at first and second line changed changed by PIC. Switch pointed by pen is start button.

Figure 14: 14 Show the result when press the stop button. Stop state of the stop watch. Look at first and second line changed by PIC. Switch pointed by pen is stop button.

Figure 15:: Show the result when push reset button. Reset state of the stop watch. Look at first and second line changed changed by PIC. Switch pointed by pen is reset button.

Figure 16:: The comparison between real-time real time digital clocks with PIC stopwatch Figure 16 shows the comparison of the stop watch running by hand phone and the PIC’s. The output obtained is similar to the hand phone does.

8.0 Conclusion After we done our project about stop stop watch, we are able to learn and developed knowledge in designing by used a microcontroller. We also learn how to developed skills and knowledge in systematic design approach. According to our project we are able to use the assembly language, and can compare pare the best method can be used to write the program. The other method we can write the program by used the PIC basic pro and mikroC. So the best method we used is by write the program with assembly language. The main reason we used the assembly language because we can know the time instruction can be execute. We also know how to calculate the delay it is because this project needs us to calculate the delay and used it into our program. Beside that we are know how the microprocessor can be embed with LCD display.

Appendix

Appendix A

Table 1: The Command Control for the LCD

Appendix B list p=pic16f84a include p16f84a.inc ;**************** Label Definition ******************** #DEFINE #DEFINE #DEFINE #DEFINE #DEFINE

ORG E RS START STOP RESET

0x00 PORTA,2 PORTA,3 PORTA,4

PORTA,0 PORTA,1

D1 EQU 0X12 D2 EQU 0X13 D3 EQU 0X14 ;----------Initialize------------------------------------;MAIN PROGRAM START HERE ;--------------------------------------------------------BEGIN CLRF PORTA CLRF PORTB ;----------Initiliaze Port-------------------------------BSF STATUS,RP0 CLRF TRISB MOVLW 0X1C MOVWF TRISA BCF STATUS,RP0 SWITCH BTFSC GOTO

START $-1

MOVLW 0XCC MOVWF PORTB CALL DELAY MOVLW 0X11 MOVWF PORTB CALL DELAY GOTO SWITCH ;--------Delay--------------------------------------------DELAY MOVLW D'200' MOVWF D3 MOVLW D'100' MOVWF D2 MOVLW D'100' MOVWF D1 DECFSZ D1 GOTO $-1 DECFSZ D2 GOTO $-5 DECFSZ D3 GOTO $-9 RETURN END

Appendix C list p=pic16f84a include p16f84a.inc ;**************** Label Definition ******************** #DEFINE #DEFINE #DEFINE #DEFINE #DEFINE

ORG E RS START STOP RESET

D1 D2 D3 COUNT1 EQU COUNT2 EQU

0x00 PORTA,2 PORTA,3 PORTA,4 EQU EQU EQU 0X15 0X16

PORTA,0 PORTA,1

0X12 0X13 0X14

;----------Initialize------------------------------------;MAIN PROGRAM START HERE ;--------------------------------------------------------BEGIN CLRF PORTA CLRF PORTB ;----------Initiliaze Port-------------------------------BSF STATUS,RP0 CLRF TRISB MOVLW 0X1C MOVWF TRISA BCF STATUS,RP0 MOVLW MOVWF MOVWF MOVWF MOVWF MOVWF

0X01 0X0D 0X0E 0X30 0X31 0X32

;----------Initialize LCD---------------------------------CALL FUNCSET CALL DIS_ON CALL

DELAY_5MS

CLRF

0X0F

CALL

ADDRS_START

; delay to LCD rise the voltage

;------------START_text-----------------------------------MOVF 0F,W ;insert thw count to wreg CALL TEXT ;call text STOP BSF RS ;Command register enable MOVWF PORTB ;Display text CALL Enable ;enable the LCD INCF 0F,W ;Increase count, place yo the wreg XORLW D'8' ;Check wheather the count egual = 8 BTFSC 03,02 ;check the zero flag in status register GOTO TIME ;if all the text show, jump to next command INCF 0F,F ;increase count

GOTO $-0A ;if count no equal, loop to display the text ;-------------SHOW_00:00:00.0-----------------------------TIME CALL ADDRS_TIME CLRF 0X0F MOVF 0F,W CALL TIMER BSF RS MOVWF PORTB CALL Enable INCF 0F,W XORLW D'10' BTFSC 03,02 GOTO SWITCH INCF 0F,F GOTO $-0A ;-------------Switch--------------------------------------SWITCH BTFSC START ; check the Start button pressed GOTO $-1 ; if not pressed, repeat, else will skip this step ;---------XX:XX:XX.0--------------------------------------MMSEC1 CALL CLRF MOVF CALL BSF MOVWF CALL INCF XORLW BTFSC GOTO INCF GOTO

ADDRS_START 0X0F 0F,W RUN RS PORTB Enable 0F,W D'8' 03,02 MMSEC 0F,F $-0A

;---------XX:XX:X0.x---------------------------------------MMSEC CALL ADDRS_MMSEC ULE BTFSS STOP ;is it STOP button pressed? GOTO FINISH ;if pressed, jump to stop location MOVF CALL BSF MOVWF CALL CALL

0D,W NO

;if not press, proceed the instruction

RS PORTB ;display at LCD Enable DELAY_0.1S ; delay 0.1 seconds

CALL INCF XORLW BTFSC GOTO INCF

MOVE_LEFT ;move location display 0D,W ;INCREASE D'10' ;would that make it increase to 9? 03,02 ;set the zero flag in status register MSEC 0D,F

BTFSS STOP ;is it STOP button pressed? GOTO FINISH ;if pressed, jump to stop location GOTO ULE ;if not pressed, proceed counter ;-------XX:XX:0X.X-----------------

MSEC CALL MOVF CALL BSF MOVWF CALL

ADDRS_MSEC 0E,W NO RS PORTB Enable

CALL CLRF MOVF CALL BSF MOVWF CALL CALL INCF

ADDRS_MMSEC 0D 0D,W NO RS PORTB Enable DELAY_0.1S 0D,F

INCF XORLW BTFSC GOTO INCF GOTO

0E,W D'11' 03,02 SEC 0E,F MMSEC

;--------XX:X0:XX.X--------------SEC CALL ADDRS_SEC MOVF 30,W CALL NO BSF RS MOVWF PORTB CALL Enable CALL CLRF MOVF CALL BSF MOVWF CALL INCF INCF

ADDRS_MSEC 0E 0E,W NO RS PORTB Enable 0E,F 0D,F

INCF XORLW BTFSC GOTO INCF GOTO

30,W D'7' 03,02 NEXT_SEC 30,F MMSEC

;-------XX:X0:XX.X----NEXT_SEC CALL MOVF CALL BSF MOVWF CALL CALL

ADDRS_NEXTSEC 31,W NO RS PORTB Enable ADDRS_SEC

CLRF MOVF CALL BSF MOVWF CALL INCF CLRF MOVF CALL BSF MOVWF CALL INCF INCF

30 30,W NO

RS

PORTB Enable 30,F 0E 0E,W NO

RS

PORTB Enable 0E,F 0D,F

INCF 31,W XORLW D'11' BTFSC 03,02 GOTO FINISH INCF 31,F GOTO MMSEC ;---TIME STOP----------FINISH CALL ADDRS_START CLRF 0X0F MOVF 0F,W CALL TEXT_STOP1 BSF RS MOVWF PORTB CALL Enable INCF 0F,W XORLW D'8' BTFSC 03,02 GOTO $+03 INCF 0F,F GOTO $-0A BTFSS GOTO

RESET BEGIN

; check the reset button ; if press goto initliaze program

BTFSS GOTO GOTO

START ; check the start button MMSEC1 ; if pressed, continue counter $-04 ; loop to check both button

;--------SUBROUTINE TO DISPLAY-----------Enable BSF E BCF E CALL DELAY_125MCS RETLW 0 NO

ADDWF RETLW RETLW RETLW RETLW RETLW RETLW RETLW RETLW

PCL '0' '1' '2' '3' '4' '5' '6' '7'

RETLW RETLW

'8' '9'

ADDWF RETLW RETLW RETLW RETLW RETLW RETLW RETLW RETLW

PCL 'S' 'T' 'A' 'R' 'T' 0X20 0X20 0X20

ADDWF RETLW RETLW RETLW RETLW RETLW RETLW RETLW RETLW

PCL 'R' 'U' 'N' 'N' 'I' 'N' 'G' '!'

ADDWF RETLW RETLW RETLW RETLW RETLW RETLW RETLW RETLW RETLW RETLW

PCL '0' '0' ':' '0' '0' ':' '0' '0' '.' '0'

TEXT

;BLANK SPACE ;BLANK SPACE ;BLANK SPACE

RUN

TIMER

TEXT_STOP1 ADDWF RETLW RETLW RETLW RETLW RETLW RETLW RETLW RETLW

PCL 'S' 'T' 'O' 'P' '!' '!' 0X20 0X20

;--------COMMAND FOR LCD----------FUNCSET BCF RS CALL DELAY_125MCS MOVLW 0x38 ; code for 8 bit LCD and 2 lines MOVWF PORTB CALL Enable RETURN DIS_ON BCF RS CALL DELAY_125MCS MOVLW 0x0C ; code for display On and off cursor MOVWF PORTB

CALL Enable RETURN ENTRY_MODE BCF CALL MOVLW MOVWF CALL RETURN

RS DELAY_125MCS 0x06 PORTB Enable

MOVE_LEFT BCF CALL MOVLW MOVWF CALL RETURN

RS DELAY_125MCS 0x10 PORTB Enable

;------address display---------------------------ADDRS_MSEC BCF RS CALL DELAY_125MCS MOVLW 0xC8 MOVWF PORTB CALL Enable RETURN ADDRS_SEC BCF CALL MOVLW MOVWF CALL RETURN

RS DELAY_125MCS 0xC7 PORTB Enable

ADDRS_NEXTSEC BCF CALL MOVLW MOVWF CALL RETURN

RS DELAY_125MCS 0xC5 PORTB Enable

ADDRS_MMSEC BCF CALL MOVLW MOVWF CALL RETURN

RS DELAY_125MCS 0xCA PORTB Enable

ADDRS_START BCF CALL MOVLW MOVWF CALL RETURN

RS DELAY_125MCS 0x85 PORTB Enable

ADDRS_TIME BCF CALL

RS DELAY_125MCS

MOVLW 0xC1 MOVWF PORTB CALL Enable RETURN ;------Delay subroutine-----DELAY_125MCS MOVLW D'42' MOVWF D3 DECFSZ D3,F GOTO $-1 RETURN DELAY_5MS MOVLW D'41' MOVWF D2 CALL DELAY_125MCS DECFSZ D2,F GOTO $-2 RETURN DELAY_0.1S MOVLW MOVWF MOVLW MOVWF MOVLW MOVWF DECFSZ GOTO DECFSZ GOTO DECFSZ GOTO RETURN END

D'50' D3 D'13' D2 D'50' D1 D1 $-1 D2 $-5 D3 $-9

Related Documents

Report Project Stopwatch
November 2019 4
Stopwatch
November 2019 1
Project Report
May 2020 2
Project Report
June 2020 2
Project Report
June 2020 5

More Documents from ""

Proposal Project Approved]
November 2019 9
Eis Assingment Q1
June 2020 3
Report Project Stopwatch
November 2019 4
November 2019 5
May 2020 3