|
|
View previous topic :: View next topic |
Author |
Message |
Chris_1982 Guest
|
16f877 internal eeprom |
Posted: Sat Feb 08, 2003 5:55 am |
|
|
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 |
Posted: Sat Feb 08, 2003 7:22 am |
|
|
:=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 |
Posted: Sat Feb 08, 2003 8:14 am |
|
|
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 |
Posted: Sat Feb 08, 2003 4:44 pm |
|
|
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 |
Posted: Mon Feb 10, 2003 4:42 am |
|
|
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 |
Posted: Mon Feb 10, 2003 7:05 am |
|
|
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 |
Posted: Tue Feb 11, 2003 6:54 am |
|
|
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 |
|
|
|
|
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
|