Here's my code for switch circuit... (look after that for code with multiple switches)

DEFINE OSC 4

OUTPUT portd.0

OUTPUT portd.1

main:

HIGH portd.0

PAUSE 1000

LOW portd.0

HIGH portd.1

PAUSE 2000

LOW portd.1

GOTO main

The following is my code for using IF ELSE statements (two lights and two switches woooh!)

    main:      'begins program
    IF portb.7 = 1 AND portb.4 = 0 THEN  'If the switch at portd7 gets electricity and port.4 does not 
    '(Upper right first down vs. upper right 4 down)
    HIGH portd.1      'High means the light will turn on
    HIGH portd.3
    PAUSE 1000         'Slows down the clock
    LOW portd.1
    LOW portd.3
    HIGH  portd.2
    HIGH  portd.0
    ENDIF           'This tidbit is done with

    IF portb.4 = 1 AND portb.7 = 0 THEN     'Movin on to my next switch at portb4 (Upper right 4 down vs. Upper right 1st down)
    LOW portd.1
    LOW portd.2
    LOW  portd.0
    LOW  portd.3
    PAUSE 1000
    HIGH portd.3        'The rest of it will be light blinking on with pause in middle each time
    PAUSE 1000
    high portd.0
    pause 1000
    high portd.2
    pause 1000
    high portd.1
    ENDIF

    IF portb.4 = 1 AND portb.7 = 1 THEN
    LOW portd.3
    LOW portd.2
    HIGH portd.0
    high portd.1
    ENDIF

    IF portb.4 = 0 AND portb.7 = 0 THEN
    LOW portd.0
    LOW portd.1
    HIGH portd.3
    HIGH portd.2
    ENDIF 
    GOTO main 'loopin back to the beginning

My Pics and First Week Lab are found in my Journal


Page last modified September 21, 2005, at 08:48 PM