Stairwell light code from BS1 to PHP2.50a


Closed Thread
Results 1 to 2 of 2
  1. #1
    Join Date
    Jun 2005
    Location
    Germany
    Posts
    6

    Question Stairwell light code from BS1 to PHP2.50a

    Hi all,

    this ist me first post. I have here the old code of a stairwell light in BS1 and would like to convert it in PicBasic 2.50a. What do I have to do?

    ************************************************** *****************

    ' {$STAMP BS1}
    'Typ: PBASIC-Source for stairwell light
    'Name: stairwell_light.bas
    'Stand: 29/11/1999

    ' Constants
    SYMBOL tast_msk= %00010000 'Mask for button
    SYMBOL lampen = 6 'Pin for lamps

    ' Variables
    SYMBOL inp = B0 'read IO byte
    SYMBOL count1 = W1 'Cycle counter
    SYMBOL init = W2 '2559 Cycles to 20 ms
    SYMBOL count2 = B6 'Number of keystrokes
    SYMBOL count3 = B7 'Minutes
    SYMBOL outflag = B8 'Flag whether pushed for a long time

    ' Initialization
    count1 = 0 'counter for time interval = 0
    count2 = 0 'Number of keystrokes = 0
    count3 = 0 'Minutes = 0
    outflag = 0 'Flag = 0

    DIRS = %01000000 'Pin 6 is output (relay)

    EEPROM 0, ($0f,$09) '$09FF in EEPROM
    READ 0,init 'Read Initialwert (Lo byte)
    READ 1,inp 'Read Initialwert (hi byte)
    init = 256 * inp + init 'Initialwert cycle counter

    ' Main program
    main:
    inp = PINS & tast_msk 'masking of bit 3
    IF inp = tast_msk THEN decr_count 'If not pressed button, then decr-count
    PAUSE 300 'Pause for 300 ms
    inp = PINS & tast_msk 'masking of bit 3
    IF outflag = 1 THEN on 'Questions whether turned off already
    IF inp <> tast_msk THEN off1 'questions on long pushing -> Lamp off
    on: HIGH lampen 'Switching on light
    outflag = 0 'Putting back flag for out switching cycle

    IF count2 = 4 THEN main 'more as 4 times push prevent
    count2 = count2 + 1 'Number of keystrokes inkr.
    LOOKUP count2, (0,3,10,30,600),count3 'Minutes determine
    count1 = init 'lamps on for 1 minute

    decr_count:
    PAUSE 20 'Pause 20 ms
    IF count1 = 0 THEN off0 'if count1 = 0, then light off
    count1 = count1 - 1 'Cycle counter decrementieren
    IF outflag = 1 THEN L1 'In the end switching cycle
    IF count3 > 1 THEN L1 'last minute reaches?
    IF count1 <> 853 THEN L1 '20 second before end reaches?
    count2 = 0 'Number of keystrokes = 0
    LOW lampen
    PAUSE 500 'Light for 0.5 Seconds off
    HIGH lampen
    L1: IF count1 <> 0 THEN main 'if cycle not gone off, then loop
    count3 = count3 - 1 'Number of cycles decrementieren
    IF count3 <> 0 THEN count1_init 'if count3 > 0, then cont1 newly initialize


    off0: 'switching off normally after expiry of the time
    LOW lampen
    count2 = 0 'Number of keystrokes = 0 '
    count3 = 0
    GOTO main 'Number of keystrokes = 0

    off1: 'Switching off by pushing for a long time
    LOW lampen
    PAUSE 500 'Light for 0.5 Seconds off
    HIGH lampen
    count1 = init ' counter for a minute initialize
    count2 = 0 'putting count2 to 0
    count3 = 1 'a minute
    outflag= 1 'Putting flag for out switching cycle
    GOTO main 'back to the main program

    count1_init:
    count1 = init 'count1 initialsieren
    GOTO main 'back to the main program

    ************************************************** *****************



    I am grateful for help

    Konrad
    Last edited by vtt-info; - 21st December 2007 at 17:09.

  2. #2
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    most of Stamps function will work as is, but here's some minor mods

    Usually, it's nice to use the PORT name of the PIC, even if some function allow to use PIN#

    LED VAR PORTA.0

    There's no DIRS, depending of the PIC, you'll ned to use TRISx or TRISIO

    TRISA=0 ' set all PORTA i/o to output

    IN PBP you don't need to alias to a Byte,bit, word variable, you just define it

    MyByteA VAR BYTE
    MyBitVar var BIT
    MyWordVar var WORD

    In the PBP manual, have a look at section 10
    <hr>

    Welcome on the forum

    PS: when you ask a question, always tell which PIC model you're going to use, if you have any schematic, post it too. More info we have, better the replies will be.

    HTH
    Last edited by mister_e; - 21st December 2007 at 17:35.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

Similar Threads

  1. How much code space do PBP statements use.
    By Darrel Taylor in forum Code Examples
    Replies: 5
    Last Post: - 13th February 2009, 21:31
  2. Loop with two motor and 2 sensors
    By MrRoboto in forum mel PIC BASIC
    Replies: 4
    Last Post: - 8th December 2008, 23:40
  3. Making Program Code Space your playground...
    By Melanie in forum Code Examples
    Replies: 15
    Last Post: - 19th July 2008, 08:26
  4. Light Sensor & LCD :: Code & Schematic
    By munim in forum Schematics
    Replies: 5
    Last Post: - 12th December 2006, 14:51
  5. Timer PIC16F57
    By leonel in forum mel PIC BASIC Pro
    Replies: 25
    Last Post: - 1st July 2005, 08:14

Members who have read this thread : 1

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts