Shop OBEX P1 Docs P2 Docs Learn Events
Post "Blink an LED" program in your favorite langauge. — Parallax Forums

Post "Blink an LED" program in your favorite langauge.

BeanBean Posts: 8,129
edited 2010-05-16 22:20 in Propeller 1
Here is the idea:
· Post a program that blinks the LED on pin 16 of the Propeller demo board at 1Hz.

· Please post the absolute simplest program possible.

· Let's see how many languages we can post, this will let propellers user see a smidge of each language available.

· Here is spin:

' Spin
CON
  _ClkMode = RCFAST             ' Internal 12MHz                                   
  LED = 16                      ' LED pin is 16
 
PUB Program
   dira[noparse][[/noparse]LED]~~                  ' Make pin an output
   REPEAT                       ' Repeat forever
     outa[noparse][[/noparse]LED]~~                ' Make pin high
     waitcnt (cnt+6_000_000)   ' Wait 500mSec
     outa[noparse][[/noparse]LED]~                 ' Make pin low
     waitcnt (cnt+6_000_000)   ' Wait 500mSec


· Here is PASM:


' PASM
CON
  _ClkMode = RCFAST        ' Internal 12MHz                                       

PUB Program
  CogInit(0, @Init, 0)     ' Start PASM code                      
                                                            
DAT                                                         
                  org           0                           
Init                                                        
                  mov           dira,LED                      ' Make pin an output
                  mov           wait,cnt                      ' Setup for 500mSec wait
                  add           wait,_6_000_000
Again
                  or            outa,LED                      ' Make pin high
                  waitcnt       wait,_6_000_000              ' Wait 500mSec
                  andn          outa,LED                      ' Make pin low
                  waitcnt       wait,_6_000_000              ' Wait 500mSec
                  jmp           #Again                        ' Repeat forever

 
LED               LONG %00000000_00000001_00000000_00000000
_6_000_000        LONG 6_000_000
wait              RES 1



· And PropBASIC:

' PropBASIC
DEVICE P8X32A          ' Defaults to internal 12MHz
 
LED    PIN 16 OUTPUT   ' LED is pin 16 and make it an output
 
PROGRAM Start          ' Start execution at label Start
 
Start:
  HIGH LED             ' Make pin high
  PAUSE 500            ' Pause 500mSec
  LOW LED              ' Make pin low
  PAUSE 500            ' Pause 500mSec
  GOTO Start           ' Repeat forever

 


Bean


▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Use BASIC on the Propeller with the speed of assembly language.

PropBASIC thread http://forums.parallax.com/showthread.php?p=867134

March 2010 Nuts and Volts article·http://www.parallax.com/Portals/0/Downloads/docs/cols/nv/prop/col/nvp5.pdf


Post Edited (Bean) : 2/15/2010 7:27:49 PM GMT
«1

