ROBODYSSEY SYSTEMS LLC

Product Catalog
Code Page
Policies
Gallery
Whats New
Press Releases
Resources
Links
Contact Us
About Us
Press

Home Product Catalog Shopping Cart Resources Links
Code Page Policies Gallery

'@ Platform: PicBasic
'@ Version: 1.0
'@ Author: Brian Patton (brianp@robodyssey.com)
' Robodyssey Systems, LLC. - www.robodyssey.com
'@ Last Updated: Dec 30, 2003
'***********************************************
'Nice experiment lighting Leds connected to ports B and C
'Port A has voltage dividers hooked to RA0 and RA1
'The Voltage Dividers each have a photo resistor.
'A sharp sensor is connected to RA2.

'This program provides a bar graph Led output of light intensity
'on PortC and a Led bar graph of distance on PortB
'Enjoy!
'*********Materials*****************************
' 1 Robodyssey PicPac MotherBoard
' 1 Pic16F876 or similar
' 9 Leds w pull up resistors
' 1 Sharp GP2D12 sensor
' 2 Voltage Divider boards
' 2 Photo Resistors
' PicBasic Compiler and a programmer

'***********************************************
' Register Locations

Symbol TRISA = $85 ' Register Location of TRISA
Symbol TRISC = $87 ' Register Location of TRISC
Symbol PortC = 7 ' Register Location of PortC
Symbol ADCON0 = $1F ' Register location of ADCON0
Symbol ADCON1 = $9F ' Register Location of ADCON1
Symbol ADRESH = $1E ' Register Location of ADRESH
Symbol ADRESL = $9E ' Register Location of ADRESL

'*****Initiation********************************
Init:
Dirs = %11111111 ' Set all Port B to output


'*****Main Code Block Area**********************

'************ A/D Read *************************

Start:
poke TRISC, %00000000 'Set all PortC Output
poke TRISA, %11111111 'Set all PortA Input
poke ADCON1, %00000010 'xxxx0010 - PortA 0-4 analog inputs, 5-7 digital inputs
'0xxxxxxx Sets result to Left justified
'1xxxxxxx Sets result to Right justified
AD0chk:
poke ADCON0, %11000001 'Set A/D to RC Osc, Channel 0, A/D converter ready
'xx000xxx-Chan 0(RA0), xx001xxx-Chan 1(RA1),
'xx010xxx-Chan 2(RA2), xx011xxx-Chan 3(RA3),
'xx100xxx-Chan 4(RA4), xx101xxx-Chan 5(RA5),
'xx110xxx-Chan 6(RA6), xx111xxx-Chan 7(RA7),

b0 = %11000101 'xxxxx1xx - on, xxxxx0xx - off
Poke ADCON0,b0 ' Turn on the conversion at Bit 2

AD0fin:
Pause 5
Peek ADCON0,b0
If b0 = %11000101 Then AD0fin ' Wait for low on bit-2 of ADCON0, conversion finished
Peek ADRESH,b3 ' Move HIGH byte of result B3 variable


AD1chk:
poke ADCON0, %11001001 'Set A/D to RC Osc, Channel 1, A/D converter ready
'xx000xxx-Chan 0(RA0), xx001xxx-Chan 1(RA1),
'xx010xxx-Chan 2(RA2), xx011xxx-Chan 3(RA3),
'xx100xxx-Chan 4(RA4), xx101xxx-Chan 5(RA5),
'xx110xxx-Chan 6(RA6), xx111xxx-Chan 7(RA7),

b0 = %11001101 'xxxxx1xx - on, xxxxx0xx - off
Poke ADCON0,b0 ' Turn on the conversion at Bit 2

AD1fin:
Pause 5
Peek ADCON0,b0
If b0 = %11001101 Then AD1fin ' Wait for low on bit-2 of ADCON0, conversion finished
Peek ADRESH,b4 ' Move HIGH byte of result B4 variable

AD2chk:
poke ADCON0, %11010001 'Set A/D to RC Osc, Channel 2, A/D converter ready
'xx000xxx-Chan 0(RA0), xx001xxx-Chan 1(RA1),
'xx010xxx-Chan 2(RA2), xx011xxx-Chan 3(RA3),
'xx100xxx-Chan 4(RA4), xx101xxx-Chan 5(RA5),
'xx110xxx-Chan 6(RA6), xx111xxx-Chan 7(RA7),

