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 CCS Technical Support

16f877 internal eeprom

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







16f877 internal eeprom
PostPosted: Sat Feb 08, 2003 5:55 am     Reply with quote

HI all
I am trying to write to the internal EEPROM memory on my PIC16f877 (at the moment i am only using MPLAB simulator). I can read the data but not write. When i try to run my program the read works fine then the write brings up the program memory window.
Any suggestions as to what i am doing wrong?
I have copied my program below.
Another question i have is can you write/read the 32bit float numbers??

cheers chris


#DEVICE PIC16F877
#include "C:\Program Files\PICC\Chris programs\eeprom.h"


void main() {
int x,ad,y;
float airspeed;
#byte Float_airspeed = airspeed;

setup_adc_ports(NO_ANALOGS);
setup_adc(ADC_CLOCK_DIV_2);
setup_spi(FALSE);
setup_psp(PSP_DISABLED);
setup_counters(RTCC_INTERNAL,RTCC_DIV_2);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DISABLED,0,1);
setup_ccp1(CCP_OFF);
setup_ccp2(CCP_OFF);

ad=02;
x=16;
airspeed=28.523;
y=read_eeprom(ad);
write_eeprom(ad,x);
___________________________
This message was ported from CCS's old forum
Original Post ID: 11420
Rod Ladwig
Guest







Re: 16f877 internal eeprom
PostPosted: Sat Feb 08, 2003 7:22 am     Reply with quote

