Hi there
I realise there is more than this post on toggling with an XOR operation on the 16F690 but I had read these, tried for days and need help...
I'm using MPLAB-X with a PicKit 2 and it's demoboard [04-01831 Rev2] to turn on and off the left LED (DS1) which is connected to the RC0 pin.
Flashing the LED works well if I move 0 or 1 to the RC0, it just doesn't with the XOR.
I've read the datasheet and cannot figure out why it's not working?
Can anyone help?
I'm guessing it's my setup somewhere but it could be anything...
My code is as follows:
I realise there is more than this post on toggling with an XOR operation on the 16F690 but I had read these, tried for days and need help...
I'm using MPLAB-X with a PicKit 2 and it's demoboard [04-01831 Rev2] to turn on and off the left LED (DS1) which is connected to the RC0 pin.
Flashing the LED works well if I move 0 or 1 to the RC0, it just doesn't with the XOR.
I've read the datasheet and cannot figure out why it's not working?
Can anyone help?
I'm guessing it's my setup somewhere but it could be anything...
My code is as follows:
Code:
ORG 0x00 ;This is where we come on power up and reset
;*****Set up the Constants********************
STATUS equ 0x03 ;Address of STATUS register
TRISC equ 0x87 ;Address of TRISC register (bank 1)
ANSEL equ 0x11E ;Address of Anaglogue setup (bank 2)
ANSELH equ 0x11F ;Address of Anaglogue setup (bank 2)
PORTC equ 0x07 ;Address of Port C (bank 0 or 3)
RP0 equ 0x05 ;Bit location of RP0
RP1 equ 0x06 ;and RP1.
COUNT equ 0x20 ;Counter for our delay loop
TIME equ 0xff ;Variable for the delay loop
;****Set up the port***************************
bcf STATUS,5 ;Ensure Bank 0 with
bcf STATUS,6 ;RP0 & RP1 = 0
clrf PORTC ;Make all PortC outputs low
bsf STATUS,5 ;Switch to Bank 1 with
bcf STATUS,6 ;RP0 & RP1 = 1 (bit 5 set)
clrf TRISC ;Set all of PortC to outputs
bcf STATUS,5 ;Switch to Bank 2 with
bsf STATUS,6 ;RP0 & RP1 = 2 (bit 6 set)
clrf ANSEL ;Ensure PortC is digital
clrf ANSELH ;Ensure PortC is digital
bcf STATUS,5 ;Switch to Bank 0 again
bcf STATUS,6 ;RP0 & RP1 = 1 (bit 5 set)
;****Setting for toggling the RC0 (LED)*************
movlw 0x01 ;Set up our w register with 01h
;****Toggle the LED ***************************
start xorwf PORTC,1 ;toggle RC0, store the result in PortC
;****Add a delay*******************************
call delay
;****Now clear the WDT & go back to the start of the program****
clrwdt ;This simply resets the WDT
goto start ;go back to Start and turn LED on again
;****Subroutine to give a delay between bit movements******
delay
movlw TIME ; Get the delay time,
movwf COUNT ; and put it into a variable
loop1
decfsz COUNT,1 ;Decrement 1 from the delay time until it
goto loop1 ;reaches zero.
return
;****End of subroutine**************
;****End of the program*************************
end ;Needed by some compilers, and also
;just in case we miss the goto instruction.