Comments

  • kwinnkwinn Posts: 8,697
    edited 2010-02-15 15:32
    How about this for PASM.
    ' PASM
    CON
      _ClkMode = RCFAST        ' Internal 20MHz                                      
    
    PUB Program
      CogInit(0, @Init, 0)     ' Start PASM code                     
                                                               
    DAT                                                        
                      org           0                          
    Init                                                       
                      mov           dira,LED                      ' Make pin an output
                      mov           wait,cnt                      ' Setup for 500mSec wait
                      add           wait,_10_000_000
    Again
                      xor           outa,LED                      ' Make pin high
                      waitcnt       wait,_10_000_000              ' Wait 500mSec
                      jmp           #Again                        ' Repeat forever
     
    LED               LONG %00000000_00000001_00000000_00000000
    _10_000_000       LONG 10_000_000
    wait              RES 1
    
    
  • kwinnkwinn Posts: 8,697
    edited 2010-02-15 15:37
    And the same for Spin.
    ' Spin
    CON
      _ClkMode = RCFAST             ' Internal 20MHz                                  
      LED = 16                      ' LED pin is 16
     
    PUB Program
       dira[noparse][[/noparse]LED]~~                  ' Make pin an output
       REPEAT                       ' Repeat forever
         !outa[noparse][[/noparse]LED]                 ' Make pin high
         waitcnt (cnt+10_000_000)   ' Wait 500mSec
    
    
  • Brian RileyBrian Riley Posts: 626
    edited 2010-02-15 15:55
    ' PropBASIC
    '
    ' Bean's BlinkLED Challenge - B Riley, Underhill Center, VT
    '
    DEVICE P8X32A          ' Defaults to internal 20MHz
    
    LED    PIN 16 LOW      ' LED is pin 16 and make it an output
    
    PROGRAM Start          ' Start execution at label Start
    
    Start:
      TOGGLE LED             ' if its HIGH make it LOW, etc
      PAUSE 500                ' Pause 500mSec
      GOTO Start               ' Repeat forever
    
    
    



    even tighter yet ... cheers ... BBR

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    cheers ... brian riley, n1bq, underhill center, vermont
    The Shoppe at Wulfden
    www.wulfden.org/TheShoppe/
  • AJMAJM Posts: 171
    edited 2010-02-15 16:44
    You can probably simplify spin even more to:

    ' Spin
    
    PUB Program
       dira[noparse][[/noparse]16]~~                   ' Make pin an output
       REPEAT                       ' Repeat forever
         !outa[noparse][[/noparse]16]                  ' Make pin high
         waitcnt (clkfreq/2 + cnt)  ' Wait 500mSec
    
    
  • HumanoidoHumanoido Posts: 5,770
    edited 2010-02-15 17:11
    and this is the most simplified code:
  • kwinnkwinn Posts: 8,697
    edited 2010-02-15 17:39
    @AJM, Learn something new every day. Thought the clkmode was required.
  • Tracy AllenTracy Allen Posts: 6,666
    edited 2010-02-15 18:26
    For the record, the internal RCFAST is nominally 12 MHz, not 20 MHz.

    While not the shortest program, the cog counters are are a separately programmed entity...

    ' spin with counter A
    PUB LED1Hz
        ctra:=%0_00100_000_00000000_000000_000_010000
        '                  nco                                              pin16
        frqa:=358    '   2^32 * 1Hz /  12MHz
        dira[noparse][[/noparse]16]~~     ' pin 16 output
        repeat   ' forever
    

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Tracy Allen
    www.emesystems.com
  • HughHugh Posts: 362
    edited 2010-02-15 18:47
    In the language of Professor Stanley Unwin:

    //Remarkibold - flash an LED
    Repeatifold:
     Huffallo-dowder LED1
    Goodlibilode
    //Remarkibold - Exit
    
    

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Hugh - the thinking woman's Geoffrey Pyke.
  • BeanBean Posts: 8,129
    edited 2010-02-15 19:24
    Tracy Allen said...
    For the record, the internal RCFAST is nominally 12 MHz, not 20 MHz.

    While not the shortest program, the cog counters are are a separately programmed entity...

    ' spin with counter A
    PUB LED1Hz
        ctra:=%0_00100_000_00000000_000000_000_010000
        '                  nco                                              pin16
        frqa:=358    '   2^32 * 1Hz /  12MHz
        dira[noparse][[/noparse]16]~~     ' pin 16 output
        repeat   ' forever
    

    Tracy,
    · Oops, I got confused with the RCSLOW which is 20KHz.
    · My bad.

    Bean


    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    Use BASIC on the Propeller with the speed of assembly language.

    PropBASIC thread http://forums.parallax.com/showthread.php?p=867134

    March 2010 Nuts and Volts article·http://www.parallax.com/Portals/0/Downloads/docs/cols/nv/prop/col/nvp5.pdf
    ·
  • BeanBean Posts: 8,129
    edited 2010-02-15 19:26
    I meant simplest to understand.
    Not least amout of code.
    This is meant for newbies to get a glimps of the different languages.

    Bean.


    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    Use BASIC on the Propeller with the speed of assembly language.

    PropBASIC thread http://forums.parallax.com/showthread.php?p=867134

    March 2010 Nuts and Volts article·http://www.parallax.com/Portals/0/Downloads/docs/cols/nv/prop/col/nvp5.pdf
    ·
  • fullspecengfullspeceng Posts: 76
    edited 2010-02-15 22:50
    Why do you have two outputs for toggling an LED? That would just be bad programming as it's double the program space.

    Usually XOR is used for toggling a bit.

    In C it's:

    while(1){
    outa^=LED;
    delay();
    }
  • Brian RileyBrian Riley Posts: 626
    edited 2010-02-15 23:06
    Bean said...
    I meant simplest to understand. Not least amout of code.

    This is meant for newbies to get a glimpse of the different languages.

    Bean.

    I have been away from Propeller for a year or two. I had forgotten one of is greatest strength's ... THIS FORUM! This kind of exercise helps not just newbies ... way to go, Bean!

    That said, I recently downloaded Propeller Forth and plan to boot it up. Does anyone out there know enough about PropForth to code a BlinkLED in Forth for us to see? I would love to see that.

    cheers ... BBR

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    cheers ... brian riley, n1bq, underhill center, vermont
    The Shoppe at Wulfden
    www.wulfden.org/TheShoppe/
  • RossHRossH Posts: 5,519
    edited 2010-02-15 23:22
    Hi Bean,

    Here's one for Catalina:
    #include <catalina_cog.h>
    
    #define LED 16
    
    void main() {
       unsigned mask   = 1 << LED;
       unsigned on_off = 1 << LED;
    
       _dira(mask, mask);
       for (;;) {
          _outa(mask, on_off);
          _waitcnt(_cnt() + _clockfreq()/2);
          on_off ^= mask;
       }
    }
    



    Ross.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Catalina - a FREE C compiler for the Propeller - see Catalina
  • kuronekokuroneko Posts: 3,623
    edited 2010-02-16 00:43
    I don't think we should encourage hardwired frequency constants in PASM when it can be avoided. clkfreq should be recognised (by the user) from SPIN so let's use it.

    PUB main
    
      cognew(@init, 0)     ' Start PASM code                     
                                                               
    DAT             org     0                                  
    
    init            mov     dira, LED               ' make pin an output
                    rdlong  delay, #0               ' get clkfreq
                    shr     delay, #1               ' half a second
    
                    mov     time, cnt               ' current time
                    add     time, delay             ' first target
    
    again           waitcnt time, delay             ' delay 500ms and setup next target
                    xor     outa, LED               ' LED on/off
                    jmp     #again                  ' repeat forever
     
    LED             long    |< 16                   ' pin 16
    delay           res     1
    time            res     1
    
                    fit
    
  • HumanoidoHumanoido Posts: 5,770
    edited 2010-02-22 08:10
    We see the following:

    SPIN
    PROPASM
    PropBASIC
    C

    but no more.
    Is anyone running other languages on the Propeller chip?
    There are some to choose from here:

    http://forums.parallax.com/showthread.php?p=809630

    humanoido
  • Cluso99Cluso99 Posts: 18,069
    edited 2010-02-22 11:52
    kuroneko: Nice. It's best to use the cklfreq smile.gif

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Links to other interesting threads:

    · Home of the MultiBladeProps: TriBlade,·RamBlade,·SixBlade, website
    · Single Board Computer:·3 Propeller ICs·and a·TriBladeProp board (ZiCog Z80 Emulator)
    · Prop Tools under Development or Completed (Index)
    · Emulators: CPUs Z80 etc; Micros Altair etc;· Terminals·VT100 etc; (Index) ZiCog (Z80) , MoCog (6809)·
    · Prop OS: SphinxOS·, PropDos , PropCmd··· Search the Propeller forums·(uses advanced Google search)
    My cruising website is: ·www.bluemagic.biz·· MultiBlade Props: www.cluso.bluemagic.biz
  • Laserist1984Laserist1984 Posts: 9
    edited 2010-02-24 13:35
    Blink LED non stop
  • BradCBradC Posts: 2,601
    edited 2010-02-24 13:44
    Laserist1984 said...
    Blink LED non stop

    Context? Language? Man toggling light switch?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    You only ever need two tools in life. If it moves and it shouldn't use Duct Tape. If it does not move and it should use WD40.
  • AribaAriba Posts: 2,690
    edited 2010-02-24 20:18
    Mike Green's FemtoBasic:

    10 OUTA[noparse][[/noparse]16] = 1
    20 PAUSE 500
    30 OUTA[noparse][[/noparse]16] = 0
    40 PAUSE 500
    50 GOTO 10
    
    



    Andy
  • prof_brainoprof_braino Posts: 4,313
    edited 2010-05-07 22:50
    \ FLASH AN LED using PROPFORTH 2.5 (new version of salsanci spinforth 1.1, not propellerforth from Cliffe Biffle)
    \ load PropForth.spin into eeprom and use teraterm 1 ms per char and 1 ms per line 38400 baud worked best for me
    \ save as file and "send file" in teraterm
    \ unmodified demo board
    \ sorry but I didn't get the parenthesis comments to work so the
    \ stack notes are at the end of each line (it looks funny to me, too)
    \ I always put in too many comments, force of habit [noparse]:)[/noparse]
    \
    \ each unit of functionality is implemented as a single word
    \ when each word is functioning correctly, string them together

    variable w-delay \ ( uses w@ w! time delay in milliseconds )
    : !DELAY w-delay w! ; \ ( ms - ) ( store the milliseconds to wait )
    : .DELAY w-delay w@ del_ms ; \ ( - ) ( wait for milliseconds in delay )

    : pin16-output 10000 dira ! ; \ ( - ) ( make pin16 output )
    : pin16-hi 10000 outa ! ; \ ( - ) ( make pin16 high LED ON )
    : pin16-lo 0 outa ! ; \ ( - ) ( make pin16 low LED OFF )

    \ ... string them together...

    : flash16 pin16-hi .DELAY pin16-lo .DELAY ; \ ( - ) ( flash LED using DELAY )

    \ ... and put it in a loop

    : FLASHES pin16-output 0 do flash16 loop ; \ ( number of flashes desired - )

    \ After one has determined what code is needed, it is possible to
    \ cram everything into a single word
    \ doing everything all in one word is sometimes refered to as
    \ write only code (write once - edit never again )
    \ this takes slightly less space but can be confusing on larger applications
    \ after the code has been left alone for a few days

    : ALL-ONE-WORD \ ( flashes - )
    10000 dira ! \ ( make pin16 output )
    0 do \ flashes to 0 DO ...
    10000 outa ! \ ( make pin16 high LED ON )
    100 del_ms \ ( delay for 100 ms)
    0 outa ! \ ( make pin16 low LED OFF )
    100 del_ms
    loop ;

    10 ALL-ONE-WORD
    \ next use the other method

    50 !DELAY
    20 FLASHES
  • Brian RileyBrian Riley Posts: 626
    edited 2010-05-07 23:10
    prof_braino said...
    \ FLASH AN LED using PROPFORTH 2.5 (new version of salsanci spinforth 1.1, not propellerforth from Cliffe Biffle)
    \ load PropForth.spin into eeprom and use teraterm 1 ms per char and 1 ms per line 38400 baud worked best for me

    so where do we find PROPFORTH 2.5?

    cheers ... BBR

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    cheers ... brian riley, n1bq, underhill center, vermont
    The Shoppe at Wulfden
    www.wulfden.org/TheShoppe/
    www.wulfden.org/TheShoppe/prop/ - Propeller Products
    www.wulfden.org/TheShoppe/k107/ - Serial LCD Display Gear
  • Jay KickliterJay Kickliter Posts: 446
    edited 2010-05-08 01:02
    [b]PUB[/b] start
        [b]cognew[/b](@Toggle, 0)
    
    [b]DAT[/b]
                       [b]ORG[/b] 0 'Begin at Cog RAM addr 0
    Toggle             [b]long[/b] %101000_0010_1111_111110110_000000110    'mov dira, pin 'Set Pin to output
                       [b]long[/b] %101000_0010_1111_000001000_111110001    'mov Time, cnt 'Calculate delay time
                       [b]long[/b] %100000_0011_1111_000001000_000010000    'add Time, #$f 'Set initial delay here
    :loop              [b]long[/b] %111110_0010_1111_000001000_000000111    'waitcnt Time, Delay 'Wait
                       [b]long[/b] %011011_0010_1111_111110100_000000110    'xor outa, Pin 'Toggle Pin
                       [b]long[/b] %010111_0001_1111_000000000_000000011    'jmp #:loop 'Loop endlessly
    
    Pin                [b]long[/b] %0000_0000_0000_0000_0000_0000_0000_0001 'pin 0
    Delay              [b]long[/b] %0000_0000_0001_1110_1000_0100_1000_0000 '2_000_000 'Clock cycles to delay
    Time               [b]res[/b] 1 'System Counter Workspace
                       [b]FIT[/b] 496
    
    
    
  • BeanBean Posts: 8,129
    edited 2010-05-08 02:16
    Jay,
    · I see you went with "machine code" instead of the more familiar "assembly code".
    · That brings back memories of my Timex Sinclair 1000 writing assembly programs and converting them to hex for input into the machine.
    · Oh, yeah. Fun days...Fun days.

    Bean

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    Use BASIC on the Propeller with the speed of assembly language.
    PropBASIC thread http://forums.parallax.com/showthread.php?p=867134

    March 2010 Nuts and Volts article·http://www.parallax.com/Portals/0/Downloads/docs/cols/nv/prop/col/nvp5.pdf
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    There are two rules in life:
    · 1) Never divulge all information
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    If you choose not to decide, you still have made a choice. [noparse][[/noparse]RUSH - Freewill]
  • Oldbitcollector (Jeff)Oldbitcollector (Jeff) Posts: 8,091
    edited 2010-05-08 13:24
    FOR i=1 to 50
       OUT 888, 255
       FOR x=1 to 500
       NEXT x
       OUT 888,0
       FOR x=1 to 500
       NEXT x
    NEXT i
    
    



    OBC

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Are you Propeller Powered? PropellerPowered.com
    Visit the: PROPELLERPOWERED SIG forum kindly hosted by Savage Circuits.
  • JonnyMacJonnyMac Posts: 9,208
    edited 2010-05-08 14:45
    Bean said...
    Jay,
    I see you went with "machine code" instead of the more familiar "assembly code".
    That brings back memories of my Timex Sinclair 1000 writing assembly programs and converting them to hex for input into the machine.
    Oh, yeah. Fun days...Fun days. Bean

    Been there, too. I taught myself to program with my TS-1000. Even when I "upgraded" to a Commodore 64 I still used the TS-1000 and I'm regretting not bringing it with me when I moved back home from Texas.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon McPhalen
    Hollywood, CA
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2010-05-08 17:56
    [b]CON[/b]
    
      [b]_clkmode[/b]      = [b]xtal1[/b] + [b]pll16x[/b]
      [b]_xinfreq[/b]      = 5_000_000
    
    [b]OBJ[/b]
    
      s2    : "s2"
    
    [b]PUB[/b] start
    
      s2.start
      s2.set_led(s2#LEFT, s2#BLINK_RED)
    
    
    


    (For the upcoming S2 robot.)

    -Phil
  • HarleyHarley Posts: 997
    edited 2010-05-08 18:52
    @Phil,

    Are there any releasable details on the S2 robot yet?

    Would be interesting to hear about if possible. I suppose it will do more than S1 scribbler.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Harley Shanko
  • hover1hover1 Posts: 1,929
    edited 2010-05-08 18:59
    @Harley
    A little bit of info here:

    ·http://forums.parallax.com/showthread.php?p=899204

    Jim


    Blink......Blink
  • prof_brainoprof_braino Posts: 4,313
    edited 2010-05-16 18:13
    http://code.google.com/p/propforth/
    http://code.google.com/p/propforth/wiki/PropForth

    NOTE: propforth.spin will load onto your demo board, but the rest of the files listed may have problems.

    The instructions to recreate the kernel from source, to load source, and to save a new forth image do not work as presented in the instructions. At least that is what I experienced. I am guessing that the author has some pre-conditions that are not mentioned in the instructions, otherwise the version posted might just be buggy. He seems to think it works just fine as is, but my results are pretty much the same as listed in the ISSUES page.

    I'm not really an assembler guy, so its taking me a long to time to figure out what is causing the problem. But its still kind of cool.
  • HarleyHarley Posts: 997
    edited 2010-05-16 19:04
    @ hover1. Thanks for that URL.

    Wow! S2 looks like it will be many times better than S1. Lots to digest about S2.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Harley Shanko
Sign In or Register to comment.