Programing

Home | Members | Summary | Background | Scope | Design Concepts | Final Design | Testing | Conclusions | Calculations | Parts List | Site Map


Up
Static Buoyancy
Dynamic Buoyancy
Power Consumption
Programing

Sub-Pages

 

 

Microcontroller Programming

 

        This page contains the program that was used on the microcontroller for the submersible robot. It should be noted that this program was meant to only serve as an example of what kind of programming can be done using the microcontroller. A copy of this program can be found here. The software package necessary to interface with the microcontroller is available at www.parallax.com.

 

' {$STAMP BS2}

' {$PBASIC 2.5}

' Senior Design Project

' Hardare Connection:

'      P12--P15 control Value #1--Value #4

'      P1 connects to a reed switch (get 0 when closed)

'      P2 connects to a solar pannel (get 1 when lighted)

'-------------------------------------------------------------------------

' Initialization and Variable Declaration

i VAR Word                         'Counter

j VAR Word                         'Counter

k VAR Word                         'Counter

i=0

j=0

LOW 12                             'Turn off Value #1

LOW 13                             'Turn off Value #2

LOW 14                             'Turn off Value #3

LOW 15                             'Turn off Value #4

'-------------------------------------------------------------------------

'Program starts

 

'8 hour delay

GOSUB Time15

GOSUB Time15

GOSUB Time15

GOSUB Time15

GOSUB Time15

GOSUB Time15

GOSUB Time15

GOSUB Time15

GOSUB Time15

GOSUB Time15

GOSUB Time15

GOSUB Time15

 

 

DO

  IF (IN2=1) THEN                  'Check the solar pannel, IN2=1 when receive light

    GOSUB P1

    END                            'Put CPU into low power mode until reset

  ELSE

    GOSUB Time15

    GOSUB Time15

    GOSUB Time15

    GOSUB Time15                   'An hour delay

 

    IF (i > 92318) THEN              'Adjust j according to value of i

      j=33

    ENDIF

    IF (i <= 86879) THEN

      j=34

    ENDIF

    IF (i <= 81455) THEN

      j=35

    ENDIF

    IF (i <= 76020) THEN

      j=36

    ENDIF

    IF (i <= 70619) THEN

      j=37

    ENDIF

    IF (i <= 65186)  THEN

      j=38

    ENDIF

    IF (i <= 59727)  THEN

      j=39

    ENDIF

    IF (i <= 54328)  THEN

      j=40

    ENDIF

    IF (i <= 48876)  THEN

      j=41

    ENDIF

    IF (i <= 43459)  THEN

      j=42

    ENDIF

    IF (i <= 38042)  THEN

      j=43

    ENDIF

    IF (i <= 32587)  THEN

      j=44

    ENDIF

    IF (i <= 27188)  THEN

      j=45

    ENDIF

    IF (i <= 21761)  THEN

      j=46

    ENDIF

    IF (i <= 16310)  THEN

      j=47

    ENDIF

    IF (i <= 10887)  THEN

      j=48

    ENDIF

    IF (i <= 5449)  THEN

      j=49

    ENDIF

    IF (i <= 50)  THEN

      j=50

    ENDIF

 

    DO UNTIL (j=0)

      i=i+1

      j=j-1

      HIGH 12                      'Turn on Value #1

      PAUSE 1000                   '1 Second delay

      LOW 12                       'Turn off Value #1

      PAUSE 2000                   '2 Second delay

      HIGH 13                      'Turn on Value #2

      PAUSE 1000                   '1 Second delay

      LOW 13                       'Turn off Value #2

      PAUSE 3000                   '3 Second delay

    LOOP

 

    GOSUB Time15

    GOSUB Time15

    GOSUB Time15

    GOSUB Time15                   'An hour delay

 

    IF (IN2=1) THEN                'Check the solar pannel

      GOSUB P1

      END                          'Put CPU into low power mode until reset

    ELSE

      HIGH 14                      'Turn on Value #3

      PAUSE 5000                   '5 Seconds delay

      LOW 14                       'Turn off Value #3

    ENDIF

 

  ENDIF

 

LOOP

 

'--------------------------------------------------------------------------

'Subroutine P1: turn on/off value #3 and #4

P1:

    HIGH 14                        'Turn on Value #3

    PAUSE 5000                     '5 Seconds delay

    LOW 14                         'Turn off Value #3

    PAUSE 5000                     '5 Seconds delay

    HIGH 15                        'Turn on Value #4

    PAUSE 5000                     '5 Seconds delay

    LOW 15                         'Turn off Value #4

RETURN

 

'--------------------------------------------------------------------------

'Subroutine Time15: 15 minutes delay

Time15:

    k=0

   PAUSE 500                      'Use when debugging

    DO UNTIL (k>=180)              '5Sec*12*15=180

      k=k+1

      PAUSE 5000                   '5 Seconds delay

    LOOP

RETURN


Home | Members | Summary | Background | Scope | Design Concepts | Final Design | Testing | Conclusions | Calculations | Parts List | Site Map

Last updated: 04/09/07.