I have successfuly programmed LED flashing programme with those normal codes (MOV and all that..) now, I'm trying this XOR one but, don't understand why this is not working.
Code:
list p=16f690
#include<p16f690.inc>
#define LED PORTC,0;Define pin 0 of port c as LED
__CONFIG _MCLRE_ON & _CP_OFF & _WDT_OFF & _INTRC_OSC_NOCLKOUT
ERRORLEVEL -302
TEMP_VAR UDATA
temp RES 1
delay1 RES 1;reserves 1 byte for delay1
delay2 RES 1;reserves 1 byte for delay2
;*******************************************************************
Main:;Main programme begains
CODE 0x05; Start address at 0x05
Setpins:; Select output and input
bsf STATUS,RP0 ;Switch to bank 1
movlw b'11110';MOVe 11110 to W
movwf TRISC ;set pin 0 of PORT C as output
bcf STATUS,RP0 ;Switch back to bank 0
movlw b'00001';MOVe 00001 to W
Start:
xorwf LED
call Loop
call Loop
goto Start
Loop:
decfsz delay1,1
goto Loop
decfsz delay2,1
goto Loop
return
END
I tried what Gayan Soyza suggested but, that is not working and I am already using Nigel's tutorials they are very helpful but, I can't see any special help on XOR, please help me, I'm on this for hours, trying to blink just an LED with XOR code !, please point out where is the mistake I'm just a layman!
but then you try to toggle the LED using this instruction in the main code
Code:
xorwf LED
which if you substitute your definition for 'LED' is
Code:
xorwf PORTC,0
The 0 here isn't the bit you want to toggle it's the destination for the result of the XOR operation. The 0 tells it to put the result in W so your code never writes anything back to PORTC.
Also, you need to turn off analogue mode and set the port to digital I/O. See datasheet
Code:
Setpins:; Select output and input
bsf STATUS,RP0 ;Switch to bank 1
movlw b'11110' ;MOVe 11110 to W
movwf TRISC ;set pin 0 of PORT C as output
bcf STATUS, RP0 ; Switch to bank 2
bsf STATUS, RP1
bcf ANSEL, ANS4 ; Set PORTC, 0 to digital mode
bcf STATUS,RP0 ;Switch back to bank 0
bcf STATUS,RP1
movlw b'00001' ;MOVe 00001 to W
Start:
xorwf PORTC,F
call Loop
call Loop
goto Start
Loop:
decfsz delay1,1
goto Loop
decfsz delay2,1
goto Loop
return
Hmm....... that works , but what I did'nt understand is that why it is:
bcf ANSEL,ANS4
and why not,:
bcf ANSEL,ANS0
After all the LED is connected at pin 0 of port c and not at pin 4
I mean the data sheet says :
Setting the ANSx bit of a corresponding pin will
cause all digital reads of that pin to return ‘0’ and also
permit analog functions of that pin to operate correctly.
Please explain as easily as possible, Thank you for your help !!
Read the data sheet again. The Analogue bit numbers don't correspond to the same port bit numbers; how could they since you have PortA,0 and PortC,0 and they're both analogue inputs.
I'm sorry but I still don't get that, I know this may sound stupid to you but I'm working with .ASM since last few days only, I have checked all registers associated with port c (that is given in table format in datasheet) and I found that ANS4 is corresponds to bit 4 and bit 4 also corresponds to pin 4 of port c, I know you are trying to tell me something quite different but, if you can make it more simpler than I'll be very grateful !
I'm sorry but I still don't get that, I know this may sound stupid to you but I'm working with .ASM since last few days only, I have checked all registers associated with port c (that is given in table format in datasheet) and I found that ANS4 is corresponds to bit 4 and bit 4 also corresponds to pin 4 of port c, I know you are trying to tell me something quite different but, if you can make it more simpler than I'll be very grateful !
Oh! that was very easy, right before my eyes, it is also given in table 1.5, Thank you very much and sorry to bother you about this, now I think that it is out of quastion that why Microchip built it like this (AN4 fo RC0) as it is related to archtructure stuff, is'nt it ?, we just have to accept as it is.