phtuan
24-03-2016, 08:13 AM
Chào mọi người. Mình viết chương trình đọc và ghi vào eeprom của 1 chuỗi data gồm 1 biến num_point và 1 mảng biến point kiểu cấu trúc. Mô phỏng chương trình trên proteus thì chạy OK nhưng chạy mạch ngoài thực tế thì kg đúng. Chương trình của mình:
//Khai báo:
struct alarm_time
{
int8 day:3;
int8 hour:5;//kieu thap phan
int8 min:6; //kieu thap phan
int8 style:2;
};
struct alarm_time point[45];
int8 num_point;
//Chương trình con ghi vào eeprom
void write_point()
{
int8 i;
write_eeprom(0,num_point);
delay_ms(10);
for (i=0;i<num_point;i++)
{
write_eeprom(4*i+1,point[i].day);
delay_ms(10);
write_eeprom(4*i+2,point[i].hour);
delay_ms(10);
write_eeprom(4*i+3,point[i].min);
delay_ms(10);
write_eeprom(4*i+4,point[i].style);
delay_ms(10);
}
}
//Chương trình con đọc từ eeprom
void read_point()
{
int8 i,temp_receive;
temp_receive=read_eeprom(0);
num_point=temp_receive;
for (i=0;i<num_point;i++)
{
point[i].day =read_eeprom(4*i+1);
point[i].hour =read_eeprom(4*i+2);
point[i].min =read_eeprom(4*i+3);
point[i].style =read_eeprom(4*i+4);
}
}
Trong chuơng trình mình khởi tạo chuỗi data sau đó dùng hàm:
write_point();
read_point();
Biên dịch và nạp chương trình để cho pic lưu giá trị vào eeprom
Sau đó xóa hàm write_point() chỉ dùng hàm read_point() biên dịch và nạp lại cho pic thì chương trình chạy khg đúng.
Bạn nào có kinh nghiệm về vấn đề này giúp mình. Thanks all!
//Khai báo:
struct alarm_time
{
int8 day:3;
int8 hour:5;//kieu thap phan
int8 min:6; //kieu thap phan
int8 style:2;
};
struct alarm_time point[45];
int8 num_point;
//Chương trình con ghi vào eeprom
void write_point()
{
int8 i;
write_eeprom(0,num_point);
delay_ms(10);
for (i=0;i<num_point;i++)
{
write_eeprom(4*i+1,point[i].day);
delay_ms(10);
write_eeprom(4*i+2,point[i].hour);
delay_ms(10);
write_eeprom(4*i+3,point[i].min);
delay_ms(10);
write_eeprom(4*i+4,point[i].style);
delay_ms(10);
}
}
//Chương trình con đọc từ eeprom
void read_point()
{
int8 i,temp_receive;
temp_receive=read_eeprom(0);
num_point=temp_receive;
for (i=0;i<num_point;i++)
{
point[i].day =read_eeprom(4*i+1);
point[i].hour =read_eeprom(4*i+2);
point[i].min =read_eeprom(4*i+3);
point[i].style =read_eeprom(4*i+4);
}
}
Trong chuơng trình mình khởi tạo chuỗi data sau đó dùng hàm:
write_point();
read_point();
Biên dịch và nạp chương trình để cho pic lưu giá trị vào eeprom
Sau đó xóa hàm write_point() chỉ dùng hàm read_point() biên dịch và nạp lại cho pic thì chương trình chạy khg đúng.
Bạn nào có kinh nghiệm về vấn đề này giúp mình. Thanks all!