:=HI all
:=I am trying to write to the internal EEPROM memory on my PIC16f877 (at the moment i am only using MPLAB simulator). I can read the data but not write. When i try to run my program the read works fine then the write brings up the program memory window.
:=Any suggestions as to what i am doing wrong?
:=I have copied my program below.
:=Another question i have is can you write/read the 32bit float numbers??
:=
:=cheers chris
:=
:=
:=#DEVICE PIC16F877
:=#include "C:\Program Files\PICC\Chris programs\eeprom.h"
:=
:=
:=void main() {
:= int x,ad,y;
:= float airspeed;
:= #byte Float_airspeed = airspeed;
:=
:= setup_adc_ports(NO_ANALOGS);
:= setup_adc(ADC_CLOCK_DIV_2);
:= setup_spi(FALSE);
:= setup_psp(PSP_DISABLED);
:= setup_counters(RTCC_INTERNAL,RTCC_DIV_2);
:= setup_timer_1(T1_DISABLED);
:= setup_timer_2(T2_DISABLED,0,1);
:= setup_ccp1(CCP_OFF);
:= setup_ccp2(CCP_OFF);
:=
:= ad=02;
:= x=16;
:= airspeed=28.523;
:= y=read_eeprom(ad);
:= write_eeprom(ad,x);


/*******************************************************************************/
/* function
/* Read and write 4 bytes to EEProm
/*******************************************************************************/
// n is an offset into the eeprom. For floats
// you must increment it by 4. For example if
// the first float is at 0 the second one should
// be at 4 and the third at 8.

void WRITE_FLOAT_EEPROM(long int n, float data) {
int i;

for (i = 0; i < 4; i++)
write_eeprom(i + n, *(&data + i) ) ;
}

float READ_FLOAT_EEPROM(long int n) {
int i;
float data;

for (i = 0; i < 4; i++)
*(&data + i) = read_eeprom(i + n);

return(data);
}
___________________________
This message was ported from CCS's old forum
Original Post ID: 11422
Chris_1982
Guest







Re: 16f877 internal eeprom
PostPosted: Sat Feb 08, 2003 8:14 am     Reply with quote

Thanks for that code Rod thats realy useful I can now read float numbers.
BUT i still can not write values to the memory.
Do you or anyone else out there know whether i should be able to use the MPLAB simulator to run this code and see the results in the EEPROM memory window? (I know that i could when i have produced the equivalent code in assembly )
Thanks again
Chris


:=:=HI all
:=:=I am trying to write to the internal EEPROM memory on my PIC16f877 (at the moment i am only using MPLAB simulator). I can read the data but not write. When i try to run my program the read works fine then the write brings up the program memory window.
:=:=Any suggestions as to what i am doing wrong?
:=:=I have copied my program below.
:=:=Another question i have is can you write/read the 32bit float numbers??
:=:=
:=:=cheers chris
:=:=
:=:=
:=:=#DEVICE PIC16F877
:=:=#include "C:\Program Files\PICC\Chris programs\eeprom.h"
:=:=
:=:=
:=:=void main() {
:=:= int x,ad,y;
:=:= float airspeed;
:=:= #byte Float_airspeed = airspeed;
:=:=
:=:= setup_adc_ports(NO_ANALOGS);
:=:= setup_adc(ADC_CLOCK_DIV_2);
:=:= setup_spi(FALSE);
:=:= setup_psp(PSP_DISABLED);
:=:= setup_counters(RTCC_INTERNAL,RTCC_DIV_2);
:=:= setup_timer_1(T1_DISABLED);
:=:= setup_timer_2(T2_DISABLED,0,1);
:=:= setup_ccp1(CCP_OFF);
:=:= setup_ccp2(CCP_OFF);
:=:=
:=:= ad=02;
:=:= x=16;
:=:= airspeed=28.523;
:=:= y=read_eeprom(ad);
:=:= write_eeprom(ad,x);
:=
:=
:=/*******************************************************************************/
:=/* function
:=/* Read and write 4 bytes to EEProm
:=/*******************************************************************************/
:=// n is an offset into the eeprom. For floats
:=// you must increment it by 4. For example if
:=// the first float is at 0 the second one should
:=// be at 4 and the third at 8.
:=
:=void WRITE_FLOAT_EEPROM(long int n, float data) {
:= int i;
:=
:= for (i = 0; i < 4; i++)
:= write_eeprom(i + n, *(&data + i) ) ;
:=}
:=
:=float READ_FLOAT_EEPROM(long int n) {
:= int i;
:= float data;
:=
:= for (i = 0; i < 4; i++)
:= *(&data + i) = read_eeprom(i + n);
:=
:= return(data);
:=}
___________________________
This message was ported from CCS's old forum
Original Post ID: 11423
Shane Rowell
Guest







Re: 16f877 internal eeprom
PostPosted: Sat Feb 08, 2003 4:44 pm     Reply with quote

I am away from my office, but one thing comes to mind. Have you enabled the fuse that allows for EE write?

Shane


:=Thanks for that code Rod thats realy useful I can now read float numbers.
:=BUT i still can not write values to the memory.
:=Do you or anyone else out there know whether i should be able to use the MPLAB simulator to run this code and see the results in the EEPROM memory window? (I know that i could when i have produced the equivalent code in assembly )
:=Thanks again
:=Chris
:=
:=
:=:=:=HI all
:=:=:=I am trying to write to the internal EEPROM memory on my PIC16f877 (at the moment i am only using MPLAB simulator). I can read the data but not write. When i try to run my program the read works fine then the write brings up the program memory window.
:=:=:=Any suggestions as to what i am doing wrong?
:=:=:=I have copied my program below.
:=:=:=Another question i have is can you write/read the 32bit float numbers??
:=:=:=
:=:=:=cheers chris
:=:=:=
:=:=:=
:=:=:=#DEVICE PIC16F877
:=:=:=#include "C:\Program Files\PICC\Chris programs\eeprom.h"
:=:=:=
:=:=:=
:=:=:=void main() {
:=:=:= int x,ad,y;
:=:=:= float airspeed;
:=:=:= #byte Float_airspeed = airspeed;
:=:=:=
:=:=:= setup_adc_ports(NO_ANALOGS);
:=:=:= setup_adc(ADC_CLOCK_DIV_2);
:=:=:= setup_spi(FALSE);
:=:=:= setup_psp(PSP_DISABLED);
:=:=:= setup_counters(RTCC_INTERNAL,RTCC_DIV_2);
:=:=:= setup_timer_1(T1_DISABLED);
:=:=:= setup_timer_2(T2_DISABLED,0,1);
:=:=:= setup_ccp1(CCP_OFF);
:=:=:= setup_ccp2(CCP_OFF);
:=:=:=
:=:=:= ad=02;
:=:=:= x=16;
:=:=:= airspeed=28.523;
:=:=:= y=read_eeprom(ad);
:=:=:= write_eeprom(ad,x);
:=:=
:=:=
:=:=/*******************************************************************************/
:=:=/* function
:=:=/* Read and write 4 bytes to EEProm
:=:=/*******************************************************************************/
:=:=// n is an offset into the eeprom. For floats
:=:=// you must increment it by 4. For example if
:=:=// the first float is at 0 the second one should
:=:=// be at 4 and the third at 8.
:=:=
:=:=void WRITE_FLOAT_EEPROM(long int n, float data) {
:=:= int i;
:=:=
:=:= for (i = 0; i < 4; i++)
:=:= write_eeprom(i + n, *(&data + i) ) ;
:=:=}
:=:=
:=:=float READ_FLOAT_EEPROM(long int n) {
:=:= int i;
:=:= float data;
:=:=
:=:= for (i = 0; i < 4; i++)
:=:= *(&data + i) = read_eeprom(i + n);
:=:=
:=:= return(data);
:=:=}
___________________________
This message was ported from CCS's old forum
Original Post ID: 11432
chris_1982
Guest







Re: 16f877 internal eeprom
PostPosted: Mon Feb 10, 2003 4:42 am     Reply with quote

I have now checked the program running on the PIC as well as the sim and niether work!! I have tried both with the statement #FUSES NOCPD.

What am I doing wrong ????

cheers chris



:=I am away from my office, but one thing comes to mind. Have you enabled the fuse that allows for EE write?
:=
:=Shane
:=
:=
:=:=Thanks for that code Rod thats realy useful I can now read float numbers.
:=:=BUT i still can not write values to the memory.
:=:=Do you or anyone else out there know whether i should be able to use the MPLAB simulator to run this code and see the results in the EEPROM memory window? (I know that i could when i have produced the equivalent code in assembly )
:=:=Thanks again
:=:=Chris
:=:=
:=:=
:=:=:=:=HI all
:=:=:=:=I am trying to write to the internal EEPROM memory on my PIC16f877 (at the moment i am only using MPLAB simulator). I can read the data but not write. When i try to run my program the read works fine then the write brings up the program memory window.
:=:=:=:=Any suggestions as to what i am doing wrong?
:=:=:=:=I have copied my program below.
:=:=:=:=Another question i have is can you write/read the 32bit float numbers??
:=:=:=:=
:=:=:=:=cheers chris
:=:=:=:=
:=:=:=:=
:=:=:=:=#DEVICE PIC16F877
:=:=:=:=#include "C:\Program Files\PICC\Chris programs\eeprom.h"
:=:=:=:=
:=:=:=:=
:=:=:=:=void main() {
:=:=:=:= int x,ad,y;
:=:=:=:= float airspeed;
:=:=:=:= #byte Float_airspeed = airspeed;
:=:=:=:=
:=:=:=:= setup_adc_ports(NO_ANALOGS);
:=:=:=:= setup_adc(ADC_CLOCK_DIV_2);
:=:=:=:= setup_spi(FALSE);
:=:=:=:= setup_psp(PSP_DISABLED);
:=:=:=:= setup_counters(RTCC_INTERNAL,RTCC_DIV_2);
:=:=:=:= setup_timer_1(T1_DISABLED);
:=:=:=:= setup_timer_2(T2_DISABLED,0,1);
:=:=:=:= setup_ccp1(CCP_OFF);
:=:=:=:= setup_ccp2(CCP_OFF);
:=:=:=:=
:=:=:=:= ad=02;
:=:=:=:= x=16;
:=:=:=:= airspeed=28.523;
:=:=:=:= y=read_eeprom(ad);
:=:=:=:= write_eeprom(ad,x);
:=:=:=
:=:=:=
:=:=:=/*******************************************************************************/
:=:=:=/* function
:=:=:=/* Read and write 4 bytes to EEProm
:=:=:=/*******************************************************************************/
:=:=:=// n is an offset into the eeprom. For floats
:=:=:=// you must increment it by 4. For example if
:=:=:=// the first float is at 0 the second one should
:=:=:=// be at 4 and the third at 8.
:=:=:=
:=:=:=void WRITE_FLOAT_EEPROM(long int n, float data) {
:=:=:= int i;
:=:=:=
:=:=:= for (i = 0; i < 4; i++)
:=:=:= write_eeprom(i + n, *(&data + i) ) ;
:=:=:=}
:=:=:=
:=:=:=float READ_FLOAT_EEPROM(long int n) {
:=:=:= int i;
:=:=:= float data;
:=:=:=
:=:=:= for (i = 0; i < 4; i++)
:=:=:= *(&data + i) = read_eeprom(i + n);
:=:=:=
:=:=:= return(data);
:=:=:=}
___________________________
This message was ported from CCS's old forum
Original Post ID: 11470
Nigel Steed
Guest







Re: 16f877 internal eeprom
PostPosted: Mon Feb 10, 2003 7:05 am     Reply with quote

Hi Chris,

I have had this too, and contacted CCS. I was using compiler version 2.13 and they said it was very old and not stable. They suggested upgrading to version 3.13 and now all is well.

Best Wishes

Nigel
___________________________
This message was ported from CCS's old forum
Original Post ID: 11474
Nigel Steed
Guest







Re: 16f877 internal eeprom
PostPosted: Tue Feb 11, 2003 6:54 am     Reply with quote

Hi Chris,

I had the same thing, and contacted CCS about it. They said I was using an old compiler version ( 2.13 ) and they suggested upgrading to the latest version. This has now cured the problem.

Hope this helps

Best Regards

Nigel

:=I have now checked the program running on the PIC as well as the sim and niether work!! I have tried both with the statement #FUSES NOCPD.
:=
:=What am I doing wrong ????
:=
:=cheers chris
:=
:=
:=
:=:=I am away from my office, but one thing comes to mind. Have you enabled the fuse that allows for EE write?
:=:=
:=:=Shane
:=:=
:=:=
:=:=:=Thanks for that code Rod thats realy useful I can now read float numbers.
:=:=:=BUT i still can not write values to the memory.
:=:=:=Do you or anyone else out there know whether i should be able to use the MPLAB simulator to run this code and see the results in the EEPROM memory window? (I know that i could when i have produced the equivalent code in assembly )
:=:=:=Thanks again
:=:=:=Chris
:=:=:=
:=:=:=
:=:=:=:=:=HI all
:=:=:=:=:=I am trying to write to the internal EEPROM memory on my PIC16f877 (at the moment i am only using MPLAB simulator). I can read the data but not write. When i try to run my program the read works fine then the write brings up the program memory window.
:=:=:=:=:=Any suggestions as to what i am doing wrong?
:=:=:=:=:=I have copied my program below.
:=:=:=:=:=Another question i have is can you write/read the 32bit float numbers??
:=:=:=:=:=
:=:=:=:=:=cheers chris
:=:=:=:=:=
:=:=:=:=:=
:=:=:=:=:=#DEVICE PIC16F877
:=:=:=:=:=#include "C:\Program Files\PICC\Chris programs\eeprom.h"
:=:=:=:=:=
:=:=:=:=:=
:=:=:=:=:=void main() {
:=:=:=:=:= int x,ad,y;
:=:=:=:=:= float airspeed;
:=:=:=:=:= #byte Float_airspeed = airspeed;
:=:=:=:=:=
:=:=:=:=:= setup_adc_ports(NO_ANALOGS);
:=:=:=:=:= setup_adc(ADC_CLOCK_DIV_2);
:=:=:=:=:= setup_spi(FALSE);
:=:=:=:=:= setup_psp(PSP_DISABLED);
:=:=:=:=:= setup_counters(RTCC_INTERNAL,RTCC_DIV_2);
:=:=:=:=:= setup_timer_1(T1_DISABLED);
:=:=:=:=:= setup_timer_2(T2_DISABLED,0,1);
:=:=:=:=:= setup_ccp1(CCP_OFF);
:=:=:=:=:= setup_ccp2(CCP_OFF);
:=:=:=:=:=
:=:=:=:=:= ad=02;
:=:=:=:=:= x=16;
:=:=:=:=:= airspeed=28.523;
:=:=:=:=:= y=read_eeprom(ad);
:=:=:=:=:= write_eeprom(ad,x);
:=:=:=:=
:=:=:=:=
:=:=:=:=/*******************************************************************************/
:=:=:=:=/* function
:=:=:=:=/* Read and write 4 bytes to EEProm
:=:=:=:=/*******************************************************************************/
:=:=:=:=// n is an offset into the eeprom. For floats
:=:=:=:=// you must increment it by 4. For example if
:=:=:=:=// the first float is at 0 the second one should
:=:=:=:=// be at 4 and the third at 8.
:=:=:=:=
:=:=:=:=void WRITE_FLOAT_EEPROM(long int n, float data) {
:=:=:=:= int i;
:=:=:=:=
:=:=:=:= for (i = 0; i < 4; i++)
:=:=:=:= write_eeprom(i + n, *(&data + i) ) ;
:=:=:=:=}
:=:=:=:=
:=:=:=:=float READ_FLOAT_EEPROM(long int n) {
:=:=:=:= int i;
:=:=:=:= float data;
:=:=:=:=
:=:=:=:= for (i = 0; i < 4; i++)
:=:=:=:= *(&data + i) = read_eeprom(i + n);
:=:=:=:=
:=:=:=:= return(data);
:=:=:=:=}
___________________________
This message was ported from CCS's old forum
Original Post ID: 11522
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