Email: Password: Remember Me | Create Account (Free)

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
???
06/08/07 20:05
Read: times


 
#140440 - I used Charles Bannister's trick
Responding to: ???'s previous message
Formatting was there (wihout the pre/pre tags) and is nice, but I still haven't received answer to my question - which version of sdcc?

I tried some 2.6.2 and it looks good - of course I don't have the real hardware to try.

JW

#define MEM_OE        P2_0
#define MEM_WE        P2_1
#define MEM_RY_BY     P2_2
#define MEM_RESET     P2_3
#define MEM_CE        P2_4
#define LATCH1	      P2_5	 
#define LATCH2 	      P2_6 	
#define LATCH3        P2_7
#define MDATA	      P0

void hardware_rst(void)  // takes flash into reading array mode
{
	MEM_CE = 1;
	MEM_OE = 1;
	
	MEM_RESET = 0;
	_asm
	nop
	nop
	nop
	nop
	nop
	nop
	nop
	nop
	_endasm;
	MEM_RESET = 1;
		_asm
	nop
	nop
	nop
	nop
	nop
	nop
	nop
	nop
	_endasm;
	
	while(!MEM_RY_BY);
}


// MEMORY FUNCTION T0 LATCH ADDRESS TO FLASH
void latch_address(unsigned long address)
{
        unsigned char lda1,lda2,lda3;
        
        lda3 = (address & 0x00ff0000)>>16;
        lda2 = (address & 0x0000ff00)>>8;
        lda1 =  address & 0x000000ff;        
    	LATCH1 = 0;
     	LATCH2 = 0;
     	LATCH3 = 0;

       MDATA = lda1; //lsb

       _asm
       nop
       nop
       nop
       nop
       _endasm;
       	LATCH1 = 1;
       _asm
       nop
       nop
       nop
       nop
       _endasm;
 	LATCH1 = 0;       	

       MDATA = lda2;  
       _asm
       nop
       nop
       nop
       nop
       _endasm;
       	LATCH2 = 1;
       _asm
       nop
       nop
       nop
       nop
       _endasm;
	LATCH2 = 0;       	

       MDATA = lda3;  //msb
       _asm
       nop
       nop
       nop
       nop
       _endasm;
       	LATCH3 = 1;
       _asm
       nop
       nop
       nop
       nop
       _endasm;
	LATCH3 = 0;       	
}


//FUNCTION TO READ ARRAY DATA FROM FLASH
unsigned char flash_read(unsigned long address)
{
	unsigned char datta;
	
	latch_address(address);
	P0 = 0xff;
	MEM_WE = 1;   //WRITE ENABLE
	MEM_CE = 0;   //CHIP ENABLE
	MEM_OE = 0;   // OUTPUT ENABLE
		_asm
		nop
		nop
 		nop
		nop
		nop
		nop
 		nop
		nop
		_endasm;
	datta = MDATA;
	MEM_OE = 1;
	MEM_CE = 1;
 return(datta);

}

void write_command(unsigned long address,unsigned char cmd)
{
	
	MEM_RESET = 1;
	
	latch_address(address);
	MEM_CE = 0;
	MEM_OE = 1;
	MEM_WE = 0;
	MDATA  = cmd;
	_asm
	nop
	nop
	_endasm;
	MEM_WE = 1;
	MEM_CE = 1;	
}

void flash_eraseall(void)
{
	//hardware_rst();
	
	while(!MEM_RY_BY);

	write_command(0x00000555,0xAA);
	write_command(0x000002AA,0x55);
	write_command(0x00000555,0x80);
	write_command(0x00000555,0xAA);
	write_command(0x000002AA,0x55);
	write_command(0x00000555,0x10);
	while(MEM_RY_BY);
        while(!MEM_RY_BY);
 	

}

void flash_write(unsigned long address,unsigned char dat)
{       
 	hardware_rst();
	while(!MEM_RY_BY);
	write_command(0x00000555,0xAA);
	write_command(0x000002AA,0x55);
	write_command(0x00000555,0xA0);
	write_command(address,dat);
	while(MEM_RY_BY);
	while(!MEM_RY_BY);	
}


void main(void)
{

	unsigned char j;
        unsigned int i;

        unsigned long mempointer;
	
	for(j=0;j50us) for flash
                            // memory (AM290F016D)-Tvcs
	{
		_asm
		nop
		nop
		_endasm;
	}

 

	// Serial port configuration
	TH1 	= 256 - ((FCLK / 384)/BAUD);//1200 baudrate
	TMOD 	= 0x20;	//8 bit auto reload
	TR1 	= 1;			
	SCON 	= 0x50;	//8bit UART set by TIMER1 for serial_0
	
	RI 	= 0; 	

	//Flash memory defaults for TTL standby state
	hardware_rst();  
	MEM_CE 	   = 1;    
	MEM_RESET  = 1;

        TI = 0;
        SBUF = 'R';
        while(!TI);
       
       flash_eraseall();
       mempointer = 0x00000000;

      // ********flash write loop*************
       for(i=0;i


List of 11 messages in thread
TopicAuthorDate
external flashmemory interfacing for data storage            01/01/70 00:00      
   You should know how to post code by now            01/01/70 00:00      
   which version of sdcc?            01/01/70 00:00      
   code posted            01/01/70 00:00      
      Hmmm...            01/01/70 00:00      
   I used Charles Bannister's trick            01/01/70 00:00      
      As soon as possible?            01/01/70 00:00      
   As soon as possible? Maybe he is in bed!            01/01/70 00:00      
      I am very sorry....            01/01/70 00:00      
         sorry for being impatient...            01/01/70 00:00      
            Thanks            01/01/70 00:00      

Back to Subject List