Picaxe small project request

Discussion in 'The Projects Forum' started by happysoul, Nov 11, 2014.

  1. happysoul

    Thread Starter New Member

    Sep 9, 2014
    28
    0
    Hi guys and gals
    i was wondering if someone could give me the picaxe coding for a small project .On power up i need to have one output pin pulse 6 times( or variable 8 max), say once a second and then stop till it is powered up next time.
    thanks ahead
    Happysoul.
     
  2. KMoffett

    AAC Fanatic!

    Dec 19, 2007
    2,574
    230
  3. elec_mech

    Senior Member

    Nov 12, 2008
    1,513
    193
    What, and let them have all the fun?

    Here you go:
    Code (Text):
    1. #picaxe 08m2                       ' Define PICAXE 08M2
    2. #no_data                           ' Ignore EEPROM data - loads program faster
    3.  
    4. '========================================================================
    5.  
    6. Initialize:                        ' Initialize Routine - initialize pins and set up variables
    7.     LET dirsC = %00000010          ' Make pin C.1 a output; rest as inputs
    8.     LET pinsC = %00000000          ' Turn off all outputs on port C
    9.     SYMBOL i = b0                  ' Data byte variable used with FOR loop
    10.     LET i = 0                      ' Set i equal to 0
    11.     SYMBOL pulse_num = b1          ' Data byte variable used to set number of cycles or loops
    12.     LET pulse_num = 6              ' Set pulse_num equal to 6
    13.     SYMBOL pulse_high = b2         ' Data byte variable used to set pulse high time
    14.     LET pulse_high = 500           ' Set pulse_num equal to 500 (milliseconds)  
    15.     SYMBOL pulse_low = b3          ' Data byte variable used to set pulse low time
    16.     LET pulse_high = 500           ' Set pulse_num equal to 500 (milliseconds)
    17.  
    18. Main:                              ' Main Routine
    19.  
    20. FOR i = 1 to pulse_num             ' Perform following pulse_num of times
    21.     HIGH C.1                       ' Make output on C.1 high
    22.     PAUSE pulse_high               ' Wait for pulse_high time
    23.     LOW C.1                        ' Make output on C.1 low
    24.     PAUSE pulse_high               ' Wait for pulse_low time
    25. NEXT                               ' Repeat
    26.  
    27. END                                ' End program
    You can change the pulse high and low times to suit your needs as well as the number of loops. As currently written, the pulse will be high for half a second then low for half a second or to put another way 1 Hz with a 50% duty cycle.
     
    absf likes this.
  4. happysoul

    Thread Starter New Member

    Sep 9, 2014
    28
    0
     
  5. happysoul

    Thread Starter New Member

    Sep 9, 2014
    28
    0
    Thank you very much ,appreciate it have yourself a great day
     
Loading...