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

problem by interrupt timer and read external eeprom
Goto page Previous  1, 2
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
mahdifahime



Joined: 05 Jan 2013
Posts: 22

View user's profile Send private message

PostPosted: Wed Apr 03, 2013 4:43 am     Reply with quote

no anybody other way ? the way is slowly speed
Ttelmah



Joined: 11 Mar 2010
Posts: 19831

View user's profile Send private message

PostPosted: Wed Apr 03, 2013 4:51 am     Reply with quote

Have you tried just using 5uSec.
As I said in my earlier post, if you are running the chip at 3.3v (you haven't told us whether this is the case), it requires 4.74uSec between transactions. So 5uSec should be enough.

Best Wishes
mahdifahime



Joined: 05 Jan 2013
Posts: 22

View user's profile Send private message

PostPosted: Wed Apr 03, 2013 5:01 am     Reply with quote

i can't running the chip at 3.3v . i can running chip just at 5V
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Wed Apr 03, 2013 5:25 am     Reply with quote

mahdifahime wrote:
i can't running the chip at 3.3v . i can running chip just at 5V
Good. because at 3.3V the chip can't run at 20MHz.
5V and 20MHz is OK.

Code:
for (i=adress;i<1023;i+=2)
As you are comparing 3 bytes at a time, this should be '+3' instead of '+2'.

Note that in the CCS compiler you don't have to set the TRIS registers, the compiler will do this for you on every input and output instruction.

Please post your most recent program:
- Complete (so we can copy/paste)
- with correct indentation (only 1 instruction at a line, not two '}' characters at a line, etc).


Post your compiler version number.
mahdifahime



Joined: 05 Jan 2013
Posts: 22

View user's profile Send private message

PostPosted: Wed Apr 03, 2013 5:49 am     Reply with quote

ckielstra wrote:

Please post your most recent program:
- Complete (so we can copy/paste)
- with correct indentation (only 1 instruction at a line, not two '}' characters at a line, etc).


Post your compiler version number.


the program for test read from external eeprom
Code:

#include <16f72.h>

#use delay (crystal=20Mhz)
#fuses hs,NOWDT,BROWNOUT,PROTECT
#define EEPROM_SDA  PIN_C4
#define EEPROM_SCL  PIN_C3
#define led pin_c5
#use i2c(master,SDA=PIN_C4,SCL=PIN_C3)
#include <2408.c>


int8 tick;

 
  #int_timer2
  void timer2_isr() { 
  if(++tick>=50){
  tick=0;
  output_toggle(led);
  }
  }
 
   void main(){output_b(0b0);
   setup_timer_2 ( T2_DIV_BY_16,55,16);
   enable_interrupts(INT_timer2);
   enable_interrupts(GLOBAL);
   set_tris_b(0b00000101);
   set_tris_a(0b0000011);
   int16 i;
   int8 r3,r2,r1,byte1,byte2,byte3;
   int1 gg=0;
   
    while(true){
 
  for (i=0;i<1023;i+=2){
  i++;
  r3=read_ext_eeprom(i);
  r2=read_ext_eeprom(i+1);
  r1=read_ext_eeprom(i+2);
  if (byte3==r3&&byte2==r2&&byte1==r1){i=1024;gg=1;}}
  }}


compiler version 4.130
mahdifahime



Joined: 05 Jan 2013
Posts: 22

View user's profile Send private message

PostPosted: Thu Apr 04, 2013 5:45 am     Reply with quote

not idea for problem?
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Sun Apr 07, 2013 4:12 pm     Reply with quote

What makes people in this forum stop responding is that you haven't followed many of the good tips you received:
- There are still TRIS register settings in your program
- The code still has a terrible layout which makes it difficult to read. After every line with '{' you should indent a few characters.
- You still declare all your variables half way the main function. In C++ that is allowed but the CCS compiler is C and is known to sometimes create wrong code when you do this.
- I told you to fix the bug where you increase i by 3 instead of 2. You added an extra i++ but that doesn't fix it.

Then, there is another bug where you read up outside the eeprom's memory range. Your loop increases until the value of 1022, but you read at address (i+2) ==1024. (or actually even worse, 1025 after your last 'i++' addition).

With all this sloppy code and bugs we don't know if the problem is in the hardware or software.

Actually, your problem is still not very clear to me. You say the data you read from the eeprom is corrupted after reading for a long time?
How do you know it is corrupted? Tell us how you test this.
mahdifahime



Joined: 05 Jan 2013
Posts: 22

View user's profile Send private message

PostPosted: Mon Apr 08, 2013 9:27 am     Reply with quote

yes. I read from the eeprom is corrupted after reading for a long time?
i test the down program for 5,6 hourse
Code:

#include <16f72.h>

#use delay (crystal=20Mhz)
#fuses hs,NOWDT,BROWNOUT,PROTECT
#define EEPROM_SDA  PIN_C4
#define EEPROM_SCL  PIN_C3
#define led pin_c5
#use i2c(master,SDA=PIN_C4,SCL=PIN_C3)
#include <2408.c>


int8 tick;

 
  #int_timer2
  void timer2_isr() {
  if(++tick>=50){
  tick=0;
  output_toggle(led);
  }
  }
 
   void main(){output_b(0b0);
   setup_timer_2 ( T2_DIV_BY_16,55,16);
   enable_interrupts(INT_timer2);
   enable_interrupts(GLOBAL);
   set_tris_b(0b00000101);
   set_tris_a(0b0000011);
   int16 i;
   int8 r3,r2,r1,byte1,byte2,byte3;
   int1 gg=0;
   
    while(true){
 
  for (i=0;i<1023;i+=2){
  i++;
  r3=read_ext_eeprom(i);
  r2=read_ext_eeprom(i+1);
  r1=read_ext_eeprom(i+2);
  if (byte3==r3&&byte2==r2&&byte1==r1){i=1024;gg=1;}}
  }}

and then read and show information eeprom in lcd by program down

Code:

#include <16f72.h>
#use delay (crystal=20Mhz)
#fuses hs,nowdt,BROWNOUT,PROTECT
#define EEPROM_SDA  PIN_C4
#define EEPROM_SCL  PIN_C3
#define lcd_db4 pin_a5
#define lcd_db5 pin_a1
#define lcd_db6 pin_a3
#define lcd_db7 pin_a2
#define lcd_rs pin_c2
#define lcd_rw pin_c1
#define lcd_e pin_c0
#include <flex_lcd420.c>
#use i2c(master,SDA=PIN_C4,SCL=PIN_C3)
#include <2408.c>

void main(){ lcd_init();
setup_adc( ADC_OFF );
disable_interrupts(INT_timer0);
setup_timer_1(T1_DISABLED);
set_tris_b(0b00);
set_tris_a(0b00);
set_tris_c(0b00);int16 i;
while(true){
for (i=1023;i<=1023;--i){lcd_putc('\f');
lcd_gotoxy(1,1);
printf(lcd_putc,"%u   %u",read_ext_eeprom(0),read_ext_eeprom(1));
printf(lcd_putc,"\n%lu=%u   %lu=%u",i,read_ext_eeprom(i),i-3,read_ext_eeprom(i-3));
printf(lcd_putc,"\n%lu=%u   %lu=%u"i-1,read_ext_eeprom(i-1),i-4,read_ext_eeprom(i-4));
printf(lcd_putc,"\n%lu=%u   %lu=%u"i-2,read_ext_eeprom(i-2),i-5,read_ext_eeprom(i-5));
delay_ms(1000);i-=5;
}
}}

 
Mike Walne



Joined: 19 Feb 2004
Posts: 1785
Location: Boston Spa UK

View user's profile Send private message

PostPosted: Mon Apr 08, 2013 4:02 pm     Reply with quote

I'll keep this brief.

Sorry, but I'm still as confused as in my previous posts.

You continue to take very little notice of the advice offered by ckielstra.

Mike
mahdifahime



Joined: 05 Jan 2013
Posts: 22

View user's profile Send private message

PostPosted: Fri Apr 12, 2013 7:12 am     Reply with quote

I understand Not the solution for problem. and it is The big problem
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Goto page Previous  1, 2
Page 2 of 2

 
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