BiPOM Forum

General => Micro-IDE => Topic started by: delunn on May 10, 2005, 07:02:28 am

Title: Example of using more Ram
Post by: delunn on May 10, 2005, 07:02:28 am
Do you have an example of using more ram. Using the 89C51ED2 in the MINI-MAX/51-D, I get errors of runnning out of ram when I\'ve used <100 bytes of the 2K.
Title: Re: Example of using more Ram
Post by: vitaliy on May 10, 2005, 01:52:06 pm
#include <8051io.h>
#define OFFSET      0x300
struct _header
{
     unsigned char byte;
     unsigned int  word;
};

unsigned char GetExpandData( unsigned int address)
{
     asm
     {
           MOV A,#-3
           ADD      A,SP            Adjust for stack offset
           XCH      A,R0            
           MOV DPL,[R0]
           INC R0
           MOV DPH,[R0]
           MOVX A,@DPTR
           RET
     }
}
void SetExpandData( unsigned int address,unsigned char data )
{
     asm
     {
           MOV A,#-5
           ADD      A,SP            Adjust for stack offset
           XCH      A,R0            And restore order
           MOV DPL,[R0]
           INC R0
           MOV DPH,[R0]      
           INC R0
           MOV      A,[R0]
           MOVX @DPTR,A
           RET
     }
}
register unsigned int G_offSet;
void memset (register unsigned char* dest,
                             register unsigned char* source,
                                   unsigned int  len)
{
     unsigned int address;
     unsigned char ndx;
     address = dest + G_offSet;
     for (ndx =0 ; ndx < len; ndx++)
           SetExpandData(address++,*source++);
     
}                                        
void memget (register unsigned char* dest,
                             register unsigned char* source,
                                   unsigned int  len)
{
     unsigned int address;
     unsigned char ndx;
     address = source + G_offSet;
     for (ndx =0 ; ndx < len; ndx++)
           *dest++ = GetExpandData(address++);
}                                    

void main()
{
     unsigned int address;
     unsigned char dataByte;
     unsigned int  dataWord;
     struct _header *pt;
     serinit(9600);
     asm
     {
           MOV 8EH,#0CH       ; Enable Expanded memory
; Clear all locations of expanded memory      
           MOV DPTR,#0
NEXT:            
           CLR      A
           MOVX @DPTR,A
           INC      DPTR
           MOV      A,DPH      
           JNB      ACC.2,NEXT                  
     }
     pt =0;
     G_offSet = OFFSET;      // set offset inside of Expanded memory
//      
     dataByte = 0xA5;
     dataWord = 0x1234;
     memset(&pt->byte,&dataByte,sizeof(pt->byte)); // write byte
     memset(&pt->word,&dataWord,sizeof(pt->word)); // write word      
//      
     dataByte = 0x00;
     dataWord = 0x0000;
     memget(&dataByte,&pt->byte,sizeof(pt->byte));  // read byte
     memget(&dataWord,&pt->word,sizeof(pt->word));  // read word
//      
     printf("\\ndataByte = %02x ",dataByte);
     printf("\\ndataWord = %04x ",dataWord);

     
                 
     for(address= 0; address < 0x400; address++)
     {      
           if(!(address % 16))
           {
                 printf("\\n%04x ",address);
           }      
           printf("%02x ",GetExpandData(address));
     }
     for(;;);

}
Title: Re: Example of using more Ram
Post by: Don Lunn on May 10, 2005, 03:04:39 pm
Now if this was in basic, It would really be good. Thanks