MEL PICBASIC Forum - Amicus18 Companion Shield Manual #1


  • Amicus18 Companion Shield Manual #1

    In this article we will go throught the code listed in the Amicus18 Companion Shield Manual, section, "Building the Companion Shield". The Amicus18 Companion Shield Manual can be found here: http://www.myamicus.co.uk/content.php?117-Documents

    For the complete manual re-written for Pic Basic Pro go here:
    http://mackrackit.cambs.net/Amicus18/

    The code listed in the manual is written in Proton, I go line by line re-writing the code in Pic Basic Pro starting with the "2 LED Flasher".

    2 LED Flasher:
    Code:
    ' PIC18F25K20 ON THE AMICUS BOARD
    ' Flash 2 LEDs connected to RB2 and RB3 
    
        DEFINE OSC 64         'THE 16MHz IS PLLed TO 64 MHz
        DEFINE LOADER_USED 1  'USING THE AMICUS USB BOOT-LOADER
        
        PORTB = 0             'MAKES PORTB LOW
        TRISB=%00000000       'MAKES PORTB PINS OUTPUTS
        LED1 VAR PORTB.2      'ASSIGNS VAR TO PIN   
        LED2 VAR PORTB.3      'ASSIGNS VAR TO PIN  
        
        While 1 = 1             ' Create an infinite loop 
        	High LED1               ' Illuminate LED1 
        	PAUSE 500               ' Wait for half a second 
        	Low LED1                ' Extinguish LED1 
        	High LED2               ' Illuminate LED2 
        	PAUSE 500               ' Wait for half a second 
        	Low LED2                ' Extinguish LED2 
        Wend                    ' Do it forever
    The next set of codes is the "4 LED Sequencer". There are three codes for this hardware setup.
    4 LED Sequencer:
    Code:
    ' PIC18F25K20 ON THE AMICUS BOARD
    ' Illuminate 4 LEDs attached to PortB in sequence 
    ' Make sure the Amicus18 board's jumper Q3 is set to the RB1 position 
        
        DEFINE OSC 64         'THE 16MHz IS PLLed TO 64 MHz
        DEFINE LOADER_USED 1  'USING THE AMICUS USB BOOT-LOADER   
        PORTB = 0             'MAKES PORTB LOW
        TRISB=%00000000       'MAKES PORTB PINS OUTPUTS
        
        While 1 = 1        ' Create an infinite loop 
        	PORTB = %00000001  ' Illuminate the first LED 
        	PAUSE 300          ' Delay a pre-determined amount of time 
        	PORTB = %00000010  ' Illuminate the second LED 
        	PAUSE 300          ' Delay a pre-determined amount of time 
        	PORTB = %00000100  ' Illuminate the third LED 
        	PAUSE 300          ' Delay a pre-determined amount of time 
        	PORTB = %00001000  ' Illuminate the fourth LED 
        	PAUSE 300          ' Delay a pre-determined amount of time 
        Wend               ' Do it forever
    4 LED Sequencer A:
    Code:
    ' PIC18F25K20 ON THE AMICUS BOARD
    ' Illuminate 4 LEDs attached to PortB in sequence 
    ' Using a more advanced method 
    ' Make sure the Amicus18 board's jumper Q3 is set to the RB1 position 
    
        DEFINE OSC 64         'THE 16MHz IS PLLed TO 64 MHz
        DEFINE LOADER_USED 1  'USING THE AMICUS USB BOOT-LOADER   
        PORTB = 0             'MAKES PORTB LOW
        TRISB=%00000000       'MAKES PORTB PINS OUTPUTS
        bPortShadow VAR Byte  ' Create a variable to hold the state of PortB 
        bLoop VAR Byte        ' Create a variable for the bit counting loop 
              
        While 1 = 1                   ' Create an infinite loop       
            bPortShadow = 1           ' Set the initial state of PortB 
            PORTB = bPortShadow       ' Transfer the shadow variable to PortB 
            PAUSE 300                 ' Wait a pre-determined amount of time 
        For bLoop = 0 To 2            ' Create a loop from 0 to 2 
            bPortShadow = bPortShadow << 1 ' Shift a bit left one position 
            PORTB = bPortShadow       ' Transfer the shadow variable to PortB 
            PAUSE 300                 ' Wait a pre-determined amount of time 
        Next                          ' Close the loop    
        Wend                          ' Do it forever
    4 LED Sequencer B:
    Code:
    ' PIC18F25K20 ON THE AMICUS BOARD
    ' Illuminate 4 LEDs attached to PortB in sequence left to right
    ' Using a more advanced method 
    ' Make sure the Amicus18 board's jumper Q3 is set to the RB1 position 
    
        DEFINE OSC 64         'THE 16MHz IS PLLed TO 64 MHz
        DEFINE LOADER_USED 1  'USING THE AMICUS USB BOOT-LOADER   
        PORTB = 0             'MAKES PORTB LOW
        TRISB=%00000000       'MAKES PORTB PINS OUTPUTS
        bPortShadow VAR Byte  ' Create a variable to hold the state of PortB 
        bLoop VAR Byte        ' Create a variable for the bit counting loop 
        
        bPortShadow = 1          ' Set the initial state of PortB 
        Low PORTB                ' Make PortB output low (Extinguish all four LEDs) 
        PORTB = bPortShadow      ' Transfer the shadow variable to PortB 
        PAUSE 300                ' Wait a pre-determined amount of time 
        While 1 = 1              ' Create an infinite loop       
        For bLoop = 0 To 2       ' Create a loop from 0 to 2 
            bPortShadow = bPortShadow << 1 ' Shift a bit left one position 
            PORTB = bPortShadow   ' Transfer the shadow variable to PortB 
            PAUSE 300                  ' Wait a pre-determined amount of time 
        Next                           ' Close the loop 
        For bLoop = 2 To 0 Step -1     ' Create a loop from 2 to 0 
            bPortShadow = bPortShadow >> 1 ' Shift a bit right one position 
            PORTB = bPortShadow        ' Transfer the shadow variable to PortB 
            PAUSE 300                  ' Wait a pre-determined amount of time 
        Next                           ' Close the loop 
        Wend                           ' Do it forever
    The next set of codes is the "8 LED Sequencer". There are three codes for this hardware setup.
    8 LED Sequencer:
    Code:
    ' PIC18F25K20 ON THE AMICUS BOARD
    ' Illuminate 8 LEDs attached to PortB in sequence 
    ' Make sure the Amicus18 board's jumper Q3 is set to the RB1 position 
        
        DEFINE OSC 64         'THE 16MHz IS PLLed TO 64 MHz
        DEFINE LOADER_USED 1  'USING THE AMICUS USB BOOT-LOADER   
        PORTB = 0             'MAKES PORTB LOW
        TRISB=%00000000       'MAKES PORTB PINS OUTPUTS
        
        While 1 = 1        ' Create an infinite loop 
        	PORTB = %00000001  ' Illuminate the first LED 
        	PAUSE 300          ' Delay a pre-determined amount of time 
        	PORTB = %00000010  ' Illuminate the second LED 
        	PAUSE 300          ' Delay a pre-determined amount of time 
        	PORTB = %00000100  ' Illuminate the third LED 
        	PAUSE 300          ' Delay a pre-determined amount of time 
        	PORTB = %00001000  ' Illuminate the fourth LED 
        	PAUSE 300          ' Delay a pre-determined amount of time 
       	 PORTB = %00010000  ' Illuminate the fith LED 
        	PAUSE 300          ' Delay a pre-determined amount of time 
        	PORTB = %00100000  ' Illuminate the sixth LED 
        	PAUSE 300          ' Delay a pre-determined amount of time 
        	PORTB = %01000000  ' Illuminate the seventh LED 
        	PAUSE 300          ' Delay a pre-determined amount of time 
        	PORTB = %10000000  ' Illuminate the eighth LED 
        	PAUSE 300          ' Delay a pre-determined amount of time 
        Wend               ' Do it forever
    8 LED Sequencer A:
    Code:
    ' PIC18F25K20 ON THE AMICUS BOARD
    ' Illuminate 8 LEDs attached to PortB in sequence 
    ' Using a more advanced method 
    ' Make sure the Amicus18 board's jumper Q3 is set to the RB1 position 
    
        DEFINE OSC 64         'THE 16MHz IS PLLed TO 64 MHz
        DEFINE LOADER_USED 1  'USING THE AMICUS USB BOOT-LOADER   
        PORTB = 0             'MAKES PORTB LOW
        TRISB=%00000000       'MAKES PORTB PINS OUTPUTS
        bPortShadow VAR Byte  ' Create a variable to hold the state of PortB 
        bLoop VAR Byte        ' Create a variable for the bit counting loop 
              
        While 1 = 1                   ' Create an infinite loop       
            bPortShadow = 1           ' Set the initial state of PortB 
            PORTB = bPortShadow       ' Transfer the shadow variable to PortB 
            PAUSE 300                 ' Wait a pre-determined amount of time 
        For bLoop = 0 To 6            ' Create a loop from 0 to 6 
            bPortShadow = bPortShadow << 1 ' Shift a bit left one position 
            PORTB = bPortShadow       ' Transfer the shadow variable to PortB 
            PAUSE 300                 ' Wait a pre-determined amount of time 
        Next                          ' Close the loop    
        Wend                          ' Do it forever
    8 LED Sequencer B:
    Code:
    ' PIC18F25K20 ON THE AMICUS BOARD
    ' Illuminate 4 LEDs attached to PortB in sequence left to right
    ' Using a more advanced method 
    ' Make sure the Amicus18 board's jumper Q3 is set to the RB1 position 
    
        DEFINE OSC 64         'THE 16MHz IS PLLed TO 64 MHz
        DEFINE LOADER_USED 1  'USING THE AMICUS USB BOOT-LOADER   
        PORTB = 0             'MAKES PORTB LOW
        TRISB=%00000000       'MAKES PORTB PINS OUTPUTS
        bPortShadow VAR Byte  ' Create a variable to hold the state of PortB 
        bLoop VAR Byte        ' Create a variable for the bit counting loop 
        
        bPortShadow = 1          ' Set the initial state of PortB 
        Low PORTB                ' Make PortB output low (Extinguish all four LEDs) 
        PORTB = bPortShadow      ' Transfer the shadow variable to PortB 
        PAUSE 300                ' Wait a pre-determined amount of time 
        While 1 = 1              ' Create an infinite loop       
        For bLoop = 0 To 6       ' Create a loop from 0 to 6 
            bPortShadow = bPortShadow << 1 ' Shift a bit left one position 
            PORTB = bPortShadow   ' Transfer the shadow variable to PortB 
            PAUSE 300                  ' Wait a pre-determined amount of time 
        Next                           ' Close the loop 
        For bLoop = 6 To 0 Step -1     ' Create a loop from 6 to 0 
            bPortShadow = bPortShadow >> 1 ' Shift a bit right one position 
            PORTB = bPortShadow        ' Transfer the shadow variable to PortB 
            PAUSE 300                  ' Wait a pre-determined amount of time 
        Next                           ' Close the loop 
        Wend                           ' Do it forever
    The last code in this section is the "Traffic Light Sequencer".
    Code:
    ' PIC18F25K20 ON THE AMICUS BOARD
    ' Simulate a single traffic light using Red, Yellow, and Green LEDs 
    
        DEFINE OSC 64         'THE 16MHz IS PLLed TO 64 MHz
        DEFINE LOADER_USED 1  'USING THE AMICUS USB BOOT-LOADER   
        PORTB = 0             'MAKES PORTB LOW
        TRISB=%00000000       'MAKES PORTB PINS OUTPUTS
        
        Red   VAR PORTB.0              ' Red LED is attached to RB0 
        Amber VAR PORTB.1            ' Amber LED is attached to RB1 
        Green VAR PORTB.2            ' Green LED is attached To RB2 
        RedInterval CON 4000      ' Time that the Red light will stay on 
    ' Time that the Red and Amber lights will stay on 
        AmberRedInterval CON RedInterval / 4 
    ' Time that the Amber light will stay on    
        AmberInterval CON RedInterval - AmberRedInterval  
        GreenInterval CON 6000    ' Time that the Green light will stay on 
            
        While 1 = 1                   ' Create an infinite loop 
            High Red                   ' Illuminate the Red LED 
            PAUSE RedInterval         ' Wait for the appropriate length of time 
            High Amber                  ' Illuminate the Amber LED 
            PAUSE AmberRedInterval    ' Wait for the appropriate length of time 
            Low Red                     ' Extinguish the Red LED 
            PAUSE AmberInterval       ' Wait for the appropriate length of time 
            High Green                   ' Illuminate the Green LED 
            Low Amber                    ' Extinguish the Amber LED 
            PAUSE GreenInterval        ' Wait for the appropriate length of time 
            Low Green                   ' Extinguish the Green LED 
            High Amber                   ' Illuminate the Amber LED 
            PAUSE AmberInterval        ' Wait for the appropriate length of time 
            Low Amber                   ' Extinguish the Amber LED 
        Wend                          ' Do it forever