Hi Guys,
I'm kind of new to the whole programming of embedded systems, and circuit design, but I'm trying
I've started with the basic, make LEDs flash etc, all working fine, now I'm trying to check an input bit, but having problems. The Code is as follows
Basically, in the subroutine which turns the LED on, b'00000001 is loaded into the W register, then RA0 is checked,in this version to see if the bit is clear, if it is set, the next line b'00000011' is skipped .... Therefore, if it is clear I should get 2 leds, if it is set, only one.
I'm using a PIC 16F627 on the Velleman VM111 experiment/programming board. On this board, the LEDS are wired to RB0-RB5, and four switches to RA0-RA3 ..... My problem is that I only get one LED flashing in this version. If I change the bit check command to BTFSS instead of BTFSC, I get 2 LEDs, but pressing buttons does nothing ..... I'm probably doing something stupid, but I can't sleep until it stops taunting me!!!
Does anyone have any insight into where I'm going wrong?? ... Feel free to make fun of coding style, criticism is the only way I'll learn. I know I should have used the include file instead of my own hardcoded constants, I'll sort that soon
Cheers everyone
I'm kind of new to the whole programming of embedded systems, and circuit design, but I'm trying
I've started with the basic, make LEDs flash etc, all working fine, now I'm trying to check an input bit, but having problems. The Code is as follows
Rich (BB code):
;==========================================================================
;
; Configuration Bits
;
;==========================================================================
_BODEN_ON EQU 3FFFh
_BODEN_OFF EQU 3FBFh
_CP_ALL EQU 03FFh
_CP_75 EQU 17FFh
_CP_50 EQU 2BFFh
_CP_OFF EQU 3FFFh
_DATA_CP_ON EQU 3EFFh
_DATA_CP_OFF EQU 3FFFh
_PWRTE_OFF EQU 3FFFh
_PWRTE_ON EQU 3FF7h
_WDT_ON EQU 3FFFh
_WDT_OFF EQU 3FFBh
_LVP_ON EQU 3FFFh
_LVP_OFF EQU 3F7Fh
_MCLRE_ON EQU 3FFFh
_MCLRE_OFF EQU 3FDFh
_ER_OSC_CLKOUT EQU 3FFFh
_ER_OSC_NOCLKOUT EQU 3FFEh
_INTRC_OSC_CLKOUT EQU 3FFDh
_INTRC_OSC_NOCLKOUT EQU 3FFCh
_EXTCLK_OSC EQU 3FEFh
_LP_OSC EQU 3FECh
_XT_OSC EQU 3FEDh
_HS_OSC EQU 3FEEh
__CONFIG _BODEN_ON & _CP_OFF & _DATA_CP_OFF & _PWRTE_ON & _WDT_OFF & _LVP_OFF & _MCLRE_ON & _INTRC_OSC_NOCLKOUT
;==========================================================================
;
; Set Up Constants
;
;==========================================================================
STATUS EQU 03h ; Address of the status register
TRISA EQU 85h ; Address of the TRISA register
TRISB EQU 86h ; Address of the TRISB register
PORTA EQU 05h ; Address of the Port A
PORTB EQU 06h ; Address of the Port B
COUNT1 EQU 20h ; Address of the first general purpose register
COUNT2 EQU 21h ; Address of the second genral purpose register
;==========================================================================
;
; Start Of Program
;
;==========================================================================
;*****Set Up the port*****;
BSF STATUS, 5 ; Set bit 5 of the status register - move to bank 1
MOVLW b'00001111' ; Move 00001111 into the W register
MOVWF TRISA ; Move the value is the W register to TRISA register RA0-RA3 as inputs
MOVLW b'00000000' ; Move 00000000 into the W register
MOVWF TRISB ; Move the value is the W register to TRISA register RB0-RB7 outputs
BCF STATUS, 5 ; Clear bit 5 of the status register - move back to bank 0
;*****Turn On The LED*****;
Start CALL LED_On ; Call LED on subroutine
CALL Delay ; Call delay subroutine
CALL LED_Off ; Call LED Off Subroutine
CALL Delay ; Call delay subroutine
;****Now go back to the start of the program****
GOTO Start ;go back to Start and turn LED on again
;****Subroutines****
;-----Subroutine To Turn LED On-----
LED_On MOVLW b'00000001' ; Turn the LED on by first putting
BTFSC PORTA,0 ; If RA0 is set, skip next line
MOVLW b'00000011' ; Turn the LED on by first putting
MOVWF PORTB ; it into the w register and then on the port
return
;-----End Of Subroutine-----
;-----Subroutine To Turn LED OFF-----
LED_Off MOVLW b'00000000' ; Turn the LED off by first putting
MOVWF PORTB ; it into the w register and then on the port
return
;-----End Of Subroutine-----
;-----Subroutine To Turn Incur Delay-----
Delay MOVLW b'11111111' ; Moves 11111111 into W register
MOVWF COUNT1 ; Moves the value of W into COUNT1
MOVWF COUNT2 ; Moves the value of W into COUNT2
Loop DECFSZ COUNT1,1
GOTO Loop
DECFSZ COUNT2,1
GOTO Loop
return
;-----End Of Subroutine-----
;****End of the subroutines****
;****End of the program****
end ;Needed by some compilers, and also just in case we miss the goto instruction.
I'm using a PIC 16F627 on the Velleman VM111 experiment/programming board. On this board, the LEDS are wired to RB0-RB5, and four switches to RA0-RA3 ..... My problem is that I only get one LED flashing in this version. If I change the bit check command to BTFSS instead of BTFSC, I get 2 LEDs, but pressing buttons does nothing ..... I'm probably doing something stupid, but I can't sleep until it stops taunting me!!!
Does anyone have any insight into where I'm going wrong?? ... Feel free to make fun of coding style, criticism is the only way I'll learn. I know I should have used the include file instead of my own hardcoded constants, I'll sort that soon
Cheers everyone