I'm trying to learn the assembler to program PICs. I'm doing alright, largely learning off of Nigel's tutorials.
I wrote a some-what complicated bit of code and it didn't work. So I keep trouble shooting it until I get down to really basic stuff ... and that won't even work.
Someone, please tell me why even this insanely simple bit of code won't work.
tone equ 0x31
sLoop
movlw 0xff
movwf tone
movlw tone ; <<<<<<
movwf PORTA
goto sLoop
I'm just trying to put 0xff into the register tone and then have tone put into PORTA.
If I replace tone with 0xff on the line with the arrows, it works fine. For some reason it won't let me load a value into tone and then use it later.
As 'csaba911' has pointed out, you're using the totally wrong instruction, MOVLW means 'Move Literal' - a constant value, specified on the rest of the line. 'Tone' is just an equate name, and will have a numeric value (the address of the GPR it points to), this value will be copied to the W register.
What you need is MOVF - 'Move File', as already pointed out 'MOVF Tone, W' will move the contents of the GPR pointed to by Tone into the W register.
What I'd like it do is ... count up the number of switches that are on (grounding the pin) and if 0x0? number of switches are on, then put on the LEDs. So if it were 0x01 it would require 1 switch to be on.
What happens in reality with this code, is if there are 1 or 2 switches on ... the LEDs will be on. 3-5 and the lights are off ... doesn't make sense to me.
BTFSC and BTFSS check a single bit for being high or low, this isn't what you want to happen!. To check for a particular value in a register you need to either use SUB or XOR on the two values, and check the zero flag to see if they were equal.
BTFSC and BTFSS are what I want. I want to see how many switches are activated ... so if there are 4, slit will have a value of 4. If 2, then slit will have a value of 3. It doesn't matter which switches are activated, I just need to know how many there are.
BTFSC and BTFSS are what I want. I want to see how many switches are activated ... so if there are 4, slit will have a value of 4. If 2, then slit will have a value of 3. It doesn't matter which switches are activated, I just need to know how many there are.
The count procedure should go through the 5 switches and see how many are on (grounded). Say 3 are on, slit will have a value of 0x03.
Now how do I say if slit = 0x03 then call SuperLoop ?? Because like Nigel mentioned, btfss and btfsc only test a single pin and not actually the register value.
Nigel mentioned something about SUB or XOR? Do I have to have registers pre-filled with 0x01, 0x02, 0x03... then compare the values to slit ??
Any guidance would be greatly appreciated.
Nigel ... I think I misunderstood what you were originally saying. Sorry bout that.
For future reference ... anyone doing PIC programming, here is how you do an IF REGISTER = ??? THEN ...
In this case ... if slit = ?? then ...
Quick explanation:
The value you are checking is loaded into W and subtracted from your register. If the result is zero, then the Z bit of the status flag becomes '1'. Then we can tell it to call a subroutine. If it isn't equal to the value we just checked, the old value is restored (by adding W to it) and we continue to check it against another value.
You have a register called Slit, which contains the number of switches that are turned ON - you want to check if either the value equals a certain number, or is greater than a certain number.
Try looking at . These 8 bit examples use ADDLW rather than SUBLW, simply because 12 bit PIC's don't have SUBLW, so they use complement subtraction.
If you check my tutorials, various ones do similar comparisons, check the IR receiver ones - these check the incoming IR code and turn on the respective LED's.
One thing I didn't think to mention earlier, you could also do this with a simple 'jump table' - the table would have five entries, each jumping to the routine required for that value.