|
|
View previous topic :: View next topic |
Author |
Message |
deepakomanna
Joined: 06 Mar 2007 Posts: 92 Location: Pune,India
|
int32 data eeprom write problem |
Posted: Wed Jun 20, 2007 11:27 pm |
|
|
Dear Sir,
here i am using 16f913, MPLAB 7.5 Ver. & CCS PCM C Compiler, Version 3.249, 34534.
HERE i am storing the int32 data into eeprom location from 0x00 in every 1 sec.And reading the data
i.e.number.And display on the LCD.But it shows value 6553.5 only.here i want to store the data
from 0 to 99999.9.So plz tell me where i m wrong.
here i am testing this code using ICD 2.below is my soft code.
Code: | #include<16F913.h>
//#include<internal_eeprom.c>
#fuses INTRC_IO,NOWDT,PUT,/*****/MCLR,/****/NOPROTECT,NOCPD,NOBROWNOUT,NOIESO,NOFCMEN //external MCLR bcz of MPLAB ICD2
#use delay(clock=8000000)
/////////////////////////////////////////////////////////////////////////////////////////
// LCD Configuration //
/////////////////////////////////////////////////////////////////////////////////////////
// Digit segments A B C D E F G DP
// b7 b6 b5 b4 b3 b2 b1 b0
#define DIGIT1 COM3+6, COM2+6, COM0+6, COM1+6, COM0+5, COM3+5, COM2+5, COM1+5 // DISPALYS FROM RIGHT SIDE
#define DIGIT2 COM3+7, COM2+7, COM0+7, COM1+7, COM0+4, COM3+4, COM2+4 // DISPALYS FROM RIGHT SIDE
#define DIGIT3 COM3+8, COM2+8, COM0+8, COM1+8, COM0+3, COM3+3, COM2+3 // DISPALYS FROM RIGHT SIDE
#define DIGIT4 COM3+9, COM2+9, COM0+9, COM1+9, COM0+2, COM3+2, COM2+2 // DISPALYS FROM RIGHT SIDE
#define DIGIT5 COM3+11, COM2+11, COM0+11, COM1+11, COM0+1, COM3+1, COM2+1 // DISPALYS FROM RIGHT SIDE
#define DIGIT6 COM3+12, COM2+12, COM0+12, COM1+12, COM0+0, COM3+0, COM2+0 // DISPALYS FROM RIGHT SIDE
#define VLCD_ENABLE 0x10
#define BLANK 0
#define DOT 1
#define eeprom_address 0
//character 0 1 2 3 4 5 6 7 8 9
byte const Digit_Map[10] = {0xFC,0x60,0xDA,0xF2,0x66,0xB6,0xBE,0xE0,0xFE,0xF6};
byte lcd_pos;
byte segments;
void init_CPU();
int32 ee_read32(int16);
void ee_write32(int16,int32);
unsigned int16 sec_counter = 0;
static unsigned int16 min_count = 0;
static long number = 0;
int1 flag = 1;
int1 flag2 = 0;
int8 i = 0;
int8 sec_count;
void lcd_putc(char c)
{
if(c=='\f')
lcd_pos=0;
else {
if((c>='0')&&(c<='9'))
{
segments=Digit_Map[c-'0'];
}
else
segments=BLANK;
switch(lcd_pos)
{
case 1: lcd_symbol(segments,DIGIT6); break; // fill 1s place
case 2: lcd_symbol(segments,DIGIT5); break; // fill 10s place
case 3: lcd_symbol(segments,DIGIT4); break; // fill 100s place
case 4 : lcd_symbol(segments,DIGIT3); break; // fill 1000s place
case 5 :if(flag2 == 1)
lcd_symbol(segments,DIGIT2); break; // fill 10000splace
case 6 :
if((flag == 1))
{
lcd_symbol((DOT |segments),DIGIT1); // fill 100000s place
}
else
{
lcd_symbol(segments,DIGIT1);
}
if(number <10)
{
flag2 = 0;
lcd_symbol(Digit_Map[i],DIGIT2);
}
else
flag2 = 1;
break;
}
}
lcd_pos++;
}
#int_ccp1
void ccp1_isr(void)
{
sec_counter++;
if(sec_counter >= 337)
{
flag =~flag; // compliment flag for decimal point.
sec_counter = 0;
min_count++;
if(min_count == 30)
{
number++;
if(number == 999999)
number = 0;
min_count = 0;
}
}
//set_timer1(0);
}
#INT_TIMER0
void timer0_isr(void)
{
// interrupt routine for 25 msec
sec_count++;
if(sec_count == 40)
{
//write data every 1 sec to eeprom.
DISABLE_INTERRUPTS(GLOBAL);
ee_write32(eeprom_address, number); //write data to EEPROM loc 0x00
ENABLE_INTERRUPTS(GLOBAL);
sec_count = 0;
}
}
void main()
{
init_CPU();
while(TRUE)
{
number = ee_read32(eeprom_address); //read data from EEPROM loc 0x00
printf(lcd_putc,"\f%6lu",number);
}
}
int32 ee_read32(int16 base_address)
{
char i;
int32 data_read;
for(i=0; i<4; i++)
*(&data_read+i) = read_eeprom(base_address+i);
return (data_read);
}
void ee_write32(int16 base_address ,int32 data)
{
char i;
for(i=0; i<4; i++)
write_eeprom(base_address+i,*(&data+i));
}
void init_CPU()
{
/************** PORT SETTINGS ****************/
PORT_B_PULLUPS(0XC0); // RB7 & RB6 i/p for programming devices.
SET_TRIS_A(0X80); //
SET_TRIS_B(0XC0);
SET_TRIS_C(0X27); //VLCD 1,2,3 i/p
SET_TRIS_E(0X08); // RE3 i/p for programming the device.
/*************** LCD SETTINGS ********************/
SETUP_LCD( LCD_MUX14 |LCD_INTRC|VLCD_ENABLE, 2);
/**************** COMPARATOR SETTINGS ***************/
SETUP_COMPARATOR(NC_NC_NC_NC);
/**************** INTERRUPT SETTINGS *****************/
ENABLE_INTERRUPTS(GLOBAL);
//ENABLE_INTERRUPTS(INT_TIMER1); //enable timer1 interrupt
ENABLE_INTERRUPTS(INT_TIMER0); //enable timer1 interrupt
SETUP_TIMER_0(RTCC_INTERNAL|RTCC_DIV_256);
SET_TIMER0(61); // timer0 interrupt for 25 msec.
/***************************************************************/
set_timer1(0);
setup_ccp1(CCP_CAPTURE_RE); //Capture on rising edge
clear_interrupt(INT_CCP1);
enable_interrupts(INT_CCP1);
setup_timer_1(T1_INTERNAL | T1_DIV_BY_8);
}
|
_________________ Thank You,
With Best Regards,
Deepak. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Thu Jun 21, 2007 1:04 am |
|
|
Look closely at your data types. For most of your data types you're
using the CCS names, which show the number of bits in the type. But in
one important case, you're using the traditional C name. And, you've
made the assumption that the size of that data type in CCS is the same
as in MSVC++. It's not. It's smaller.
This number in your post is an important clue:
Quote: | But it shows value 6553.5 only |
Take out the decimal point, so it reads as 5 digits. That's the maximum
size of a certain data type. Your intention was to make it a larger type.
The problem occurred, and was not noticed by you, because you used the
traditional type name in one line of your code. |
|
|
deepakomanna
Joined: 06 Mar 2007 Posts: 92 Location: Pune,India
|
int32 data eeprom write problem |
Posted: Thu Jun 21, 2007 2:51 am |
|
|
Thanks for reply,
As u told i made change is,
int32 number = 0;
So now display is showing 42949.6,it's ok. I undestand the data range.
but here i m incrementing the data i.e. number++;(see in ccp1 interrupt) from 0 to 999999
And,here i want to display data from 0 to 99999.9.
not only 42949.6
Quote: | // ccp1 interrupt is used to measure the count between two rising pulses. Here we are connected frequency generator to pin no 16 of 16f913 and freq. input is 337Hz. |
_________________ Thank You,
With Best Regards,
Deepak. |
|
|
Ttelmah Guest
|
|
Posted: Thu Jun 21, 2007 2:55 am |
|
|
Beware also though, how long the EEPROM will last...
You are writing once per second. There are 86400 seconds in a day. The chip has a quoted EEPROM write 'life', of typically 1E6 cycles, and a 'worst case', of 1E5 cycles. The latter is only just over one day of use like this....
There have been a lot of solutions posted here in the past to avoid this sort of problem, but you need to think now about this, before you are 'bitten' by the chip failing.
Best Wishes |
|
|
deepakomanna
Joined: 06 Mar 2007 Posts: 92 Location: Pune,India
|
int32 data eeprom write problem |
Posted: Thu Jun 21, 2007 11:26 pm |
|
|
Dear Sir,
if i define the statement,
Quote: | ee_write32(eeprom_address, number);
| in the #INT_TIMER0 interrupt routine,
no data is written in EEPROM,but if i declare the same stament ,where i am incrementing data i.e. number++; the data is written in EEPROM
Code: | if(min_count == 30)
{
number++;
ee_write32(eeprom_address, number);
if(number == 999999)
number = 0;
min_count = 0;
}
|
Here the number is declared static global Quote: | static int32 number = 0;
|
So,if any change in data that should affect.So i am not getting correct result ?
Plz reffer posted code with change as u suggested. _________________ Thank You,
With Best Regards,
Deepak. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Fri Jun 22, 2007 12:25 pm |
|
|
Quote: | #INT_TIMER0
void timer0_isr(void)
{
sec_count++;
if(sec_count == 40)
{
//write data every 1 sec to eeprom.
DISABLE_INTERRUPTS(GLOBAL);
ee_write32(eeprom_address, number);
ENABLE_INTERRUPTS(GLOBAL);
sec_count = 0;
}
} |
Don't disable/enable global interrupts inside an interrupt service routine.
See this post:
http://www.ccsinfo.com/forum/viewtopic.php?t=31091&start=1&highlight=dangerous |
|
|
deepakomanna
Joined: 06 Mar 2007 Posts: 92 Location: Pune,India
|
EEPROM data how to read |
Posted: Sat Jun 23, 2007 12:27 am |
|
|
Thankes Master Programmer,
I was wested so much time for this,
One little query,
How to see Internal EEPROM Data by using ICD 2 _________________ Thank You,
With Best Regards,
Deepak. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sun Jun 24, 2007 1:51 pm |
|
|
Go to the View menu in MPLAB, and select EEPROM. This will open a
window to show the internal data eeprom.
The Help file in MPLAB for the ICD2 says this:
Quote: |
If data EEPROM is written during program execution, the EEPROM window
of MPLAB IDE will not reflect the changes. You will need to perform a
READ of EEPROM memory in order to update the values in the window |
I was able to view the updated contents of the EEPROM by right-clicking
with my mouse on the EEPROM window. Then I select "Refresh" and
it shows the new data (after a write to eeprom operation). In that
case, I didn't need to do a read operation in the program code, as
they suggest above. |
|
|
|
|
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
|