Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Strange timing problem

Status
Not open for further replies.

2camjohn

Member
I have been experimenting with programming pics but i have come upons a very strange and annoying problem.


Whenever i try and use a timing function (eg turn on an LED wait and turn it off) it just stops with the led left on.

I am using a pic16f84.

here is my compiled 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
ORG 0x0000
BCF PCLATH,3
BCF PCLATH,4
GOTO L0002
ORG 0x0004
RETFIE
L0002: NOP
; 1: TRISB = 0x00 'set all PORTB pins as outputs
BSF STATUS,RP0
CLRF 0x06
BCF STATUS,RP0
; 2: TRISA = %111111 'set PORTA pins as inputs
BSF STATUS,RP0
MOVLW 0x3F
MOVWF 0x05
BCF STATUS,RP0
; 3: start:
L0001: NOP
; 4: High PORTB.1
BSF PORTB,1
BSF STATUS,RP0
BCF TRISB,1
BCF STATUS,RP0
; 5: Low PORTB.0
BCF PORTB,0
BSF STATUS,RP0
BCF TRISB,0
BCF STATUS,RP0
; 6: WaitUs 255
MOVLW 0xFF
MOVWF R4L
CALL X001
; 7: Low PORTB.1
BCF PORTB,1
BSF STATUS,RP0
BCF TRISB,1
BCF STATUS,RP0
; 8: High PORTB.0
BSF PORTB,0
BSF STATUS,RP0
BCF TRISB,0
BCF STATUS,RP0
; 9: WaitUs 255
MOVLW 0xFF
MOVWF R4L
CALL X001
; 10: Goto start
GOTO L0001
; End of program
L0003: GOTO L0003
; Waitus Routine - Byte Argument
X001: MOVLW 0x0A
SUBWF R4L,F
BTFSS STATUS,C
RETURN
GOTO X002
X002: MOVLW 0x06
SUBWF R4L,F
BTFSS STATUS,C
RETURN
GOTO X002
; End of listing
END


Note it is supposed to flash two leds alternately, waiting 255ms between each flash. Instead both LEDs remain on permenantly.


Thanks for any help you can offer.
 
Status
Not open for further replies.

EE World Online Articles

Loading
Top