??? 11/01/06 19:30 Read: times |
#127233 - re posting code Responding to: ???'s previous message |
/*************************************************************/ /* DIRECCION_PAGINA recieves page number as integer and returns an address pointer */ /*************************************************************/ long direccion_pagina(int pagina) { int page_address[MAX_PAGE_ADDRS]; long address=0; int i; /*inicializo el array PAGE_ADDRESS en 0*/ for(i=0;i< MAX_PAGE_ADDRS;i++) page_address[i] = 0; i = 0; while (pagina>1) { page_address[i+8] = pagina%2; pagina = pagina/2; i++; } page_address[i+8] = pagina; for (i=0;i<16;i++){ address=address + power(2,i)*page_address[i]; } if (page_address[16] == 1) a16 = 1; else a16 = 0; if (page_address[17] == 1) a17 = 1; else a17 = 0; if (page_address[18] == 1) a18 = 1; else a18 = 0; return address; } /**************************************************************/ /* WRITE_FLASH_SECTOR copies the external RAM buffer to the Flash in the selected page */ /**************************************************************/ void write_Flash_sector(char *s, int page_num) { int i; char datos; // datos: temp. byte in internal Ram char xdata *address_pointer; long temp; EA = 0; CE_RAM=1; temp = direccion_pagina(page_num); P10 = 0; P11 = 0; P12 = 0; //write 3 test bytes before writing buffer /*write 0xAA in address 0x05555 of FLASH */ CE_FLASH=0; address_pointer = 0x5555; *address_pointer = 0xAA; CE_FLASH = 1; CE_FLASH=0; /*write 0x55 in address 0x02AAA of FLASH */ address_pointer = 0x2AAA; *address_pointer = 0x55; CE_FLASH = 1; CE_FLASH=0; /*write 0xA0 in addresss 0x05555 of FLASH */ address_pointer = 0x5555; *address_pointer = 0xA0; CE_FLASH = 1; //Reads 1 byte of external Ram and writes it to Flash //till completing page address_pointer = (char*) temp; P10 = a16; P11 = a17; P12 = a18; i=0; while(i<=BUFFER_SIZE-1) { CE_RAM = 0; datos = s[i]; CE_RAM = 1; CE_FLASH = 0; *address_pointer = datos; CE_FLASH = 1; i++; address_pointer++; } CE_RAM = 0; EA = 1; delayms(10); /*10 miliseg allow latch page*/ } /************************************************************** READ_FLASH_SECTOR copies a sector from the 29C040 into the SRAM buffer *************************************************************/ void read_Flash_sector(char *s, int page_num) { int i; char datos; // datos: temp Byte char xdata *address_pointer; EA = 0; address_pointer = (char *) direccion_pagina(page_num); P10 = a16; P11 = a17; P12 = a18; i=0; CE_RAM = 1; while (i<MAX_msg_per_page*Msg_size) { CE_FLASH = 0; datos = *address_pointer; CE_FLASH = 1; CE_RAM = 0; s[i]=datos; CE_RAM = 1; address_pointer++; i++; } for (i=MAX_msg_per_page*Msg_size;i<=BUFFER_SIZE-1;i++) { s[i]='\0'; } CE_RAM = 0; EA = 1; } <\pre> |
Topic | Author | Date |
4Mb Flash 29C040 | 01/01/70 00:00 | |
project description | 01/01/70 00:00 | |
which brand? | 01/01/70 00:00 | |
manufacturers datasheet link | 01/01/70 00:00 | |
neat chip | 01/01/70 00:00 | |
re posting code | 01/01/70 00:00 | |
newbie | 01/01/70 00:00 | |
a few things | 01/01/70 00:00 | |
bitwise operations | 01/01/70 00:00 | |
where are you?, please add location to profile | 01/01/70 00:00 | |
from Argentina![]() | 01/01/70 00:00 | |
Code | 01/01/70 00:00 | |
trouble description | 01/01/70 00:00 |