stopwatch using pic16f84a

SgtWookie

Joined Jul 17, 2007
22,230
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.
 

Thread Starter

Phantasm

Joined Nov 3, 2009
6
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
 

Attachments

auri_z

Joined Feb 5, 2009
8
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
 

AlexR

Joined Jan 16, 2008
732
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.
 

Thread Starter

Phantasm

Joined Nov 3, 2009
6
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
 

auri_z

Joined Feb 5, 2009
8
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
 

Attachments

Last edited:

DumboFixer

Joined Feb 10, 2009
217
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

Rich (BB code):
;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

TRISA = 16
TRISB = 192
Dim a(7) As Byte
Dim b As Byte
Dim n As Byte
Dim x As Byte
Dim y As Byte
RA = 0
RB = 0
a(5) = 2
a(6) = 1

start:
b = b + 1
If b = 2 Then
    a(1) = a(1) + 1
    b = 0
Endif
If a(1) = 10 Then
    a(2) = a(2) + 1
    (1) = 0
Endif
If a(2) = 6 Then
    a(3) = a(3) + 1
    a(2) = 0
Endif
If a(3) = 10 Then
    a(4) = a(4) + 1
    a(3) = 0
Endif
If a(4) = 6 Then
    a(5) = a(5) + 1
    a(4) = 0
Endif
If a(5) = 10 Then
    a(6) = 1
    a(5) = 0
Endif
If a(6) = 1 Then
    If a(5) = 3 Then
        a(6) = 0
        a(5) = 1
    Endif
Endif

For x = 1 To 6
    RA = a(x)
    RB = x
    If x = 3 Then
        RB = 4
    Endif
    If x = 4 Then
        RB = 8
    Endif
    If x = 5 Then
        RB = 16
    Endif
    If x = 6 Then
        RB = 32
    Endif
    WaitMs 30
Next x

If RA.4 = 0 Then
    j1:
    If RA.4 = 1 Then
        Goto select_time
    Else
        Goto j1
    Endif
Endif

Goto start

End

compare:
If a(1) = 10 Then
    a(1) = 0
Endif

If a(2) = 6 Then
    a(2) = 0
Endif

If a(3) = 10 Then
    a(3) = 0
Endif

If a(4) = 6 Then
    a(4) = 0
Endif

If a(5) = 10 Then
    a(5) = 0
Endif

If a(6) = 1 Then
    If a(5) = 3 Then
        a(5) = 1
    Endif
Endif

If a(6) > 1 Then
    a(6) = 0
Endif
Return

ok:
    If RA.4 = 0 Then
        j4:
        If RA.4 = 1 Then
            Goto start
        Else
            Goto j4
        Endif
    Endif
Return

select_time:
If RB.6 = 0 Then
    j2:
    If RB.6 = 1 Then
        x = x + 1
        If x > 6 Then
            x = 1
        Endif
        n = x
        If x = 3 Then
            n = 4
        Endif
        If x = 4 Then
            n = 8
        Endif
        If x = 5 Then
            n = 16
        Endif
        If x = 6 Then
            n = 32
        Endif
        RA = a(x)
        RB = n
    Else
        Goto j2
    Endif
Endif
If RB.7 = 0 Then
    Goto change
Endif
Gosub ok
Goto select_time
Return

change:
If RB.7 = 0 Then
    j3:
    If RB.7 = 1 Then
        a(x) = a(x) + 1
        Gosub compare
        RA = a(x)
    Else
        Goto j3
    Endif
Endif
If RB.6 = 0 Then
    Gosub select_time
Endif
Gosub ok
Goto change
;End of program
END
 

Thread Starter

Phantasm

Joined Nov 3, 2009
6
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.
 

DumboFixer

Joined Feb 10, 2009
217
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.
 

BMorse

Joined Sep 26, 2009
2,675
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
 

SgtWookie

Joined Jul 17, 2007
22,230
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.
 

BMorse

Joined Sep 26, 2009
2,675
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.

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

t06afre

Joined May 11, 2009
5,934
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
 

SgtWookie

Joined Jul 17, 2007
22,230
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.
 
Top