PDA

View Full Version : Hỏi về đọc ghi vào EEPROM của dsPIC30F


hiodong
28-08-2009, 09:03 PM
trong file dataEEPROM.h có nội dung

/*
* ReadEErow prototype:
* Parameters Definition:
* Page: is the 8 most significant bits of the source address in EEPROM
* Offset: is 16 least significant bits of the source address in EEPROM
* DataOut: is the 16-bit address of the destination RAM location or array
* Size: is the number of words to read from EEPROM and is a value of 1 or 16
* Return Value:
* Function returns ERROREE (or -1) if Size is invalid
*/
extern int ReadEE(int Page, int Offset, int* DataOut, int Size);

/*
* EraseEErow prototype:
* Parameters Definition:
* Page: is the 8 most significant bits of the address in EEPROM to be erased
* Offset: is 16 least significant bits of the address in EEPROM to be erased
* Size: is the number of words to read from EEPROM and is a value of 1, 16 or
* 0xFFFF (for erasing ALL EEPROM memory)
* Return Value:
* Function returns ERROREE (or -1) if Size is invalid
*/
extern int EraseEE(int Page, int Offset, int Size);

/*
* WriteEErow prototype:
* Parameters Definition:
* Page: is the 8 most significant bits of the destination address in EEPROM
* Offset: is 16 least significant bits of the destination address in EEPROM
* DataIn: is the 16-bit address of the source RAM location or array
* Size: is the number of words to read from EEPROM and is a value of 1 or 16
* Return Value:
* Function returns ERROREE (or -1) if Size is invalid
*/
extern int WriteEE(int* DataIn, int Page, int Offset, int Size);

Em dùng thử mà kết quả ko chính xác, đồng thời ko hiểu rõ ý nghĩa của Page , Offset lắm
Nhờ mọi người giúp đỡ !

namqn
29-08-2009, 02:04 PM
trong file dataEEPROM.h có nội dung

/*
* ReadEErow prototype:
* Parameters Definition:
* Page: is the 8 most significant bits of the source address in EEPROM
* Offset: is 16 least significant bits of the source address in EEPROM
* DataOut: is the 16-bit address of the destination RAM location or array
* Size: is the number of words to read from EEPROM and is a value of 1 or 16
* Return Value:
* Function returns ERROREE (or -1) if Size is invalid
*/
extern int ReadEE(int Page, int Offset, int* DataOut, int Size);

/*
* EraseEErow prototype:
* Parameters Definition:
* Page: is the 8 most significant bits of the address in EEPROM to be erased
* Offset: is 16 least significant bits of the address in EEPROM to be erased
* Size: is the number of words to read from EEPROM and is a value of 1, 16 or
* 0xFFFF (for erasing ALL EEPROM memory)
* Return Value:
* Function returns ERROREE (or -1) if Size is invalid
*/
extern int EraseEE(int Page, int Offset, int Size);

/*
* WriteEErow prototype:
* Parameters Definition:
* Page: is the 8 most significant bits of the destination address in EEPROM
* Offset: is 16 least significant bits of the destination address in EEPROM
* DataIn: is the 16-bit address of the source RAM location or array
* Size: is the number of words to read from EEPROM and is a value of 1 or 16
* Return Value:
* Function returns ERROREE (or -1) if Size is invalid
*/
extern int WriteEE(int* DataIn, int Page, int Offset, int Size);

Em dùng thử mà kết quả ko chính xác, đồng thời ko hiểu rõ ý nghĩa của Page , Offset lắm
Nhờ mọi người giúp đỡ !
Bạn thử như thế nào, kết quả ra sao mà nhận xét không chính xác?

Về ý nghĩa của Page và Offset, chúng lần lượt là giá trị trang (8-bit) đặt vào thanh ghi TBLPAG và địa chỉ hiệu dụng (16-bit) trong trang đó. Data EEPROM được ánh xạ vào không gian bộ nhớ chương trình với địa chỉ tuyệt đối 24-bit, và được truy xuất tương tự như truy xuất bộ nhớ chương trình. Bạn đọc thêm mục "5 - Flash and EEPROM Programming" trong tài liệu "dsPIC Family Reference Manual" (DS70046E) để hiểu rõ hơn cơ chế truy xuất flash và EEPROM.

Dù bạn sử dụng hàm thư viện hay tự viết hàm thì đều phải cung cấp những thông tin Page và Offset cho hàm mới có thể truy xuất đúng ô nhớ cần thiết.

Thân,

hiodong
19-09-2009, 10:31 AM
Bác nào cho xin cái code ,hay thư viện ghi đọc EEPROM cái . Em còn đang vật vã với cái ma trận phím 4x3 tất cả các phím đều đọc được trừ phím 10, ko thể nào mà hiểu được, hic hic, mặc dù đã thay bàn phím

int giatribanphim()
{

int y,x;
TRISGbits.TRISG13 = 0; // row 1 // la cong ra
TRISGbits.TRISG15 = 0; // row 2
TRISCbits.TRISC1 = 0; // row 3
TRISCbits.TRISC2 = 0; // row 4


TRISCbits.TRISC14 = 1; // colum 1 // la cong vao
TRISCbits.TRISC13 = 1; // colum 2
TRISGbits.TRISG7 = 1; // colum 3


for (x=0;x<4;x++)
{
row1 = row2 = row3 = row4 = 1; // LAT
col1 = col2 = col3 = 1;
switch (x)
{
case 0: row1 = 0;break;
case 1: row2 = 0;break;
case 2: row3 = 0;break;
case 3: row4 = 0;break;
}
// delay_ms(1);

if (col1==0) {y= 3*x ; col1 = 1; goto ra;} else // PORT
if (col2==0) {y= 1 + 3*x ; col2 = 1;goto ra;} else
if (col3==0) {y= 2 + 3*x ; col3 = 1;goto ra;} else y=20;
}
ra:
row1 = row2 = row3 = row4 = 1; // LAT
delay_us(300);
return(y+1); // ra dung so cua phim
}