stopwatch using pic16f84a

Discussion in 'Homework Help' started by Phantasm, Nov 3, 2009.

  1. Phantasm

    Thread Starter New Member

    Nov 3, 2009
    6
    0
    can anyone help me about my project at school. the source code and diagram.
     
  2. SgtWookie

    Expert

    Jul 17, 2007
    22,182
    1,728
    We don't do your homework for you.

    If you are stuck on something, we can help you.

    Post your circuit diagram and the code that you have written thus far.

    This topic will be moved to the Homework Help forum before too long.
     
  3. Phantasm

    Thread Starter New Member

    Nov 3, 2009
    6
    0
    i need to modify the source code. see attachedment for diagram.

    ; Begin
    R0L EQU 0xC
    R0H EQU 0xD
    R1L EQU 0xE
    R1H EQU 0xF
    R2L EQU 0x10
    R2H EQU 0x11
    R3L EQU 0x12
    R3H EQU 0x13
    R4L EQU 0x14
    R4H EQU 0x15
    R5L EQU 0x16
    R5H EQU 0x17
    ORG 0x0000
    BCF PCLATH,3
    BCF PCLATH,4
    GOTO L0010
    ORG 0x0004
    RETFIE
    L0010:
    ; 1: TRISA = 16
    BSF STATUS,RP0
    MOVLW 0x10
    MOVWF 0x05
    ; 2: TRISB = 192
    MOVLW 0xC0
    MOVWF 0x06
    BCF STATUS,RP0
    ; 3: Dim a(7) As Byte
    ; The address of 'a' is 0x18
    a EQU 0x18
    ; 4: Dim b As Byte
    ; The address of 'b' is 0x1F
    b EQU 0x1F
    ; 5: Dim n As Byte
    ; The address of 'n' is 0x20
    n EQU 0x20
    ; 6: Dim x As Byte
    ; The address of 'x' is 0x21
    x EQU 0x21
    ; 7: Dim y As Byte
    ; The address of 'y' is 0x22
    y EQU 0x22
    ; 8: RA = 0
    CLRF 0x05
    ; 9: RB = 0
    CLRF 0x06
    ; 10: a(5) = 2
    MOVLW 0x02
    MOVWF 0x1D
    ; 11: a(6) = 1
    MOVLW 0x01
    MOVWF 0x1E
    ; 12:
    ; 13: start:
    L0001:
    ; 14: b = b + 1
    MOVF 0x1F,W
    ADDLW 0x01
    MOVWF 0x1F
    ; 15: If b = 2 Then
    MOVF 0x1F,W
    SUBLW 0x02
    BTFSS STATUS,Z
    GOTO L0011
    ; 16: a(1) = a(1) + 1
    MOVF 0x19,W
    ADDLW 0x01
    MOVWF 0x19
    ; 17: b = 0
    CLRF 0x1F
    ; 18: Endif
    L0011: MOVLW 0x1F
    ANDWF STATUS,F
    ; 19: If a(1) = 10 Then
    MOVF 0x19,W
    SUBLW 0x0A
    BTFSS STATUS,Z
    GOTO L0012
    ; 20: a(2) = a(2) + 1
    MOVF 0x1A,W
    ADDLW 0x01
    MOVWF 0x1A
    ; 21: a(1) = 0
    CLRF 0x19
    ; 22: Endif
    L0012: MOVLW 0x1F
    ANDWF STATUS,F
    ; 23: If a(2) = 6 Then
    MOVF 0x1A,W
    SUBLW 0x06
    BTFSS STATUS,Z
    GOTO L0013
    ; 24: a(3) = a(3) + 1
    MOVF 0x1B,W
    ADDLW 0x01
    MOVWF 0x1B
    ; 25: a(2) = 0
    CLRF 0x1A
    ; 26: Endif
    L0013: MOVLW 0x1F
    ANDWF STATUS,F
    ; 27: If a(3) = 10 Then
    MOVF 0x1B,W
    SUBLW 0x0A
    BTFSS STATUS,Z
    GOTO L0014
    ; 28: a(4) = a(4) + 1
    MOVF 0x1C,W
    ADDLW 0x01
    MOVWF 0x1C
    ; 29: a(3) = 0
    CLRF 0x1B
    ; 30: Endif
    L0014: MOVLW 0x1F
    ANDWF STATUS,F
    ; 31: If a(4) = 6 Then
    MOVF 0x1C,W
    SUBLW 0x06
    BTFSS STATUS,Z
    GOTO L0015
    ; 32: a(5) = a(5) + 1
    MOVF 0x1D,W
    ADDLW 0x01
    MOVWF 0x1D
    ; 33: a(4) = 0
    CLRF 0x1C
    ; 34: Endif
    L0015: MOVLW 0x1F
    ANDWF STATUS,F
    ; 35: If a(5) = 10 Then
    MOVF 0x1D,W
    SUBLW 0x0A
    BTFSS STATUS,Z
    GOTO L0016
    ; 36: a(6) = 1
    MOVLW 0x01
    MOVWF 0x1E
    ; 37: a(5) = 0
    CLRF 0x1D
    ; 38: Endif
    L0016: MOVLW 0x1F
    ANDWF STATUS,F
    ; 39: If a(6) = 1 Then
    MOVF 0x1E,W
    SUBLW 0x01
    BTFSS STATUS,Z
    GOTO L0017
    ; 40: If a(5) = 3 Then
    MOVF 0x1D,W
    SUBLW 0x03
    BTFSS STATUS,Z
    GOTO L0018
    ; 41: a(6) = 0
    CLRF 0x1E
    ; 42: a(5) = 1
    MOVLW 0x01
    MOVWF 0x1D
    ; 43: Endif
    L0018: MOVLW 0x1F
    ANDWF STATUS,F
    ; 44: Endif
    L0017: MOVLW 0x1F
    ANDWF STATUS,F
    ; 45:
    ; 46:
    ; 47: For x = 1 To 6
    MOVLW 0x01
    MOVWF 0x21
    L0019:
    MOVF 0x21,W
    SUBLW 0x06
    BTFSS STATUS,C
    GOTO L0020
    ; 48: RA = a(x)
    MOVF 0x21,W
    ADDLW 0x18
    MOVWF FSR
    MOVF INDF,W
    MOVWF 0x05
    ; 49: RB = x
    MOVF 0x21,W
    MOVWF 0x06
    ; 50: If x = 3 Then
    MOVF 0x21,W
    SUBLW 0x03
    BTFSS STATUS,Z
    GOTO L0021
    ; 51: RB = 4
    MOVLW 0x04
    MOVWF 0x06
    ; 52: Endif
    L0021: MOVLW 0x1F
    ANDWF STATUS,F
    ; 53: If x = 4 Then
    MOVF 0x21,W
    SUBLW 0x04
    BTFSS STATUS,Z
    GOTO L0022
    ; 54: RB = 8
    MOVLW 0x08
    MOVWF 0x06
    ; 55: Endif
    L0022: MOVLW 0x1F
    ANDWF STATUS,F
    ; 56: If x = 5 Then
    MOVF 0x21,W
    SUBLW 0x05
    BTFSS STATUS,Z
    GOTO L0023
    ; 57: RB = 16
    MOVLW 0x10
    MOVWF 0x06
    ; 58: Endif
    L0023: MOVLW 0x1F
    ANDWF STATUS,F
    ; 59: If x = 6 Then
    MOVF 0x21,W
    SUBLW 0x06
    BTFSS STATUS,Z
    GOTO L0024
    ; 60: RB = 32
    MOVLW 0x20
    MOVWF 0x06
    ; 61: Endif
    L0024: MOVLW 0x1F
    ANDWF STATUS,F
    ; 62: WaitMs 30
    MOVLW 0x1E
    MOVWF R0L
    CLRF R0H
    CALL W001
    ; 63: Next x
    MOVLW 0x01
    ADDWF 0x21,F
    BTFSS STATUS,C
    GOTO L0019
    L0020: MOVLW 0x1F
    ANDWF STATUS,F
    ; 64: If RA.4 = 0 Then
    BTFSC 0x05,4
    GOTO L0025
    ; 65: j1:
    L0002:
    ; 66: If RA.4 = 1 Then
    BTFSS 0x05,4
    GOTO L0026
    ; 67: Goto select_time
    GOTO L0006
    ; 68: Else
    GOTO L0027
    L0026: MOVLW 0x1F
    ANDWF STATUS,F
    ; 69: Goto j1
    GOTO L0002
    ; 70: Endif
    L0027: MOVLW 0x1F
    ANDWF STATUS,F
    ; 71: Endif
    L0025: MOVLW 0x1F
    ANDWF STATUS,F
    ; 72: Goto start
    GOTO L0001
    ; 73: End
    L0028: GOTO L0028
    ; 74: compare:
    L0003:
    ; 75: If a(1) = 10 Then
    MOVF 0x19,W
    SUBLW 0x0A
    BTFSS STATUS,Z
    GOTO L0029
    ; 76: a(1) = 0
    CLRF 0x19
    ; 77: Endif
    L0029: MOVLW 0x1F
    ANDWF STATUS,F
    ; 78: If a(2) = 6 Then
    MOVF 0x1A,W
    SUBLW 0x06
    BTFSS STATUS,Z
    GOTO L0030
    ; 79: a(2) = 0
    CLRF 0x1A
    ; 80: Endif
    L0030: MOVLW 0x1F
    ANDWF STATUS,F
    ; 81: If a(3) = 10 Then
    MOVF 0x1B,W
    SUBLW 0x0A
    BTFSS STATUS,Z
    GOTO L0031
    ; 82: a(3) = 0
    CLRF 0x1B
    ; 83: Endif
    L0031: MOVLW 0x1F
    ANDWF STATUS,F
    ; 84: If a(4) = 6 Then
    MOVF 0x1C,W
    SUBLW 0x06
    BTFSS STATUS,Z
    GOTO L0032
    ; 85: a(4) = 0
    CLRF 0x1C
    ; 86: Endif
    L0032: MOVLW 0x1F
    ANDWF STATUS,F
    ; 87: If a(5) = 10 Then
    MOVF 0x1D,W
    SUBLW 0x0A
    BTFSS STATUS,Z
    GOTO L0033
    ; 88: a(5) = 0
    CLRF 0x1D
    ; 89: Endif
    L0033: MOVLW 0x1F
    ANDWF STATUS,F
    ; 90: If a(6) = 1 Then
    MOVF 0x1E,W
    SUBLW 0x01
    BTFSS STATUS,Z
    GOTO L0034
    ; 91: If a(5) = 3 Then
    MOVF 0x1D,W
    SUBLW 0x03
    BTFSS STATUS,Z
    GOTO L0035
    ; 92: a(5) = 1
    MOVLW 0x01
    MOVWF 0x1D
    ; 93: Endif
    L0035: MOVLW 0x1F
    ANDWF STATUS,F
    ; 94: Endif
    L0034: MOVLW 0x1F
    ANDWF STATUS,F
    ; 95: If a(6) > 1 Then
    MOVF 0x1E,W
    SUBLW 0x01
    BTFSC STATUS,C
    GOTO L0036
    ; 96: a(6) = 0
    CLRF 0x1E
    ; 97: Endif
    L0036: MOVLW 0x1F
    ANDWF STATUS,F
    ; 98: Return
    RETURN
    ; 99: ok:
    L0004:
    ; 100: If RA.4 = 0 Then
    BTFSC 0x05,4
    GOTO L0037
    ; 101: j4:
    L0005:
    ; 102: If RA.4 = 1 Then
    BTFSS 0x05,4
    GOTO L0038
    ; 103: Goto start
    GOTO L0001
    ; 104: Else
    GOTO L0039
    L0038: MOVLW 0x1F
    ANDWF STATUS,F
    ; 105: Goto j4
    GOTO L0005
    ; 106: Endif
    L0039: MOVLW 0x1F
    ANDWF STATUS,F
    ; 107: Endif
    L0037: MOVLW 0x1F
    ANDWF STATUS,F
    ; 108: Return
    RETURN
    ; 109: select_time:
    L0006:
    ; 110: If RB.6 = 0 Then
    BTFSC 0x06,6
    GOTO L0040
    ; 111: j2:
    L0007:
    ; 112: If RB.6 = 1 Then
    BTFSS 0x06,6
    GOTO L0041
    ; 113: x = x + 1
    MOVF 0x21,W
    ADDLW 0x01
    MOVWF 0x21
    ; 114: If x > 6 Then
    MOVF 0x21,W
    SUBLW 0x06
    BTFSC STATUS,C
    GOTO L0042
    ; 115: x = 1
    MOVLW 0x01
    MOVWF 0x21
    ; 116: Endif
    L0042: MOVLW 0x1F
    ANDWF STATUS,F
    ; 117: n = x
    MOVF 0x21,W
    MOVWF 0x20
    ; 118: If x = 3 Then
    MOVF 0x21,W
    SUBLW 0x03
    BTFSS STATUS,Z
    GOTO L0043
    ; 119: n = 4
    MOVLW 0x04
    MOVWF 0x20
    ; 120: Endif
    L0043: MOVLW 0x1F
    ANDWF STATUS,F
    ; 121: If x = 4 Then
    MOVF 0x21,W
    SUBLW 0x04
    BTFSS STATUS,Z
    GOTO L0044
    ; 122: n = 8
    MOVLW 0x08
    MOVWF 0x20
    ; 123: Endif
    L0044: MOVLW 0x1F
    ANDWF STATUS,F
    ; 124: If x = 5 Then
    MOVF 0x21,W
    SUBLW 0x05
    BTFSS STATUS,Z
    GOTO L0045
    ; 125: n = 16
    MOVLW 0x10
    MOVWF 0x20
    ; 126: Endif
    L0045: MOVLW 0x1F
    ANDWF STATUS,F
    ; 127: If x = 6 Then
    MOVF 0x21,W
    SUBLW 0x06
    BTFSS STATUS,Z
    GOTO L0046
    ; 128: n = 32
    MOVLW 0x20
    MOVWF 0x20
    ; 129: Endif
    L0046: MOVLW 0x1F
    ANDWF STATUS,F
    ; 130: RA = a(x)
    MOVF 0x21,W
    ADDLW 0x18
    MOVWF FSR
    MOVF INDF,W
    MOVWF 0x05
    ; 131: RB = n
    MOVF 0x20,W
    MOVWF 0x06
    ; 132: Else
    GOTO L0047
    L0041: MOVLW 0x1F
    ANDWF STATUS,F
    ; 133: Goto j2
    GOTO L0007
    ; 134: Endif
    L0047: MOVLW 0x1F
    ANDWF STATUS,F
    ; 135: Endif
    L0040: MOVLW 0x1F
    ANDWF STATUS,F
    ; 136: If RB.7 = 0 Then
    BTFSC 0x06,7
    GOTO L0048
    ; 137: Goto change
    GOTO L0008
    ; 138: Endif
    L0048: MOVLW 0x1F
    ANDWF STATUS,F
    ; 139: Gosub ok
    CALL L0004
    ; 140: Goto select_time
    GOTO L0006
    ; 141: Return
    RETURN
    ; 142: change:
    L0008:
    ; 143: If RB.7 = 0 Then
    BTFSC 0x06,7
    GOTO L0049
    ; 144: j3:
    L0009:
    ; 145: If RB.7 = 1 Then
    BTFSS 0x06,7
    GOTO L0050
    ; 146: a(x) = a(x) + 1
    MOVF 0x21,W
    ADDLW 0x18
    MOVWF FSR
    MOVF INDF,W
    ADDLW 0x01
    MOVWF R5L
    MOVF 0x21,W
    ADDLW 0x18
    MOVWF FSR
    MOVF R5L,W
    MOVWF INDF
    ; 147: Gosub compare
    CALL L0003
    ; 148: RA = a(x)
    MOVF 0x21,W
    ADDLW 0x18
    MOVWF FSR
    MOVF INDF,W
    MOVWF 0x05
    ; 149: Else
    GOTO L0051
    L0050: MOVLW 0x1F
    ANDWF STATUS,F
    ; 150: Goto j3
    GOTO L0009
    ; 151: Endif
    L0051: MOVLW 0x1F
    ANDWF STATUS,F
    ; 152: Endif
    L0049: MOVLW 0x1F
    ANDWF STATUS,F
    ; 153: If RB.6 = 0 Then
    BTFSC 0x06,6
    GOTO L0052
    ; 154: Gosub select_time
    CALL L0006
    ; 155: Endif
    L0052: MOVLW 0x1F
    ANDWF STATUS,F
    ; 156: Gosub ok
    CALL L0004
    ; 157: Goto change
    GOTO L0008
    ; End of program
    L0053: GOTO L0053
    ; Waitms Routine
    W001: MOVF R0L,F
    BTFSC STATUS,Z
    GOTO W002
    CALL W003
    DECF R0L,F
    NOP
    NOP
    NOP
    NOP
    NOP
    GOTO W001
    W002: MOVF R0H,F
    BTFSC STATUS,Z
    RETURN
    CALL W003
    DECF R0H,F
    DECF R0L,F
    GOTO W001
    W003: MOVLW 0x0C
    MOVWF R2H
    W004: DECFSZ R2H,F
    GOTO W004
    NOP
    NOP
    MOVLW 0x12
    MOVWF R1L
    W005: DECFSZ R1L,F
    GOTO W006
    CALL W007
    CALL W007
    NOP
    NOP
    RETURN
    W006: CALL W007
    GOTO W005
    W007: MOVLW 0x0D
    MOVWF R2L
    W008: DECFSZ R2L,F
    GOTO W008
    NOP
    RETURN
    ; End of listing
    END
     
  4. auri_z

    New Member

    Feb 5, 2009
    8
    0
    post your code more readibility , some people do not like to analyze the code that does not irregular or create attachments in either format as the format used mplab

    what you want to modify, explain fully what you want in reach
     
  5. AlexR

    Well-Known Member

    Jan 16, 2008
    735
    54
    Your code as it stands is totally unreadable!

    Use the CODE tags to preserve formatting, keep comments on the same line as the code they refer to, use meaningful variable names to give the reader a clue of their function and include a brief description of what the code is supposed to do and what functions you are trying to modify.

    Do this and you will get plenty of help but no-one is going to waste their time trying to unravel pages of obscure and unreadable code.
     
  6. Phantasm

    Thread Starter New Member

    Nov 3, 2009
    6
    0
    sorry .. here its a digital clock and i want stopwatch dispaly minutes seconds and milliseconds.thanks

    Begin
    R0L EQU 0xC
    R0H EQU 0xD
    R1L EQU 0xE
    R1H EQU 0xF
    R2L EQU 0x10
    R2H EQU 0x11
    R3L EQU 0x12
    R3H EQU 0x13
    R4L EQU 0x14
    R4H EQU 0x15
    R5L EQU 0x16
    R5H EQU 0x17
    ORG 0x0000
    BCF PCLATH,3
    BCF PCLATH,4
    GOTO L0010
    ORG 0x0004
    RETFIE
    L0010:

    BSF STATUS,RP0
    MOVLW 0x10
    MOVWF 0x05

    MOVLW 0xC0
    MOVWF 0x06
    BCF STATUS,RP0


    a EQU 0x18


    b EQU 0x1F


    n EQU 0x20


    x EQU 0x21


    y EQU 0x22

    CLRF 0x05

    CLRF 0x06

    MOVLW 0x02
    MOVWF 0x1D

    MOVLW 0x01
    MOVWF 0x1E

    L0001:

    MOVF 0x1F,W
    ADDLW 0x01
    MOVWF 0x1F

    MOVF 0x1F,W
    SUBLW 0x02
    BTFSS STATUS,Z
    GOTO L0011

    MOVF 0x19,W
    ADDLW 0x01
    MOVWF 0x19

    CLRF 0x1F

    L0011: MOVLW 0x1F
    ANDWF STATUS,F

    MOVF 0x19,W
    SUBLW 0x0A
    BTFSS STATUS,Z
    GOTO L0012

    MOVF 0x1A,W
    ADDLW 0x01
    MOVWF 0x1A

    CLRF 0x19

    L0012: MOVLW 0x1F
    ANDWF STATUS,F

    MOVF 0x1A,W
    SUBLW 0x06
    BTFSS STATUS,Z
    GOTO L0013

    MOVF 0x1B,W
    ADDLW 0x01
    MOVWF 0x1B

    CLRF 0x1A

    L0013: MOVLW 0x1F
    ANDWF STATUS,F

    MOVF 0x1B,W
    SUBLW 0x0A
    BTFSS STATUS,Z
    GOTO L0014

    MOVF 0x1C,W
    ADDLW 0x01
    MOVWF 0x1C

    CLRF 0x1B

    L0014: MOVLW 0x1F
    ANDWF STATUS,F

    MOVF 0x1C,W
    SUBLW 0x06
    BTFSS STATUS,Z
    GOTO L0015

    MOVF 0x1D,W
    ADDLW 0x01
    MOVWF 0x1D

    CLRF 0x1C

    L0015: MOVLW 0x1F
    ANDWF STATUS,F

    MOVF 0x1D,W
    SUBLW 0x0A
    BTFSS STATUS,Z
    GOTO L0016

    MOVLW 0x01
    MOVWF 0x1E

    CLRF 0x1D

    L0016: MOVLW 0x1F
    ANDWF STATUS,F

    MOVF 0x1E,W
    SUBLW 0x01
    BTFSS STATUS,Z
    GOTO L0017

    MOVF 0x1D,W
    SUBLW 0x03
    BTFSS STATUS,Z
    GOTO L0018

    CLRF 0x1E

    MOVLW 0x01
    MOVWF 0x1D

    L0018: MOVLW 0x1F
    ANDWF STATUS,F

    L0017: MOVLW 0x1F
    ANDWF STATUS,F



    MOVLW 0x01
    MOVWF 0x21
    L0019:
    MOVF 0x21,W
    SUBLW 0x06
    BTFSS STATUS,C
    GOTO L0020

    MOVF 0x21,W
    ADDLW 0x18
    MOVWF FSR
    MOVF INDF,W
    MOVWF 0x05

    MOVF 0x21,W
    MOVWF 0x06

    MOVF 0x21,W
    SUBLW 0x03
    BTFSS STATUS,Z
    GOTO L0021

    MOVLW 0x04
    MOVWF 0x06

    L0021: MOVLW 0x1F
    ANDWF STATUS,F

    MOVF 0x21,W
    SUBLW 0x04
    BTFSS STATUS,Z
    GOTO L0022

    MOVLW 0x08
    MOVWF 0x06

    L0022: MOVLW 0x1F
    ANDWF STATUS,F

    MOVF 0x21,W
    SUBLW 0x05
    BTFSS STATUS,Z
    GOTO L0023

    MOVLW 0x10
    MOVWF 0x06

    L0023: MOVLW 0x1F
    ANDWF STATUS,F

    MOVF 0x21,W
    SUBLW 0x06
    BTFSS STATUS,Z
    GOTO L0024

    MOVLW 0x20
    MOVWF 0x06

    L0024: MOVLW 0x1F
    ANDWF STATUS,F

    MOVLW 0x1E
    MOVWF R0L
    CLRF R0H
    CALL W001

    MOVLW 0x01
    ADDWF 0x21,F
    BTFSS STATUS,C
    GOTO L0019
    L0020: MOVLW 0x1F
    ANDWF STATUS,F

    BTFSC 0x05,4
    GOTO L0025

    L0002:

    BTFSS 0x05,4
    GOTO L0026

    GOTO L0006

    GOTO L0027
    L0026: MOVLW 0x1F
    ANDWF STATUS,F

    GOTO L0002

    L0027: MOVLW 0x1F
    ANDWF STATUS,F

    L0025: MOVLW 0x1F
    ANDWF STATUS,F

    GOTO L0001

    L0028: GOTO L0028

    L0003:

    MOVF 0x19,W
    SUBLW 0x0A
    BTFSS STATUS,Z
    GOTO L0029

    CLRF 0x19

    L0029: MOVLW 0x1F
    ANDWF STATUS,F

    MOVF 0x1A,W
    SUBLW 0x06
    BTFSS STATUS,Z
    GOTO L0030

    CLRF 0x1A

    L0030: MOVLW 0x1F
    ANDWF STATUS,F

    MOVF 0x1B,W
    SUBLW 0x0A
    BTFSS STATUS,Z
    GOTO L0031

    CLRF 0x1B

    L0031: MOVLW 0x1F
    ANDWF STATUS,F

    MOVF 0x1C,W
    SUBLW 0x06
    BTFSS STATUS,Z
    GOTO L0032

    CLRF 0x1C

    L0032: MOVLW 0x1F
    ANDWF STATUS,F

    MOVF 0x1D,W
    SUBLW 0x0A
    BTFSS STATUS,Z
    GOTO L0033

    CLRF 0x1D

    L0033: MOVLW 0x1F
    ANDWF STATUS,F

    MOVF 0x1E,W
    SUBLW 0x01
    BTFSS STATUS,Z
    GOTO L0034

    MOVF 0x1D,W
    SUBLW 0x03
    BTFSS STATUS,Z
    GOTO L0035

    MOVLW 0x01
    MOVWF 0x1D

    L0035: MOVLW 0x1F
    ANDWF STATUS,F

    L0034: MOVLW 0x1F
    ANDWF STATUS,F

    MOVF 0x1E,W
    SUBLW 0x01
    BTFSC STATUS,C
    GOTO L0036

    CLRF 0x1E

    L0036: MOVLW 0x1F
    ANDWF STATUS,F

    RETURN

    L0004:

    BTFSC 0x05,4
    GOTO L0037

    L0005:

    BTFSS 0x05,4
    GOTO L0038

    GOTO L0001

    GOTO L0039
    L0038: MOVLW 0x1F
    ANDWF STATUS,F

    GOTO L0005

    L0039: MOVLW 0x1F
    ANDWF STATUS,F

    L0037: MOVLW 0x1F
    ANDWF STATUS,F

    RETURN

    L0006:

    BTFSC 0x06,6
    GOTO L0040

    L0007:

    BTFSS 0x06,6
    GOTO L0041

    MOVF 0x21,W
    ADDLW 0x01
    MOVWF 0x21

    MOVF 0x21,W
    SUBLW 0x06
    BTFSC STATUS,C
    GOTO L0042

    MOVLW 0x01
    MOVWF 0x21

    L0042: MOVLW 0x1F
    ANDWF STATUS,F

    MOVF 0x21,W
    MOVWF 0x20

    MOVF 0x21,W
    SUBLW 0x03
    BTFSS STATUS,Z
    GOTO L0043

    MOVLW 0x04
    MOVWF 0x20

    L0043: MOVLW 0x1F
    ANDWF STATUS,F

    MOVF 0x21,W
    SUBLW 0x04
    BTFSS STATUS,Z
    GOTO L0044

    MOVLW 0x08
    MOVWF 0x20

    L0044: MOVLW 0x1F
    ANDWF STATUS,F

    MOVF 0x21,W
    SUBLW 0x05
    BTFSS STATUS,Z
    GOTO L0045

    MOVLW 0x10
    MOVWF 0x20

    L0045: MOVLW 0x1F
    ANDWF STATUS,F

    MOVF 0x21,W
    SUBLW 0x06
    BTFSS STATUS,Z
    GOTO L0046

    MOVLW 0x20
    MOVWF 0x20

    L0046: MOVLW 0x1F
    ANDWF STATUS,F

    MOVF 0x21,W
    ADDLW 0x18
    MOVWF FSR
    MOVF INDF,W
    MOVWF 0x05

    MOVF 0x20,W
    MOVWF 0x06

    GOTO L0047
    L0041: MOVLW 0x1F
    ANDWF STATUS,F

    GOTO L0007

    L0047: MOVLW 0x1F
    ANDWF STATUS,F

    L0040: MOVLW 0x1F
    ANDWF STATUS,F

    BTFSC 0x06,7
    GOTO L0048

    GOTO L0008

    L0048: MOVLW 0x1F
    ANDWF STATUS,F

    CALL L0004

    GOTO L0006

    RETURN

    L0008:

    BTFSC 0x06,7
    GOTO L0049

    L0009:

    BTFSS 0x06,7
    GOTO L0050

    MOVF 0x21,W
    ADDLW 0x18
    MOVWF FSR
    MOVF INDF,W
    ADDLW 0x01
    MOVWF R5L
    MOVF 0x21,W
    ADDLW 0x18
    MOVWF FSR
    MOVF R5L,W
    MOVWF INDF

    CALL L0003

    MOVF 0x21,W
    ADDLW 0x18
    MOVWF FSR
    MOVF INDF,W
    MOVWF 0x05

    GOTO L0051
    L0050: MOVLW 0x1F
    ANDWF STATUS,F

    GOTO L0009

    L0051: MOVLW 0x1F
    ANDWF STATUS,F

    L0049: MOVLW 0x1F

    BTFSC 0x06,6
    GOTO L0052

    CALL L0006

    L0052: MOVLW 0x1F
    ANDWF STATUS,F

    CALL L0004

    GOTO L0008

    L0053: GOTO L0053

    W001: MOVF R0L,F
    BTFSC STATUS,Z
    GOTO W002
    CALL W003
    DECF R0L,F
    NOP
    NOP
    NOP
    NOP
    NOP
    GOTO W001
    W002: MOVF R0H,F
    BTFSC STATUS,Z
    RETURN
    CALL W003
    DECF R0H,F
    DECF R0L,F
    GOTO W001
    W003: MOVLW 0x0C
    MOVWF R2H
    W004: DECFSZ R2H,F
    GOTO W004
    NOP
    NOP
    MOVLW 0x12
    MOVWF R1L
    W005: DECFSZ R1L,F
    GOTO W006
    CALL W007
    CALL W007
    NOP
    NOP
    RETURN
    W006: CALL W007
    GOTO W005
    W007: MOVLW 0x0D
    MOVWF R2L
    W008: DECFSZ R2L,F
    GOTO W008
    NOP
    RETURN

    END
     
  7. auri_z

    New Member

    Feb 5, 2009
    8
    0
    your code still dificult to read .use standar assembly in mplab
    so easy people understand people. use the comments to explain the function of the program you created

    use file attachments that not change your code layout

    I attach a program that I created to study the pic, but the comments in my language.



    read how to write assembly , you can search in web

    and again what your problemm.?

    if your code don't work , i think it don't work
    i suggest you fix your code fist and post here again what your problem.
    what your compiler say about your error..

    i am sorry if i wrong.
    i am just student
     
    Last edited: Nov 4, 2009
  8. Phantasm

    Thread Starter New Member

    Nov 3, 2009
    6
    0
    is there anyone who use pic16f84a stopwatch with diagram?
     
  9. DumboFixer

    Active Member

    Feb 10, 2009
    219
    34
    The original source code is embedded in the listing. Why post the compiler output insterad of the plain source ?

    Here's the original source (I think) with indenting added

    Code ( (Unknown Language)):
    1. ;Begin
    2. R0L EQU 0xC
    3. R0H EQU 0xD
    4. R1L EQU 0xE
    5. R1H EQU 0xF
    6. R2L EQU 0x10
    7. R2H EQU 0x11
    8. R3L EQU 0x12
    9. R3H EQU 0x13
    10. R4L EQU 0x14
    11. R4H EQU 0x15
    12. R5L EQU 0x16
    13. R5H EQU 0x17
    14.  
    15. TRISA = 16
    16. TRISB = 192
    17. Dim a(7) As Byte
    18. Dim b As Byte
    19. Dim n As Byte
    20. Dim x As Byte
    21. Dim y As Byte
    22. RA = 0
    23. RB = 0
    24. a(5) = 2
    25. a(6) = 1
    26.  
    27. start:
    28. b = b + 1
    29. If b = 2 Then
    30.     a(1) = a(1) + 1
    31.     b = 0
    32. Endif
    33. If a(1) = 10 Then
    34.     a(2) = a(2) + 1
    35.     (1) = 0
    36. Endif
    37. If a(2) = 6 Then
    38.     a(3) = a(3) + 1
    39.     a(2) = 0
    40. Endif
    41. If a(3) = 10 Then
    42.     a(4) = a(4) + 1
    43.     a(3) = 0
    44. Endif
    45. If a(4) = 6 Then
    46.     a(5) = a(5) + 1
    47.     a(4) = 0
    48. Endif
    49. If a(5) = 10 Then
    50.     a(6) = 1
    51.     a(5) = 0
    52. Endif
    53. If a(6) = 1 Then
    54.     If a(5) = 3 Then
    55.         a(6) = 0
    56.         a(5) = 1
    57.     Endif
    58. Endif
    59.  
    60. For x = 1 To 6
    61.     RA = a(x)
    62.     RB = x
    63.     If x = 3 Then
    64.         RB = 4
    65.     Endif
    66.     If x = 4 Then
    67.         RB = 8
    68.     Endif
    69.     If x = 5 Then
    70.         RB = 16
    71.     Endif
    72.     If x = 6 Then
    73.         RB = 32
    74.     Endif
    75.     WaitMs 30
    76. Next x
    77.  
    78. If RA.4 = 0 Then
    79.     j1:
    80.     If RA.4 = 1 Then
    81.         Goto select_time
    82.     Else
    83.         Goto j1
    84.     Endif
    85. Endif
    86.  
    87. Goto start
    88.  
    89. End
    90.  
    91. compare:
    92. If a(1) = 10 Then
    93.     a(1) = 0
    94. Endif
    95.  
    96. If a(2) = 6 Then
    97.     a(2) = 0
    98. Endif
    99.  
    100. If a(3) = 10 Then
    101.     a(3) = 0
    102. Endif
    103.  
    104. If a(4) = 6 Then
    105.     a(4) = 0
    106. Endif
    107.  
    108. If a(5) = 10 Then
    109.     a(5) = 0
    110. Endif
    111.  
    112. If a(6) = 1 Then
    113.     If a(5) = 3 Then
    114.         a(5) = 1
    115.     Endif
    116. Endif
    117.  
    118. If a(6) > 1 Then
    119.     a(6) = 0
    120. Endif
    121. Return
    122.  
    123. ok:
    124.     If RA.4 = 0 Then
    125.         j4:
    126.         If RA.4 = 1 Then
    127.             Goto start
    128.         Else
    129.             Goto j4
    130.         Endif
    131.     Endif
    132. Return
    133.  
    134. select_time:
    135. If RB.6 = 0 Then
    136.     j2:
    137.     If RB.6 = 1 Then
    138.         x = x + 1
    139.         If x > 6 Then
    140.             x = 1
    141.         Endif
    142.         n = x
    143.         If x = 3 Then
    144.             n = 4
    145.         Endif
    146.         If x = 4 Then
    147.             n = 8
    148.         Endif
    149.         If x = 5 Then
    150.             n = 16
    151.         Endif
    152.         If x = 6 Then
    153.             n = 32
    154.         Endif
    155.         RA = a(x)
    156.         RB = n
    157.     Else
    158.         Goto j2
    159.     Endif
    160. Endif
    161. If RB.7 = 0 Then
    162.     Goto change
    163. Endif
    164. Gosub ok
    165. Goto select_time
    166. Return
    167.  
    168. change:
    169. If RB.7 = 0 Then
    170.     j3:
    171.     If RB.7 = 1 Then
    172.         a(x) = a(x) + 1
    173.         Gosub compare
    174.         RA = a(x)
    175.     Else
    176.         Goto j3
    177.     Endif
    178. Endif
    179. If RB.6 = 0 Then
    180.     Gosub select_time
    181. Endif
    182. Gosub ok
    183. Goto change
    184. ;End of program
    185. END
    186.  
     
  10. Phantasm

    Thread Starter New Member

    Nov 3, 2009
    6
    0
    yah sorry . i want to change the clock to stopwatch. count 00:00.00 to 60:00.00
    (min,sec,msec)

    or

    maybe 000.0 to 999.9 (a 4 digit stopwatch) im still searching where i can find that.
     
  11. blueroomelectronics

    AAC Fanatic!

    Jul 22, 2007
    1,758
    98
    Would be helpful if you commented your code.
     
  12. DumboFixer

    Active Member

    Feb 10, 2009
    219
    34
    Does the code actually work ?
    Where does the output appear ?

    What concerns me is that you have a "gosub ok" which exits via a goto to the start of the program. This is going to fill your stack as the gosub places the return address on it expecting the "return" to pull it off.

    There are too many "goto" statements in it for my liking. Also subroutrine "select_time" could be tidied up using the "select case" construct.

    And as has been said above, comments in your code would help us (and you) a great deal.
     
  13. BMorse

    Senior Member

    Sep 26, 2009
    2,675
    234
    What is the timing of the stopwatch based on???? I do not see any timers being initialized to be used...... you can get a much more "accurate" time if you used a timer and interrupt routine.........


    My .02
     
  14. SgtWookie

    Expert

    Jul 17, 2007
    22,182
    1,728
    I'm convinced it's not source code that the OP has written, nor a schematic of their creation.

    It's a clock project they found on the Internet, and now they want us to decipher the poorly written and abysmally documented source code, and convert it into a timer for them.

    I don't see how they will learn anything with such an approach.
     
  15. BMorse

    Senior Member

    Sep 26, 2009
    2,675
    234

    It is not, the op contacted me by PM before he posted anything in the forum, I had suggested he post what he has already in the forums to get help if needed, and he had said he didnt have anything and basically wanted me to do it all for him.....
     
  16. t06afre

    AAC Fanatic!

    May 11, 2009
    5,939
    1,222
    I wonder how much the OP could have done if he/she had used the same time on the assignment, as he/she have used to find an easy way out from the assignment;) Pretty much I guess
     
  17. SgtWookie

    Expert

    Jul 17, 2007
    22,182
    1,728
    As it is, the source code needs to be thrown out and started over from scratch.

    Every section of code should be well documented as far as it's function, and how variables/registers are used.
     
  18. Phantasm

    Thread Starter New Member

    Nov 3, 2009
    6
    0
    its a digital clock.
     
  19. beenthere

    Retired Moderator

    Apr 20, 2004
    15,815
    282
    Yes, it has to be if based on a microprocessor. Do you understand how a digital clock functions?
     
Loading...