Anda di halaman 1dari 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) To learn and develop knowledge in designing the application by using the microcontroller.
(2) To learn how to write an assembly language and combining with the hardware
(3) To learn how to calculate the delay in programming to design the stopwatch program
(4) 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 Ground Pin 16


of PIC 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) The size program cannot exceed 1K (PIC 16F84A)


ii) 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

No Is the START
button pressed?

Yes 3

Count increase

Delay 0.1s

Yes
Is the STOP
1
button pressed?

No

Count = 10?

second increase

No second = 59

Yes

minute increase

No
minute = 59

Yes

End
1

Is the RESET Yes


2
button pressed?

No

No Yes
Is the START
3
button pressed?

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 ********************

ORG 0x00
#DEFINE E PORTA,0
#DEFINE RS PORTA,1
#DEFINE START PORTA,2
#DEFINE STOP PORTA,3
#DEFINE RESET PORTA,4

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 START
GOTO $-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 ********************

ORG 0x00
#DEFINE E PORTA,0
#DEFINE RS PORTA,1
#DEFINE START PORTA,2
#DEFINE STOP PORTA,3
#DEFINE RESET PORTA,4

D1 EQU 0X12
D2 EQU 0X13
D3 EQU 0X14
COUNT1 EQU 0X15
COUNT2 EQU 0X16

;----------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 0X01
MOVWF 0X0D
MOVWF 0X0E
MOVWF 0X30
MOVWF 0X31
MOVWF 0X32

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

CALL DELAY_5MS ; delay to LCD rise the voltage

CLRF 0X0F

CALL ADDRS_START

;------------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 ADDRS_START
CLRF 0X0F
MOVF 0F,W
CALL RUN
BSF RS
MOVWF PORTB
CALL Enable
INCF 0F,W
XORLW D'8'
BTFSC 03,02
GOTO MMSEC
INCF 0F,F
GOTO $-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 0D,W ;if not press, proceed the instruction


CALL NO
BSF RS
MOVWF PORTB ;display at LCD
CALL Enable
CALL DELAY_0.1S ; delay 0.1 seconds

CALL MOVE_LEFT ;move location display


INCF 0D,W ;INCREASE
XORLW D'10' ;would that make it increase to 9?
BTFSC 03,02 ;set the zero flag in status register
GOTO MSEC
INCF 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 ADDRS_MSEC
MOVF 0E,W
CALL NO
BSF RS
MOVWF PORTB
CALL Enable

CALL ADDRS_MMSEC
CLRF 0D
MOVF 0D,W
CALL NO
BSF RS
MOVWF PORTB
CALL Enable
CALL DELAY_0.1S
INCF 0D,F

INCF 0E,W
XORLW D'11'
BTFSC 03,02
GOTO SEC
INCF 0E,F
GOTO MMSEC

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

CALL ADDRS_MSEC
CLRF 0E
MOVF 0E,W
CALL NO
BSF RS
MOVWF PORTB
CALL Enable
INCF 0E,F
INCF 0D,F

INCF 30,W
XORLW D'7'
BTFSC 03,02
GOTO NEXT_SEC
INCF 30,F
GOTO MMSEC

;-------XX:X0:XX.X-----

NEXT_SEC
CALL ADDRS_NEXTSEC
MOVF 31,W
CALL NO
BSF RS
MOVWF PORTB
CALL Enable

CALL ADDRS_SEC
CLRF 30
MOVF 30,W
CALL NO
BSF RS
MOVWF PORTB
CALL Enable
INCF 30,F

CLRF 0E
MOVF 0E,W
CALL NO
BSF RS
MOVWF PORTB
CALL Enable
INCF 0E,F
INCF 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 RESET ; check the reset button


GOTO BEGIN ; if press goto initliaze program

BTFSS START ; check the start button


GOTO MMSEC1 ; if pressed, continue counter
GOTO $-04 ; loop to check both button

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

NO
ADDWF PCL
RETLW '0'
RETLW '1'
RETLW '2'
RETLW '3'
RETLW '4'
RETLW '5'
RETLW '6'
RETLW '7'
RETLW '8'
RETLW '9'

TEXT
ADDWF PCL
RETLW 'S'
RETLW 'T'
RETLW 'A'
RETLW 'R'
RETLW 'T'
RETLW 0X20 ;BLANK SPACE
RETLW 0X20 ;BLANK SPACE
RETLW 0X20 ;BLANK SPACE

RUN
ADDWF PCL
RETLW 'R'
RETLW 'U'
RETLW 'N'
RETLW 'N'
RETLW 'I'
RETLW 'N'
RETLW 'G'
RETLW '!'

TIMER
ADDWF PCL
RETLW '0'
RETLW '0'
RETLW ':'
RETLW '0'
RETLW '0'
RETLW ':'
RETLW '0'
RETLW '0'
RETLW '.'
RETLW '0'

TEXT_STOP1
ADDWF PCL
RETLW 'S'
RETLW 'T'
RETLW 'O'
RETLW 'P'
RETLW '!'
RETLW '!'
RETLW 0X20
RETLW 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 RS
CALL DELAY_125MCS
MOVLW 0x06
MOVWF PORTB
CALL Enable
RETURN

MOVE_LEFT
BCF RS
CALL DELAY_125MCS
MOVLW 0x10
MOVWF PORTB
CALL Enable
RETURN

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

ADDRS_SEC
BCF RS
CALL DELAY_125MCS
MOVLW 0xC7
MOVWF PORTB
CALL Enable
RETURN

ADDRS_NEXTSEC
BCF RS
CALL DELAY_125MCS
MOVLW 0xC5
MOVWF PORTB
CALL Enable
RETURN

ADDRS_MMSEC
BCF RS
CALL DELAY_125MCS
MOVLW 0xCA
MOVWF PORTB
CALL Enable
RETURN

ADDRS_START
BCF RS
CALL DELAY_125MCS
MOVLW 0x85
MOVWF PORTB
CALL Enable
RETURN

ADDRS_TIME
BCF RS
CALL 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 D'50'
MOVWF D3
MOVLW D'13'
MOVWF D2
MOVLW D'50'
MOVWF D1
DECFSZ D1
GOTO $-1
DECFSZ D2
GOTO $-5
DECFSZ D3
GOTO $-9
RETURN

END

Anda mungkin juga menyukai