what have I got wrong

edlentz

Member
I used the manual example and the output doesn't change.  Am I missiing something?  Here's my code
 

START
TSTEQ OP1[1000] 1
SET OP1 0
TSTEQ OP2[1000] 1
SET OP2 0
TSTNE IP4[50] VAR1
CALLSUB BTN_CHG
TSTEQ IP4[1000] 0
CALLSUB BTN_DONE
CALLSUB LITES
END

BTN_CHG:
XOR VAR1 1 VAR1
TSTEQ VAR1 1
INC VAR2
RET

BTN_DONE:
TSTEQ VAR2 1
SET OP1 1
TSTEQ VAR2 2
SET OP2 1
SET VAR2 0
RET

LITES:
TSTGE CH 20 RAM2
NOP
TSTLE CH 21 RAM3
NOP
OR RAM2 RAM3 OP6
RET

The output 6 for the lites is the one I am trying to get working.  The output initially went 1 but never changed state.
 
Suggestions much appreciated
 
Thanks
 
 
I won't pretend to understand your code. I assume you are only testing various opcodes for understanding so far.
 
Let's look at you last subroutine.
 

LITES:
TSTGE CH 20 RAM2
NOP
TSTLE CH 21 RAM3
NOP
OR RAM2 RAM3 OP6
RET

You appear to be testing if the current hour (CH)
   is greater than or equal to 20
      OR
   less than or equal to 21
 
It always will be true. Can you think of a time where at least of the logic lines will NOT be true?
I would guess you intended the conditions reversed.
 
I have to admit I am a noob on programming.  I literally took the code for that subroutine out of the manual.  No wonder it is always true.  I want to be able to control some lights with this.  I guess I need to study some more.
 
Thanks
 
You will do OK.
 
Find a way to test results with some kid of indicator. The LED by the Ethernet connector works fine if the WC8 board is in full view.
 
Use your board as a testing grounds to learn the opcodes by experimenting with them.
Turn the LED off at the beginning of your code and inject a line to turn the LED on to prove you got there.
Better yet right yourself a subroutine to turn the LED on, delay for say 1000msec and the turn it off and RETurn. Now when you want to prove a line is being executed or your conditional logic worked insert a line temporarily like this:
 
   CALLSUB LED_FLASH
 
Print out the user guide Opcode table and the variable list. Read down the list and any opcodes you are not sure about set up a little test jig using your indicator routine to test out results.
 
Pretend you are the programme counter and walk through you code doing exactly what the real CPU would do, doing each test and jump with different scenarios. Maybe keep a piece of paper or whiteboard with various memory locations boxes marked on it that are involved at the time and keep current values stored in them written in the boxes, to help your simulation.
 
There you just saved yourself over $1000 for a weekend course on programming! Careful. This may eat your life. It's an obsession!
 
Have fun!!!
 
Here is a little subroutine to use as a tester line.
 
Try it out and try to call it with a subroutine call like this:
 
START
LOOP:
     CALLSUB FLASH
     DELAY 2000
     GOTO LOOP
END
 
 
Under that insert this subroutine. Keep the subroutine there for later testing use.
Note you can cut and paste the programs from and to a .txt document in Windows so you can patch tgether favourites and paste them into your WC8 editor screen.
Code:
FLASH:
	SET RAM2 20  
FLASH2:
	SETLED 0   
	DELAY 50   
	SETLED 1   
	DELAY 50   
	DEC RAM2   
	BNZ  FLASH2  
	SETLED 0  
        RET
 
Larry,you have callsub flash and in the call sub flash: you does not have ret at the end so it will continue to flast2: ?
 
Yes. What CAI said.

If I give your directions and none of the houses have numbers which house will you pick?

Labels can be placed anywhere in programs. The can be landing places for CALLSUB, GOTO BZ, BNZ or they can label the name of a place so the programmer can remember what it is for or what is it's function.


RET tells the CPU to go back to the next instruction after the instruction that sent you here.
 
Back
Top