ColonelSanders
Newbie level 2
- Joined
- May 21, 2014
- Messages
- 2
- Helped
- 0
- Reputation
- 0
- Reaction score
- 0
- Trophy points
- 1
- Activity points
- 24
Greetings everyone. I am new to this forum. What I am trying to do is take a program I have already wrote and modify it a bit. First, this is for a PIC16F84A. I have a training board I can program this to but also can use MPLAB spftware to simulate.
Currently, my program code first Lights all LED's for a 0.48 second delay, then it extinguishes all LEDs with a 0.48 delay, then it moves on to the actual main program.
The 0.48 second delay is used later on within the program. What I am trying to do is have the initial LED test to use a 5 second delay instead of a 0.48 second delay, but still utilize the 0.48 second delay for the rest of the program.
To start, I will post my original program code that works correctly with only 0.48 second delay. Next I will post the code where I tried implementing the desired 5 second delay only in the initial LED test.
I would appreciate any advice that anyone could give me on how to accomplish my goal of having a 5 second delay (LEDs on 5 sec, LEDs off five seconds) in the initial LED test.
ORIGINAL (working) PROGRAM CODE BELOW:
My Attempt at adding the desired 5 second delay (probably royally screwed it up!):
Currently, my program code first Lights all LED's for a 0.48 second delay, then it extinguishes all LEDs with a 0.48 delay, then it moves on to the actual main program.
The 0.48 second delay is used later on within the program. What I am trying to do is have the initial LED test to use a 5 second delay instead of a 0.48 second delay, but still utilize the 0.48 second delay for the rest of the program.
To start, I will post my original program code that works correctly with only 0.48 second delay. Next I will post the code where I tried implementing the desired 5 second delay only in the initial LED test.
I would appreciate any advice that anyone could give me on how to accomplish my goal of having a 5 second delay (LEDs on 5 sec, LEDs off five seconds) in the initial LED test.
ORIGINAL (working) PROGRAM CODE BELOW:
Code:
#include <GENERAL.H> ;This is the header file
COUNT1 EQU 0X20 ; Counter for the inner loop
COUNT2 EQU 0X21 ; Counter for the middle loop
COUNT3 EQU 0X22 ; Counter for the outer loop
__CONFIG 0X3FF6 ;This is the control bits for CONFIG register
ORG 0X0000 ;RESET or WDT reset vector
GOTO START
ORG 0X0004 ;Regular INT vector
;This is the area where your interrupt service routine goes
RETFIE
START ;The starting place of the user codes
; The I/O must be set up. Pins 7,8,9,10 (PORTB) and 17,18,1,2 (PORTA)
; All other pins are inputs. This allows both port latches to use the same literal
CLRF PORTA ; Ensure both port latches are all 0 before
CLRF PORTB ; setting up I/O
BSF STATUS,RP0 ; Shift to bank 1 to change TRIS registers
MOVLW 0XF0 ; TRISA and TRISB both use F0 to have pins 0 - 3
MOVWF TRISA ; as outputs
MOVWF TRISB
MOVLW 0XFE
MOVWF OPTION_REG ; The prescales needs to be set to 04 for the
; watchdog timer to time out 1.15 seconds
BCF STATUS,RP0 ; Shift to bank 0 for normal operation
MOVLW 0X0F ; This will illuminate all lights
MOVWF PORTA ; when it is loaded in both ports
MOVWF PORTB
CALL DELAY ; Provides a .48 second delay
CLRF PORTA ; This will extenguish all lights
CLRF PORTB ; when it is loaded in both ports
CALL DELAY ; Provides a .48 second delay
SWTEST
CLRWDT
BTFSC PORTB,RB5 ; This is the switch for all LEDs being lit
CALL ALLIGHTS ; (Switch 3)
CLRWDT
BTFSC PORTB,RB6 ; This is the switch for red LEDs beig lit
CALL GREENLIGHTS ; (Switch 2)
CLRWDT
BTFSC PORTB,RB7 ; This is the switch for the yellow LEDs being lit
CALL YELLOWLIGHTS ; (Switch 1)
MOVLW 0X00 ; This will extenguish all lights
MOVWF PORTA ; when it is loaded in both ports
MOVWF PORTB
GOTO SWTEST ; Return to the top of the switch test loop
ALLIGHTS
MOVLW 0X0F ; This will illuminate all lights on PORTA
MOVWF PORTA
MOVLW 0X00 ; and extenguish all on PORTB
MOVWF PORTB
CALL DELAY
MOVLW 0X00 ; This will extenguish all lights on PORTA
MOVWF PORTA
MOVLW 0X0F ; and illuminate all lights on PORTB
MOVWF PORTB
CALL DELAY
RETURN ; Return to the top of the switch test loop
GREENLIGHTS
; If switch 2 is set, only RA1 and RB1 must be illuminated, the delay called, and then
; lit, and the delay called
MOVLW 0X04 ; This will light the green lights only
MOVWF PORTA
MOVLW 0X02
MOVWF PORTB
CALL DELAY
MOVLW 0X09 ; This will light the red ights only
MOVWF PORTA
MOVLW 0X00
MOVWF PORTB
CALL DELAY
RETURN
YELLOWLIGHTS
; If switch 3 is set,RA2, RB0, RB2, RB3 must be turned on, the delay called
; and then RA0 and RA1 turned on, and the delay called again.
MOVLW 0X02 ; This will light the yellow lights only
MOVWF PORTA
MOVLW 0X0D
MOVWF PORTB
CALL DELAY
MOVLW 0X09 ; This will light the red lights only
MOVWF PORTA
MOVLW 0X00
MOVWF PORTB
CALL DELAY
RETURN ; Return to the top of the switch test loop
DELAY
; This subroutine is a fixed delay loop. It is 2,393,421 clock cycles long, for
; a wait time of .4799 seconds with a 20 MHZ resonator.
CLRF COUNT1
CLRF COUNT2
CLRF COUNT3
MOVLW 0X7E ; (1)
MOVWF COUNT3 ; (1)
LOOPOUT
MOVLW 0X4F ; (1)
MOVWF COUNT2 ; (1)
LOOPMID
MOVLW 0X4F ; (1)
MOVWF COUNT1 ; (1)
LOOPIN
DECFSZ COUNT1,F ; (1 of 2)
GOTO LOOPIN ; (2)
; This will be executed 29 times
DECFSZ COUNT2,F ; (1 of 2)
GOTO LOOPMID ; (2)
; This loop will be executed 29 times
DECFSZ COUNT3,F ; (1 of 2)
GOTO LOOPOUT ; (2)
; This loop will be executed 126 times
RETURN ; (2)
END
My Attempt at adding the desired 5 second delay (probably royally screwed it up!):
Code:
#include <GENERAL.H> ;This is the header file
COUNT1 EQU 0X20 ; Counter for the inner loop
COUNT2 EQU 0X21 ; Counter for the middle loop
COUNT3 EQU 0X22 ; Counter for the outer loop
__CONFIG 0X3FF6 ;This is the control bits for CONFIG register
ORG 0X0000 ;RESET or WDT reset vector
GOTO START
ORG 0X0004 ;Regular INT vector
;This is the area where your interrupt service routine goes
RETFIE
START ;The starting place of the user codes
; The I/O must be set up. Pins 7,8,9,10 (PORTB) and 17,18,1,2 (PORTA)
; All other pins are inputs. This allows both port latches to use the same literal
CLRF PORTA ; Ensure both port latches are all 0 before
CLRF PORTB ; setting up I/O
BSF STATUS,RP0 ; Shift to bank 1 to change TRIS registers
MOVLW 0XF0 ; TRISA and TRISB both use F0 to have pins 0 - 3
MOVWF TRISA ; as outputs
MOVWF TRISB
MOVLW 0XFE
MOVWF OPTION_REG ; The prescales needs to be set to 04 for the
; watchdog timer to time out 1.15 seconds
BCF STATUS,RP0 ; Shift to bank 0 for normal operation
MOVLW 0X0F ; This will illuminate all lights
MOVWF PORTA ; when it is loaded in both ports
MOVWF PORTB
CALL DELAY5S ; Provides a 5 second delay
CLRF PORTA ; This will extenguish all lights
CLRF PORTB ; when it is loaded in both ports
CALL DELAY5S ; Provides a 5 second delay
SWTEST
CLRWDT
BTFSC PORTB,RB5 ; This is the switch for all LEDs being lit
CALL ALLIGHTS ; (Switch 3)
CLRWDT
BTFSC PORTB,RB6 ; This is the switch for red LEDs beig lit
CALL GREENLIGHTS ; (Switch 2)
CLRWDT
BTFSC PORTB,RB7 ; This is the switch for the yellow LEDs being lit
CALL YELLOWLIGHTS ; (Switch 1)
MOVLW 0X00 ; This will extenguish all lights
MOVWF PORTA ; when it is loaded in both ports
MOVWF PORTB
GOTO SWTEST ; Return to the top of the switch test loop
ALLIGHTS
MOVLW 0X0F ; This will illuminate all lights on PORTA
MOVWF PORTA
MOVLW 0X00 ; and extenguish all on PORTB
MOVWF PORTB
CALL DELAY
MOVLW 0X00 ; This will extenguish all lights on PORTA
MOVWF PORTA
MOVLW 0X0F ; and illuminate all lights on PORTB
MOVWF PORTB
CALL DELAY
RETURN ; Return to the top of the switch test loop
GREENLIGHTS
; If switch 2 is set, only RA1 and RB1 must be illuminated, the delay called, and then
; lit, and the delay called
MOVLW 0X04 ; This will light the green lights only
MOVWF PORTA
MOVLW 0X02
MOVWF PORTB
CALL DELAY
MOVLW 0X09 ; This will light the red ights only
MOVWF PORTA
MOVLW 0X00
MOVWF PORTB
CALL DELAY
RETURN
YELLOWLIGHTS
; If switch 3 is set,RA2, RB0, RB2, RB3 must be turned on, the delay called
; and then RA0 and RA1 turned on, and the delay called again.
MOVLW 0X02 ; This will light the yellow lights only
MOVWF PORTA
MOVLW 0X0D
MOVWF PORTB
CALL DELAY
MOVLW 0X09 ; This will light the red lights only
MOVWF PORTA
MOVLW 0X00
MOVWF PORTB
CALL DELAY
RETURN ; Return to the top of the switch test loop
DELAY
; This subroutine is a fixed delay loop. It is 2,393,421 clock cycles long, for
; a wait time of .4799 seconds with a 20 MHZ resonator.
CLRF COUNT1
CLRF COUNT2
CLRF COUNT3
MOVLW 0X7E ; (1)
MOVWF COUNT3 ; (1)
LOOPOUT
MOVLW 0X4F ; (1)
MOVWF COUNT2 ; (1)
LOOPMID
MOVLW 0X4F ; (1)
MOVWF COUNT1 ; (1)
LOOPIN
DECFSZ COUNT1,F ; (1 of 2)
GOTO LOOPIN ; (2)
; This will be executed 29 times
DECFSZ COUNT2,F ; (1 of 2)
GOTO LOOPMID ; (2)
; This loop will be executed 29 times
DECFSZ COUNT3,F ; (1 of 2)
GOTO LOOPOUT ; (2)
; This loop will be executed 126 times
RETURN ; (2)
DELAY5S
CLRWDT
MOVLW 0XE3
MOVWF COUNT1
MOVLW 0X7F
MOVWF COUNT2
MOVLW 0X37
MOVWF COUNT3
DELAY5S_0
CLRWDT
DECFSZ COUNT1, F
GOTO next1
DECFSZ COUNT2, F
next1
CLRWDT
GOTO next2
DECFSZ COUNT3, F
next2
CLRWDT
GOTO DELAY5S_0
RETURN
END