CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug Reports on this forum. Send them to support@ccsinfo.com

Programming a EEPROM

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Lihua Hu
Guest







Programming a EEPROM
PostPosted: Mon Jan 13, 2003 7:36 am     Reply with quote

Hi,

I have a question. Please would anybody tell me how to program an EEPROM in 16F877.

I can program EEPROM using a keypad and i2c bus byte by byte. But if the whole range of 255 bytes need to be program, it will take a long time and mistakes are easily made. What is a more efficient way to program a block of memory in the EEPROM?

I am using CCS 3.068 and ICD. Please help me.

Thanks
___________________________
This message was ported from CCS's old forum
Original Post ID: 10646
TSchultz



Joined: 08 Sep 2003
Posts: 66
Location: Toronto, Canada

View user's profile Send private message

RE: Programming a EEPROM
PostPosted: Mon Jan 13, 2003 8:06 am     Reply with quote

:=Hi,
:=
:=I have a question. Please would anybody tell me how to program an EEPROM in 16F877.
:=
:=I can program EEPROM using a keypad and i2c bus byte by byte. But if the whole range of 255 bytes need to be program, it will take a long time and mistakes are easily made. What is a more efficient way to program a block of memory in the EEPROM?
:=
:=I am using CCS 3.068 and ICD. Please help me.
:=
:=Thanks

Use the #rom directive to put your "default values", from page 47 in the manual;
#rom 0x2100 = {1,2,3,4,5,6,7,8}

This will place 1 to 8 in the correspomding locations in EEPROM of 0 to 7.

In the PIC16F877 the first byte of the EEPROM is 0x2100, and the last byte is 0x21FF.

The #rom directive adds the bytes to the generated HEX file that is used to program the parts. The same method (different addresses) can be used to place a lookup-table in the FLASH as well.

-Troy
___________________________
This message was ported from CCS's old forum
Original Post ID: 10648
Lihua Hu
Guest







Re: RE: Programming a EEPROM
PostPosted: Mon Jan 13, 2003 8:52 am     Reply with quote

Hi Troy,

Thanks for you enlightment. This is a good way if you only program a few pics and if you have difault values to put in. But my possible problem is there may be a large number of chips need to be programed with same code but with no default valuses for the eeprommes. Is there a better way to load a block of data into the chip after it has been programed?

Please also tell me a little more about the looking up tables. I don't know how to set it up and use them. I think it might be very usefull for me. Thanks again.

Lihua
___________________________
This message was ported from CCS's old forum
Original Post ID: 10650
TSchultz



Joined: 08 Sep 2003
Posts: 66
Location: Toronto, Canada

View user's profile Send private message

RE: Programming a EEPROM
PostPosted: Mon Jan 13, 2003 10:16 am     Reply with quote

:=Hi Troy,
:=
:=Thanks for you enlightment. This is a good way if you only program a few pics and if you have difault values to put in. But my possible problem is there may be a large number of chips need to be programed with same code but with no default valuses for the eeprommes. Is there a better way to load a block of data into the chip after it has been programed?
:=
:=Please also tell me a little more about the looking up tables. I don't know how to set it up and use them. I think it might be very usefull for me. Thanks again.
:=
:=Lihua

Could you elaborate a bit on what these bytes are that need to be put in the EEPROM. If each device has completely different values then you will need to incorporate some kind on upload mechanism in your code/device. Do you have a serial interface in the design so you could use a terminal program?

With a bit more information on what you want to accomplish and what your design would permit it would be easier to make recommendations.

As an example; in many of my designs I have a multi-drop RS-485 interface and after programming I go through an initialization process. This is were I actually upload various control params that are stored in the EEPROM. I have both an upload and download mechanism built in the command set I have for the RS-485 protocol I use. With the help of a custom written program in Visual Basic I am then able to custom tailor the device by loading a particular configuration set into the EEPROM.

-Troy
___________________________
This message was ported from CCS's old forum
Original Post ID: 10653
Chang-Huei Wu
Guest







Re: RE: Programming a EEPROM
PostPosted: Mon Jan 13, 2003 1:05 pm     Reply with quote

to load a block of data into the chip after it has been programed?

If what you want if the internal DATA EEPROM of PIC ...
then ... you may try ... bootloader ...

melabs Loader (with MCU) USD$ 39.95
<a href="http://www.melabs.com/products/loader.htm" TARGET="_blank">http://www.melabs.com/products/loader.htm</a>

there are many free bootloader, but I am not sure
if they can download eeprom.

best wishes
___________________________
This message was ported from CCS's old forum
Original Post ID: 10656
Lihua Hu
Guest







Re: RE: Programming a EEPROM
PostPosted: Tue Jan 14, 2003 5:47 am     Reply with quote

Hi Troy,

You are obviously a very experienced CCS user. But I am not clever enough to explore the full potential of the compiler so I need to be educated more .

