|
' Demonstration of 3 AtoDs on one Pic chip
' Platform: PicBasic
' Version: 1.0
' Author: Brian Patton (brianp@robodyssey.com)
' Robodyssey Systems, LLC. - www.robodyssey.com
' Last Updated: Dec 27, 2003
'***********************************************
' This Program uses the 16F876 and two voltage divider boards for senses.
' It also uses 5 Leds connected with pull up 1k resistors on RB3-RB7.
' The VDBs are connected to RA0 and RA1
' The Sharp GP2D12 is connected to RA2
'*********Materials*****************************
' 1 Robodyssey PicPac MotherBoard
' 1 Pic16F876 or similar
' 5 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 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 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:
if b3 > 50 then AD0Led2 'If over 50 then move on
High 3 'If less than 50 then turn on Led RB3
Low 4 'and off Led RB4
goto AD1Led1
AD0Led2: 'over 50
High 3 'Turn on Led RB3
High 4 'Turn on Led RB4
goto AD1Led1 'Check the other next AD value stored in b4
AD1Led1:
if b4 > 50 then AD1Led2 'If over 50 then move on
High 5 'If less than 50 then turn on Led RB5
Low 6 'and off Led RB6
goto AD2Led1
AD1Led2: 'over 50
High 5 'Turn on Led RB5
High 6 'Turn on Led RB6
goto AD2Led1 'Check the other next AD value stored in b5
AD2Led1:
if b5 < 100 then AD2Led2 'If over 50 then move on
Low 7 'Turn off Led RB7
goto cont 'Let's head for the end
AD2Led2: 'over 50 so
High 7 'Turn on RB7
goto cont 'Head for the end
cont:
Pause 10 'Chill for a bit
goto AD0chk 'Start it all over again
end
|
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.
|