View Single Post
Old 10-09-2008, 10:46 PM   #15
tungtot_vl
Đệ tử 6 túi
 
tungtot_vl's Avatar
 
Tham gia ngày: Jul 2007
Bài gửi: 154
:
các anh giúp eeprom với.
bài này em gởi từ pc xuống nhiều chuỗi dũa liệu khác nhau.
khi gởi chuổi đầu tiên thì data viết vào và đọc ra cho chuôi đầu là đúng.
khi gởi tiếp chuổi thứ 2 thì chuổi data của chuổi thứ 2 đọc ra cũng đúng nhưng chuỗi 1 đọc ra lại sai
khi gởi chuỗi 3 thì chuối 3 đọc ra đúng còn chuỗi 1 và 2 đọc ra sai.
cứ tiếp tục như vậy. chuỗi vừa gởi xuống thì đọc đúng còn các chuỗi khác thì bị sai. trong khi khoảng cách địa chỉ giữa các chuỗi lớn hơn data gởi xuống
tôi không rỏ vì sao nữa. ai biết chỉ giúp với.


Code:
#include<18F4580.h>
#fuses NOLVP,NOWDT,PUT,hs,NOPROTECT,NOBROWNOUT
#device 18f4680*=16 ADC=10 high_ints=true
#use delay(clock=20000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7)
#use fast_io(a)
#byte porta=0x05
#use fast_io(b)
#byte portb=0x06
#use fast_io(c)
#byte portc=0x07
#use fast_io(d)
#byte portd=0x08
#use fast_io(e)
#byte porte=0x09
#define ch1    0x0005     //
#define ch2    0x00a5     // khoang cach 160 byte
#define ch3    0x0145
#define ch4    0x01e5
#define ch5    0x0285

//======================================================
int8 ram[150];
int8 count = 0;
int8 tam,l;
//==============================================================================
          void giao_tiep();
          void viet_eeprom();


#INT_EEPROM FAST
void viet_eeprom()
   {  int8 ma,j;
      ma = ram[0]; // mã xác định chuỗi
      printf(" %u",ma);
           switch(ma)
              {  case 1: for(j=0;j<139;j++) { write_eeprom(ch1+j,ram[j]); printf(" %u",ram[j]);  } break;
                 case 2: for(j=0;j<139;j++) { write_eeprom(ch2+j,ram[j]); printf(" %u",ram[j]);  } break;
                 case 3: for(j=0;j<139;j++) { write_eeprom(ch3+j,ram[j]); printf(" %u",ram[j]); } break;
                 case 4: for(j=0;j<139;j++) { write_eeprom(ch4+j,ram[j]); printf(" %u",ram[j]); } break;
                 case 5: for(j=0;j<139;j++) { write_eeprom(ch5+j,ram[j]); printf(" %u",ram[j]); } break;   /// printf(" %u",read_eeprom(ch5+j)); dùng vẫn sai
              }

   }

#INT_RDA
void giao_tiep() // doc pc xuong ram roi do vao eeprom
   {  int8 c,i;
      c = getc();
  //--------------------------------
      if(c!=250)  //1 byte dau tien dung de chon ma chuoi
         {
           ram[count] = count; count++;  }
      else
         { count=0; viet_eeprom();   printf("ok");  }

   }

 ////////////////////////////////////////////////
 void main()
   {
      set_tris_b(0);
      set_tris_a(0);
      set_tris_c(0x80);
      set_tris_e(0);
      set_tris_d(0);
      enable_interrupts(INT_eeprom);
      enable_interrupts(INT_RDA);
      enable_interrupts(global);
     while(true)
        {
          printf("ch1 ");
          for(l=0;l<139;l++)
            {
                tam = read_eeprom(ch1+l);
                delay_ms(5);
                printf("/%u",tam);
            }
          delay_ms(3000);
          printf("ch2 ");
          for(l=0;l<139;l++)
            {
                tam = read_eeprom(ch2+l);
             printf("/%u",tam);
            }
          delay_ms(1000);
          printf("ch3 ");
          for(l=0;l<139;l++)
            {
                tam = read_eeprom(ch3+l);
             printf("/%u",tam);
            }
          delay_ms(1000);
          printf("ch4 ");
          for(l=0;l<139;l++)
            {
                tam = read_eeprom(ch4+l);
                printf("/%u",tam);
            }
          delay_ms(1000);
          printf("ch5 ");
          for(l=0;l<139;l++)
            {
                tam = read_eeprom(ch5+l);
                printf("/%u",tam);
            }
          delay_ms(1000);
        }
   }

thay đổi nội dung bởi: namqn, 11-09-2008 lúc 04:53 PM.
tungtot_vl vẫn chưa có mặt trong diễn đàn   Trả Lời Với Trích Dẫn