From my understanding of the software and the pic's hardware, I only use the eeprom for keeping some data, which can be changed by the customer after it has been coded and will be retained data when the power is lost. I don't know how to use it for programming and can't see the benifit of it. The data been put in are very much like a list of names or addresses. When a command is received from the keypad, or an input from the i/o pin is detected then a name in the list will be displaied and send out through the RS232 port. You can see why there is no default values because each customer would like to put in their own list. But if the list is large enough to fill all the 256 bytes it will be difficult to do it and I don't think anybody like to sit and do this type of job all day.

In my design, there is a RS232 port which is used to communicat to the RS485 bus with the other pics. But I don't know how to use is to upload or download program or data and I don't know how to organise a multi-drop port. There is one more thing, will this function, which is not directly for carrying out the task the pic is designed to do, use too much of the limited program memory resources?

Thank you for the help

Lihua
___________________________
This message was ported from CCS's old forum
Original Post ID: 10680
TSchultz



Joined: 08 Sep 2003
Posts: 66
Location: Toronto, Canada

View user's profile Send private message

RE: Programming a EEPROM
PostPosted: Tue Jan 14, 2003 2:17 pm     Reply with quote

:=Hi Troy,
:=
:=You are obviously a very experienced CCS user. But I am not clever enough to explore the full potential of the compiler so I need to be educated more .
:=
:=From my understanding of the software and the pic's hardware, I only use the eeprom for keeping some data, which can be changed by the customer after it has been coded and will be retained data when the power is lost. I don't know how to use it for programming and can't see the benifit of it. The data been put in are very much like a list of names or addresses. When a command is received from the keypad, or an input from the i/o pin is detected then a name in the list will be displaied and send out through the RS232 port. You can see why there is no default values because each customer would like to put in their own list. But if the list is large enough to fill all the 256 bytes it will be difficult to do it and I don't think anybody like to sit and do this type of job all day.
:=
:=In my design, there is a RS232 port which is used to communicat to the RS485 bus with the other pics. But I don't know how to use is to upload or download program or data and I don't know how to organise a multi-drop port. There is one more thing, will this function, which is not directly for carrying out the task the pic is designed to do, use too much of the limited program memory resources?
:=
:=Thank you for the help
:=
:=Lihua

Ok, since you have a serial interface then it should be fairly easy to handle the upload of the values to EEPROM. The problem I have is that you say you are using an RS-232 imnterface to communicate with other PICS on a RS-485 interface, this will not work reliably and will most likely cause problems. Are you going through some form of clevel conversion?


-Troy
___________________________
This message was ported from CCS's old forum
Original Post ID: 10696
Lihua Hu
Guest







Re: RE: Programming a EEPROM
PostPosted: Wed Jan 15, 2003 4:05 am     Reply with quote

Hi Troy,

In my design, the series port is connected to a RS485 chip as suggested in the CCS manu. Then a group of device is communicat with each other. It has been proven that the communication is fairly steable and reliable.

However, it is possible for me to reach the series port on chip directly if that is necessary. What is your recommendation?

Lihua
___________________________
This message was ported from CCS's old forum
Original Post ID: 10711
TSchultz



Joined: 08 Sep 2003
Posts: 66
Location: Toronto, Canada

View user's profile Send private message

RE: Programming a EEPROM
PostPosted: Wed Jan 15, 2003 11:29 am     Reply with quote

:=Hi Troy,
:=
:=In my design, the series port is connected to a RS485 chip as suggested in the CCS manu. Then a group of device is communicat with each other. It has been proven that the communication is fairly steable and reliable.
:=
:=However, it is possible for me to reach the series port on chip directly if that is necessary. What is your recommendation?
:=
:=Lihua

OK, since you have a RS-485 interface with the apropriate transceiver hardware, do you also have an established communications prototcol? If so what commands are built into this protocol? If you don't have any communications protocol what were you intending to do with the RS-485 port?

In most of my designs I use a simple protocol which permits me to handle binary packed data. The basic protocol is as follows;

0- BOF
1 - UnitID
2- LEN (number of bytes LEN+CMD+CTRL+databytes)
3- CMD (packet command 0-255)
4- CTRL (command control byte)
variable number of data bytes (binary packed)
+1 FSC
+2 EOF

The FCS is a simple XOR addition of each byte which is usually sufficient for small data packets. A packet is accepted if the following criteria are met;
BOF is detected,
then UnitID must match,
then LEN is read and bytes are captured while calculating FCS,
then after LEN bytes are received XOR the next byte with calculated FCS and if zero then so far everything is OK, the next byte must the the EOF marker.

If any item is incorrect the frame is discarded and I wait until I again see the BOF marker. There is also a time-out counter handled where I must see the completed packed with this time-out or I also reset the whole process.

The code to handle this protocol is quite straight forward and I have had very good luck with this protocol.

I then handle the command received along with the data payload, and then rely to the packet. Things are much easier if you know you are always in a master-slave environments as opposed to a multi-master one.

If you want some help with this, or another protocol you can email me directly;
tschultz@canada.com

-Troy
___________________________
This message was ported from CCS's old forum
Original Post ID: 10722
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group