|
The communication cable to the PC is made as specified in the PicBasic Compiler Manual.
| |
1.0K |
|
DB9 |
| pin |
--/\/\/\---- |
RS-232 RX |
Pin 2 |
| GND |
------------ |
RS-232 GND |
Pin 5 |
This Project saves Data to an external EEPROM. First, if the C3 switch is open,
the system gathers data in through the A to D on RA0. If the pin is high (jumpered
with a resistor to supply) the chip sends the data out to the PC.
See "PicDisplay" for more details.
I2C protocols allow for easy transfer of information to an external device.
the syntax in as follows
I2COUT Control, Address, ( Value{,Value})
I2COUT being the command
Control being the chip setup info.
1xxxxxxx, 16bit chip - 0xxxxxxxx, 8bit chip.
x1010xxx, chip specific. Look it up, the 24LC256 was 1010.
xxxxxXXX, device select bits.
Address being the memory location.
Values being the variable your playing with.
I2CIN is pretty much the same but reversed in function.
I2CIN Control, Address, Var{,Var}
One important consideration, it takes about 10ms for it to occur. Thus the pause after.
This project Requires the modification of the include file "PBL.INC".
It should be located in your compilers directory. Since I wanted to do
both analog and digital signals on PortA, I decided it would be best to
relocate the I2C protocols from the standard pins 0 and 1 to pins 4 and 5.
This way I could use pin 0 as an analog input.
Doing this is really quite easy. Simply open up pbl.inc with any text editor.
Scroll down to the I2C stuff (as shown)

Then change the port pins to whatever you want. In this case 4 and 5.

|
'******** Writing to External EEPROM with a PIC ***************
'******************************************************
'@ Platform: PicBasic
'@ Version: 1.0
'@ Author: Brian Patton (brianp@robodyssey.com)
' Robodyssey Systems, LLC. - www.robodyssey.com
'@ Last Updated: Feb, 20, 2004
'******************************************************
' This Program uses the 16F876
'*********Materials**************************************
' 1 Robodyssey PicPac MotherBoard
' 1 Pic16F876 or similar
' 1 Voltage Divider board
' 1 Variable Resistor (pot)or photoresistor
' 1 10k resistor to act as switch on C3
' 1 I2C EEPROM (I used the 24LC256)
' 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 TRISC = $87 ' Register Location of TRISC
Symbol PortC = 7 ' Register Location of PortC
'***** Variables *****************************************
Symbol addr = w0 ' The bigger EEPROMs need 16 bit addresses
Symbol value = b2 ' Place for the data
Symbol cont = %11010000 ' EEPROM control byte
Symbol ADcon = b3 ' storag spot for A to D functions
Symbol Cstatus = b4 ' Check state of Port C variable
'***** Initiation *****************************************
Init:
Dirs = %11111111 ' Set all Port B to output
Poke ADCON1,%00000100 ' Pins 0,1 and 3 analog input. Pins 2,4 and 5 digital.
' 0xxxxxxx Sets result to Left justified
' 1xxxxxxx Sets result to Right justified
Poke TRISC, %11111111 ' Set all PortC Input
'**********Main Code Block Area***************************
Peek PortC,Cstatus 'Get the status of Port C
Cstatus = Cstatus & %00001000 'Set to 0 all but C3
If Cstatus = 0 Then gather 'If open then Gather Data
'If closed then Recall Data
'*********** Get Data Back Out ****************************
recall:
For addr=1 to 1000
I2Cin cont,addr,value 'See explanation above this code
Serout 0,N2400,("Recalling Data ",#value,10,13) 'display value
Pause 20
Next
End
'********** Sample and store Data **************************
gather:
Serout 0,N2400,("Gathering Data",10,13) 'Display "Gathering Data" on the PC screen
Pause 3000
Start:
Poke TRISA, %00000001 'Set pin0, PortA Input
'******** A to D Operation ********************************
AD0chk:
For addr = 1 to 1000 'addr is a 16 bit variable
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),
ADcon = %11000101 'xxxxx1xx - on, xxxxx0xx - off
Poke ADCON0,ADcon ' Turn on the conversion at Bit 2
AD0fin:
Peek ADCON0,ADcon
If ADcon = %11000101 Then AD0fin
' Wait for low on bit-2 of ADCON0, conversion finished
Peek ADRESH,value
Serout 0,N2400,(#addr," = ",#value,10,13) 'display value
I2Cout cont,addr,(value)
Pause 10 'Need time to write
Next
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.
|