Shop OBEX P1 Docs P2 Docs Learn Events
In , out and cmp — Parallax Forums

In , out and cmp

Brian_BBrian_B Posts: 842
edited 2007-06-01 09:17 in Propeller 1
I'm trying to read 3 switches on pins 0,1,2 and display results on pins 4,5,6· . any suggestions on my code ?

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Thank's Brian


www.truckwiz.com

·"Imagination is more important than knowledge..." ·· Albert Einstein

http://www.diycalculator.com/subroutines.shtml· My favorite website ( Bet you can't guess why)

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2007-05-31 02:13
    Your "cmp" use a literal source (#test1) which compares against the address of test1. Use "cmp temp,test1" to compare against the contents of test1.
  • Brian_BBrian_B Posts: 842
    edited 2007-05-31 02:23
    Mike,

    ·Changed it and it's still not working.





    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Thank's Brian


    www.truckwiz.com

    ·"Imagination is more important than knowledge..." ·· Albert Einstein

    http://www.diycalculator.com/subroutines.shtml· My favorite website ( Bet you can't guess why)
  • Mike GreenMike Green Posts: 23,101
    edited 2007-05-31 02:55
    How do you have the switches and LEDs connected?

    The way the code is written, one and only one switch (I/O pins 0-2) at a time should be connected to Vdd and the others have a pulldown.

    The LEDs (I/O pins 3-5) should be connected from an I/O pin through a series resistor to ground. 3 LEDs on = pin 0 on, 2 LEDs (pins 3-4) on = pin 1 on, 1 LED (pin 3) on = pin2 on
  • Brian_BBrian_B Posts: 842
    edited 2007-05-31 03:08
    Mike,
    This program works fine for reading a pin and displaying results.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Thank's Brian


    www.truckwiz.com

    ·"Imagination is more important than knowledge..." ·· Albert Einstein

    http://www.diycalculator.com/subroutines.shtml· My favorite website ( Bet you can't guess why)
  • JamesxJamesx Posts: 132
    edited 2007-05-31 03:44
    Brian:

    Clever code. Very nice!

    Jim C
  • Brian_BBrian_B Posts: 842
    edited 2007-05-31 11:28
    Jim c,

    ·Thanks



    Mike ,

    ·Heres how my LEDS and pushbottons are hooked up , still trying to get the CMP code to work. Also I am trying to light up 1 led ,2 leds and 3 leds .


    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Thank's Brian


    www.truckwiz.com

    ·"Imagination is more important than knowledge..." ·· Albert Einstein

    http://www.diycalculator.com/subroutines.shtml· My favorite website ( Bet you can't guess why)


    Post Edited (Brian Beckius) : 5/31/2007 11:56:47 AM GMT
  • Graham StablerGraham Stabler Posts: 2,507
    edited 2007-05-31 12:59
    You probably need to mask test before you do the compare because if any of the other propeller pins have a one on them then time and test1 will not equal.

    
    :loop   mov   time,ina  
              and    time,mask            'mask
              cmp  time,test1        wz
    if_z     jmp   #:ans1
    
    mask    long  %000111 
    
    
    
  • Brian_BBrian_B Posts: 842
    edited 2007-05-31 15:52
    Works perfect , thanks Graham

    ·Heres another chunk of code thats giving me grief· , this one is to suppose to inca djnz·the 6 leds and then start over .·But instead it·turns all leds on and waits 10 minutes to start . Is this a mask issue also ?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Thank's Brian


    www.truckwiz.com

    ·"Imagination is more important than knowledge..." ·· Albert Einstein

    http://www.diycalculator.com/subroutines.shtml· My favorite website ( Bet you can't guess why)


    Post Edited (Brian Beckius) : 6/1/2007 2:33:23 AM GMT
  • Graham StablerGraham Stabler Posts: 2,507
    edited 2007-05-31 19:07
    Well I don't know what inca is but I think you will find the problem is that you are adding two small an amount to time before the initial waitcnt.

    So it loads outa with 111111000 and then gets the waitcnt where it misses the time and then sits until it comes around again. So you need to add delay to time not 9.

    And rather than doing

    mov outa,testpin

    you might consider doing

    or outa, testpin

    That way if you are doing something with any of the other pins in a different part of the code you won't effect them because remember 111111000 is really:

    0000000000000000000000111111000

    That may be the point you are missing and why you are not sure when to use a mask.

    Graham
  • Brian_BBrian_B Posts: 842
    edited 2007-05-31 20:00
    Graham ,
    I meant djnz not inca . Changed 9 to 255 , works great

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Thank's Brian


    www.truckwiz.com

    ·"Imagination is more important than knowledge..." ·· Albert Einstein

    http://www.diycalculator.com/subroutines.shtml· My favorite website ( Bet you can't guess why)
  • Graham StablerGraham Stabler Posts: 2,507
    edited 2007-05-31 20:19
    You must have ancient south American societies on your mind [noparse]:)[/noparse]
  • Brian_BBrian_B Posts: 842
    edited 2007-06-01 01:10
    Graham,

    Just so I have my brain fully wraped around waitcnt.

    · CLOCK

    12_000_012

    12_000_013······' Mov time,cnt

    12_000_014······ 'add· time,#9

    12_000_015······ 1

    12_000_016······ 2

    12_000_019······ 3

    12_000_020······ 4.....8

    12_000_025···· 9·······' stop what your doing and wait 6_000_000 clock ticks

    18_000_025······ ' quit sitting around and get moving

    delay···· long····· 6_000_000

    So by adding 9 to the time ,you need to make sure that the instructions your trying to exacute don't take longer than 9 clock ticks ?




    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Thank's Brian


    www.truckwiz.com

    ·"Imagination is more important than knowledge..." ·· Albert Einstein

    http://www.diycalculator.com/subroutines.shtml· My favorite website ( Bet you can't guess why)


    Post Edited (Brian Beckius) : 6/1/2007 1:30:32 AM GMT
  • Graham StablerGraham Stabler Posts: 2,507
    edited 2007-06-01 01:58
    Basically yes remembering that each instruction takes 4 clock cycles so you would only have time for 2 and a bit instructions.

    Graham
  • Brian_BBrian_B Posts: 842
    edited 2007-06-01 03:56
    Cool !!!· (so 255 was a little over kill ?)

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Thank's Brian


    www.truckwiz.com

    ·"Imagination is more important than knowledge..." ·· Albert Einstein

    http://www.diycalculator.com/subroutines.shtml· My favorite website ( Bet you can't guess why)
  • Graham StablerGraham Stabler Posts: 2,507
    edited 2007-06-01 09:17
    Probably and a randomly precise value to boot [noparse]:)[/noparse]
Sign In or Register to comment.