b0 = %11010101 'xxxxx1xx - on, xxxxx0xx - off
Poke ADCON0,b0 ' Turn on the conversion at Bit 2

AD2fin:
Pause 5
Peek ADCON0,b0
If b0 = %11010101 Then AD2fin ' Wait for low on bit-2 of ADCON0, conversion finished
Peek ADRESH,b5 ' Move HIGH byte of result B5 variable


'****** Turn on Leds based on A/D value**********

AD0Led1: 'Check the AD value stored in b3
if b3 > 25 then AD0Led2 'If over 25 then move on
Poke PortC,%00000001 'Poke the First Led on Port C
goto AD1Led1 'Move on

AD0Led2:
if b3 > 50 then AD0Led3 'If over 50 then move on
Poke PortC,%00000011 'Poke the 1rst 2 Leds
goto AD1Led1 'Move on

AD0Led3: 'over 50
Poke PortC,%00000111 'Peg all three Leds
goto AD1Led1 'Check the other next AD value stored in b4

AD1Led1: 'Check the AD value stored in b4
if b4 > 25 then AD1Led2 'If over 25 then move on
peek PortC, b6 'Find the values from AD0 above
b7 = b6 + %10000000 'Add them to the next Led value
poke PortC, b7 'Shove them up the port
goto AD2Led1 'Move On

AD1Led2:
if b4 > 50 then AD1Led3 'If over 50 then move on
peek PortC, b6 'Find the values from AD0 above
b7 = b6 + %11000000 'Add them to the next Led value
poke PortC, b7 'Turn on the next light
goto AD2Led1 'Move on

AD1Led3: 'over 50
peek PortC, b6 'Find the values from AD0 above
b7 = b6 + %11100000 'Add them to the next Led value
poke PortC, b7 'Turn on the next light
goto AD2Led1 'Move On


AD2Led1: 'Check the AD value stored in b5
if b5 > 40 then AD2Led2 'If over 40 then move on
Low 5 'Turn off Led RB5
Low 6 'Turn off Led RB6
Low 7 'Turn off Led RB7
goto cont 'Let's head for the end

AD2Led2:
if b5 > 75 then AD2Led3 'If over 75 then move on
High 5 'Turn on Led RB5
Low 6 'Turn off Led RB6
Low 7 'Turn off Led RB7
goto cont 'Let's head for the end

AD2Led3:
if b5 > 125 then AD2Led4 'If over 125 then move on
High 5 'Turn on Led RB5
High 6 'Turn on Led RB6
Low 7 'Turn off Led RB7
goto cont 'Let's head for the end


AD2Led4: 'over 125 so...
High 5 'Turn on Led RB5
High 6 'Turn on Led RB6
High 7 'Turn on Led RB7
goto cont 'Head for the end

cont:
Pause 10 'Chill for a bit
goto AD0chk 'Start it all over again
end

Home Product Catalog Shopping Cart Resources Links
Code Page Policies Gallery

Robodyssey Systems manufactures Robot Kits including Autonomous Mobile Walking Robots, Wheeled Robots, Talking Robots, Expressive Robots, and Social Robots. We also sell Robotics Accessories including Nexcell NiMH AA Rechargeable Batteries, Nexcell NiMH AAA Rechargeable Batteries, Battery Holders, Velcro Straps for Battery Packs, Battery Chargers, Robot Grippers, Hobby Servos, Servos Modified for Continuous Rotation, Tail Wheels for all Rolling Robotic Platforms, Polyurethane Skate Wheels with Servo Adapter Hubs, Sharp IR Sensors and Adjustable Sensor Brackets, Sensor Cables, and Programming Cables. All of our Robot Kits can be purchased as easy to assemble robot kits or as fully assembled stationary or mobile robots. Robodyssey uses 1/8 inch aluminum and acetyl for most all of our mobile robot components and robotics accessories. We provide classroom training for teachers interested in integrating robotics, computer programming and electronics into the classroom.

We hope you enjoy our web site. Feel free to use any robotic resources. Robodyssey is your complete solution for Educational Robotics as well as Hobby Robotics.