Upload
mr-predator
View
10.171
Download
3
Embed Size (px)
DESCRIPTION
fully working on the breadboard
Citation preview
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.
InputGround
Output
Brown = 1
Black = 0
Red = 2
Tolerance
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 usedVoltage regulator
LM7805 used to produce limited voltagesupplied to PIC. This is important because the PIC will burn out if the supply voltage more than 5.5 volt.
Resistor Use resistor of 1 kΩ to bias the switch in order to have voltage drop as input signals to PIC.
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
Figure 1: voltage regulator
Figure 2: Resistor
Pin 15 of PIC
Ground Pin 16 of PIC
Figure 4: Resonator
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.
PIC Use PIC16F84A to burn into the assembled program which will process the whole system of stop watch.
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 5: The PIC16F84A
Figure 6: Liquid Crystal Display
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.
Figure 7: The Schematic Diagram
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 needsto 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 DebuggerStopwatch 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
Yes
Yes
No
No
Yes
No
Initialize output, input port and LCD
Is the START button pressed?
Start
Count increase
Delay 0.1s
second = 59
Count = 10?
Is the STOP button pressed?
1
second increase
minute increase
minute = 59No
Yes
End
2
3
6.0 TestingThis 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.
YesNo
No
Yes
1
Is the RESET button pressed?
2
Is the START button pressed?
3
Figure 10: The flowchart of the stopwatch program
Figure 11: Show the result for testing hardware with simple software
7.0 Result
Before starting the stop watch. Look at first and second line of LCD which representing operation and timer respectively.
Run state of the stop watch. Look at first and second line chanstart button.
Figure 12
Figure 13: Show the result when press the
Before starting the stop watch. Look at first and second line of LCD which representing operation and
state of the stop watch. Look at first and second line changed by PIC. Switch pointed by pen is
Figure 12: Show result to LCD
: Show the result when press the start button
Before starting the stop watch. Look at first and second line of LCD which representing operation and
ged by PIC. Switch pointed by pen is
Stop state of the stop watch. Look at first and second line changed by PIC. Switch pointed by pen is stop button.
Reset state of the stop watch. Look at first and second line changreset button.
Figure 14
Figure 15: Show the result when push reset button.
state of the stop watch. Look at first and second line changed by PIC. Switch pointed by pen is
state of the stop watch. Look at first and second line changed by PIC. Switch pointed by pen is
Figure 14: Show the result when press the stop button.
: Show the result when push reset button.
state of the stop watch. Look at first and second line changed by PIC. Switch pointed by pen is
ed by PIC. Switch pointed by pen is
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 ConclusionAfter we done our project about st
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 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 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
Figure 16: The comparison between real
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.
After we done our project about 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,
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 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.
: The comparison between real-time digital clocks with PIC stopwatch
shows the comparison of the stop watch running by hand phone and the PIC’s. The output
op 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,
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
time digital clocks with PIC stopwatch
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 0X12D2 EQU 0X13D3 EQU 0X14;----------Initialize-------------------------------------;MAIN PROGRAM START HERE;---------------------------------------------------------BEGIN
CLRF PORTACLRF PORTB
;----------Initiliaze Port--------------------------------BSF STATUS,RP0CLRF TRISBMOVLW 0X1CMOVWF TRISABCF STATUS,RP0
SWITCHBTFSC STARTGOTO $-1
MOVLW 0XCCMOVWF PORTBCALL DELAY
MOVLW 0X11MOVWF PORTBCALL DELAYGOTO SWITCH
;--------Delay---------------------------------------------DELAY
MOVLW D'200'MOVWF D3MOVLW D'100'MOVWF D2MOVLW D'100'MOVWF D1DECFSZ D1GOTO $-1DECFSZ D2GOTO $-5DECFSZ D3GOTO $-9RETURNEND
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 0X12D2 EQU 0X13D3 EQU 0X14COUNT1 EQU 0X15COUNT2 EQU 0X16
;----------Initialize-------------------------------------;MAIN PROGRAM START HERE;---------------------------------------------------------BEGIN
CLRF PORTACLRF PORTB
;----------Initiliaze Port--------------------------------BSF STATUS,RP0CLRF TRISBMOVLW 0X1CMOVWF TRISABCF STATUS,RP0
MOVLW 0X01MOVWF 0X0DMOVWF 0X0EMOVWF 0X30MOVWF 0X31MOVWF 0X32
;----------Initialize LCD----------------------------------CALL FUNCSETCALL 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 wregCALL TEXT ;call text STOPBSF RS ;Command register enableMOVWF PORTB ;Display textCALL Enable ;enable the LCDINCF 0F,W ;Increase count, place yo the wregXORLW D'8' ;Check wheather the count egual = 8BTFSC 03,02 ;check the zero flag in status registerGOTO 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_TIMECLRF 0X0FMOVF 0F,WCALL TIMERBSF RSMOVWF PORTBCALL EnableINCF 0F,WXORLW D'10'BTFSC 03,02GOTO SWITCHINCF 0F,FGOTO $-0A
;-------------Switch---------------------------------------SWITCH
BTFSC START ; check the Start button pressedGOTO $-1 ; if not pressed, repeat, else will skip this step
;---------XX:XX:XX.0---------------------------------------
MMSEC1CALL ADDRS_STARTCLRF 0X0FMOVF 0F,WCALL RUNBSF RSMOVWF PORTBCALL EnableINCF 0F,WXORLW D'8'BTFSC 03,02GOTO MMSECINCF 0F,FGOTO $-0A
;---------XX:XX:X0.x----------------------------------------MMSEC
CALL ADDRS_MMSECULE
BTFSS STOP ;is it STOP button pressed?GOTO FINISH ;if pressed, jump to stop location
MOVF 0D,W ;if not press, proceed the instructionCALL NOBSF RSMOVWF PORTB ;display at LCDCALL EnableCALL DELAY_0.1S ; delay 0.1 seconds
CALL MOVE_LEFT ;move location displayINCF 0D,W ;INCREASEXORLW D'10' ;would that make it increase to 9?BTFSC 03,02 ;set the zero flag in status registerGOTO MSECINCF 0D,F
BTFSS STOP ;is it STOP button pressed?GOTO FINISH ;if pressed, jump to stop locationGOTO ULE ;if not pressed, proceed counter
;-------XX:XX:0X.X-----------------
MSECCALL ADDRS_MSECMOVF 0E,WCALL NOBSF RSMOVWF PORTBCALL Enable
CALL ADDRS_MMSECCLRF 0DMOVF 0D,WCALL NOBSF RSMOVWF PORTBCALL EnableCALL DELAY_0.1SINCF 0D,F
INCF 0E,WXORLW D'11'BTFSC 03,02GOTO SECINCF 0E,FGOTO MMSEC
;--------XX:X0:XX.X---------------SEC
CALL ADDRS_SECMOVF 30,WCALL NOBSF RSMOVWF PORTBCALL Enable
CALL ADDRS_MSECCLRF 0EMOVF 0E,WCALL NOBSF RSMOVWF PORTBCALL EnableINCF 0E,FINCF 0D,F
INCF 30,WXORLW D'7'BTFSC 03,02GOTO NEXT_SECINCF 30,FGOTO MMSEC
;-------XX:X0:XX.X-----
NEXT_SECCALL ADDRS_NEXTSECMOVF 31,WCALL NOBSF RSMOVWF PORTBCALL Enable
CALL ADDRS_SEC
CLRF 30MOVF 30,WCALL NOBSF RSMOVWF PORTBCALL EnableINCF 30,F
CLRF 0EMOVF 0E,WCALL NOBSF RSMOVWF PORTBCALL EnableINCF 0E,FINCF 0D,F
INCF 31,WXORLW D'11'BTFSC 03,02GOTO FINISHINCF 31,FGOTO MMSEC
;---TIME STOP-----------FINISH
CALL ADDRS_STARTCLRF 0X0FMOVF 0F,WCALL TEXT_STOP1BSF RSMOVWF PORTBCALL EnableINCF 0F,WXORLW D'8'BTFSC 03,02GOTO $+03INCF 0F,FGOTO $-0A
BTFSS RESET ; check the reset buttonGOTO BEGIN ; if press goto initliaze program
BTFSS START ; check the start buttonGOTO MMSEC1 ; if pressed, continue counterGOTO $-04 ; loop to check both button
;--------SUBROUTINE TO DISPLAY------------Enable
BSF EBCF ECALL DELAY_125MCSRETLW 0
NOADDWF PCLRETLW '0'RETLW '1'RETLW '2'RETLW '3'RETLW '4'RETLW '5'RETLW '6'RETLW '7'
RETLW '8'RETLW '9'
TEXTADDWF PCLRETLW 'S'RETLW 'T'RETLW 'A'RETLW 'R'RETLW 'T'RETLW 0X20 ;BLANK SPACERETLW 0X20 ;BLANK SPACERETLW 0X20 ;BLANK SPACE
RUNADDWF PCLRETLW 'R'RETLW 'U'RETLW 'N'RETLW 'N'RETLW 'I'RETLW 'N'RETLW 'G'RETLW '!'
TIMERADDWF PCLRETLW '0'RETLW '0'RETLW ':'RETLW '0'RETLW '0'RETLW ':'RETLW '0'RETLW '0'RETLW '.'RETLW '0'
TEXT_STOP1ADDWF PCLRETLW 'S'RETLW 'T'RETLW 'O'RETLW 'P'RETLW '!'RETLW '!'RETLW 0X20RETLW 0X20
;--------COMMAND FOR LCD-----------FUNCSET
BCF RSCALL DELAY_125MCSMOVLW 0x38 ; code for 8 bit LCD and 2 linesMOVWF PORTBCALL EnableRETURN
DIS_ONBCF RSCALL DELAY_125MCSMOVLW 0x0C ; code for display On and off cursorMOVWF PORTB
CALL EnableRETURN
ENTRY_MODEBCF RSCALL DELAY_125MCSMOVLW 0x06MOVWF PORTBCALL EnableRETURN
MOVE_LEFTBCF RSCALL DELAY_125MCSMOVLW 0x10MOVWF PORTBCALL EnableRETURN
;------address display----------------------------ADDRS_MSEC
BCF RSCALL DELAY_125MCSMOVLW 0xC8MOVWF PORTBCALL EnableRETURN
ADDRS_SECBCF RSCALL DELAY_125MCSMOVLW 0xC7MOVWF PORTBCALL EnableRETURN
ADDRS_NEXTSECBCF RSCALL DELAY_125MCSMOVLW 0xC5MOVWF PORTBCALL EnableRETURN
ADDRS_MMSECBCF RSCALL DELAY_125MCSMOVLW 0xCAMOVWF PORTBCALL EnableRETURN
ADDRS_STARTBCF RSCALL DELAY_125MCSMOVLW 0x85MOVWF PORTBCALL EnableRETURN
ADDRS_TIMEBCF RSCALL DELAY_125MCS
MOVLW 0xC1MOVWF PORTBCALL EnableRETURN
;------Delay subroutine------DELAY_125MCS
MOVLW D'42'MOVWF D3
DECFSZ D3,FGOTO $-1RETURN
DELAY_5MSMOVLW D'41'MOVWF D2
CALL DELAY_125MCSDECFSZ D2,FGOTO $-2RETURN
DELAY_0.1SMOVLW D'50'MOVWF D3MOVLW D'13'MOVWF D2MOVLW D'50'MOVWF D1DECFSZ D1GOTO $-1DECFSZ D2GOTO $-5DECFSZ D3GOTO $-9RETURN
END