![]() | ![]() | ![]() |
| | |||||||
| Micro Controllers Discuss all aspects of micro controllers - building them, coding them, etc. All controllers are welcome - PIC, BASIC, Z8 Encore!, etc. |
| | LinkBack | Thread Tools | Display Modes |
| | (permalink) |
| Hello. For my line following, instead of having static values for the line and off the line sensor readings, I was thinking of having a button for the on-line reading and off line reading, so when I press each individual button: I could get the value and store it. This way, my robot would be better in different conditions without having to reprogram every time. I was wondering, is it possible? Can PICs store such data? Would anyone have any snippets? Thanks a lot, Omar | |
| |
| | (permalink) |
| That is exactly what the EEPROM is for. Reading and writing EEPROM varies from chip to chip. Which Pic are you using? Mike. P.S. I think Nigel has a tutorial on this for the 16f628. | |
| |
| | (permalink) |
| Also, the data sheet contains example code for reading and writing. Mike. | |
| |
| | (permalink) |
| Here’s an example of interfacing with 4 EEPROM’s on an I2C network; Code: Device = 16F876
XTAL 20
ALL_DIGITAL = True
Declare SCL_PIN PORTB.0
Declare SDA_PIN PORTB.1
Dim TX As PORTB.2
Dim DATA_OUT As Byte
Dim DATA_IN(20) As Byte
Dim Address As Word ' 16-bit address required
For Address = 1 To 20
DATA_OUT = Address
BStart ' Send the start command on I2C
BusOut %10100010,Address,[DATA_OUT] ' Send the byte to the EEPROM
BStop ' Send the stop command on I2C
DelayMS 5 ' Allow time for allocation of byte
Next Address
For Address = 1 To 20
BStart ' Send the start command on I2C
BusOut %10100010,[Address] ' Send the address to read
Brestart ' Send a restart command on I2C
BusIn %10100011, [DATA_IN[Address]] ' Grab data at the above address
BStop ' Send the stop command on I2C
Next Address
Stop http://users.tpg.com.au/gramo/Site/eeproms.htm
__________________ Spency. PIC Micro's - Your mind is the limit PIC's and interfacing with other devices - a PIC Basic Guide @ digital-diy.net | |
| |
| | (permalink) |
| Why complicate things? The OP wanted to know how to store 2 bytes. This can easily be done in the internal EEPROM of most Pic chips. Did you not realise that Pic's have internal EEPROM? Mike. | |
| |
| | (permalink) | ||
| I miss read that, sorry. In that case, just use the PIC's onboard memory as suggested; Quote:
Quote:
Even easier
__________________ Spency. PIC Micro's - Your mind is the limit PIC's and interfacing with other devices - a PIC Basic Guide @ digital-diy.net | |||
| |
| | (permalink) |
| That simple, huh? Thanks so much. I should have been more clear-- I am using a 16f684 microcontroller. Just one more question-- which address would I write the data to? -Omar | |
| |
| | (permalink) |
| It's only that simple if you are using basic. If you are using assembler then copy the routines out of the data sheet - there still pretty simple. You can write to any of the locations from zero to however many bytes of EEPROM are available - 256 in the 684. Mike. | |
| |
| | (permalink) |
| Wow, that seems easy enough, thank you And as for basic, in fact I am using BASIC! Great Cow Basic, to be exact. http://gcbasic.sourceforge.net/ Thanks a lot, Omar | |
| |
| | (permalink) |
| Note that EEPROM has a limited write endurance. It's unlikely you would ever run into endurance problems with user-entered button presses, however for other cases where you may write them more often the write endurance can be a real issue which may limit the lifespan of the product.
__________________ I thought what I'd do was I'd pretend I was one of those deaf-mutes. | |
| |
| | (permalink) |
| This is about 1,000,000 writes, less in some cases
__________________ Spency. PIC Micro's - Your mind is the limit PIC's and interfacing with other devices - a PIC Basic Guide @ digital-diy.net | |
| |
| | (permalink) |
| Oh. Well, I do not think I will exceed that limit-- this is merely me just experimenting with robotics; it isn't going to be in competitions or anything. I just have a few questions. Does the data which I store in the EEPROM get erased when I power off the PIC? Or is it permanent? Is it better to get a few sensor readings and finding the average between them... or just two basic readings ? Thanks, Omar | |
| |
| | (permalink) |
| The EEPROM retains the data when the power is removed. Averaging readings really depends what they are, and what you're trying to do with them. | |
| |
| | (permalink) |
| Whatever you put in the EEPROM should stay there for at least 40 years if you believe the data sheet. I would average a few readings and store that. End of the day you are going to compare against the average of the 2 readings. The actual readings are probably not too important. Mike. | |
| |
| | (permalink) |
| There's normally a limit to the number of write cycles though.
__________________ I also post at the following sites: http://www.stop-microsoft.org http://www.heated-debates.com Screen name: Aloone_Jonez And http://www.silicontronics.com, same screen name as here. | |
| |
| Bookmarks |
| Thread Tools | |
| Display Modes | |
| |
| | ||||
| Title | Starter | Forum | Replies | Latest |
| Need some help with a code provided by ATMEL | ikalogic | Micro Controllers | 1 | 23rd January 2007 03:46 PM |
| Hardcode a PIC by hand? (or 16F74 + par.port.prog = problem) | smilen | Micro Controllers | 15 | 21st November 2005 10:23 AM |
| Oscilloscope storing data software | xmat | General Electronics Chat | 10 | 14th August 2005 07:01 PM |
| Just Joined, Got some bugs I can't find. | Thedoctorisin136 | Micro Controllers | 0 | 1st March 2005 07:07 PM |
| An error in pic16f84a, why? | Zener_Diode | Micro Controllers | 6 | 11th April 2004 03:55 AM |