📄 memory.c
字号:
////////////////////////////////////////////////////////////////
//
// S C R I P T H E R M
// A SCRIPTABLE THERMOMETER
//
// entry of the National Semiconductor COP8FLASH Design Contest
// submitted by Alberto Ricci Bitti (C) 2001
// a.riccibitti@ra.nettuno.it
//
//--------------------------------------------------------------
// FOR A BETTER VIEW SET TAB SIZE=4, INDENT SIZE=4
//--------------------------------------------------------------
// FILE : memory.c
// PURPOSE: Virtual memory manager. Makes accesses to both FLASH
// (COP8 Virtual Eeprom) and RAM (graphics display spare
// RAM) virtual. Very convenent if are going to experiment
// alternative storage media (e.g. Microwire memories).
// IMPORTANT: valid for a 10MHz crystal only.
//
////////////////////////////////////////////////////////////////
#include <incop8.h>
#include <ioc8cdr.h>
#include "lcd.h"
#include "memory.h"
void clear_ram(void)
{ unsigned int i;
for (i=0; i < RAM_SIZE; i++)
{
poke_ram( i, 0);
};
}
void copy_flash_to_ram( void )
{ unsigned int i;
for (i=0; i < RAM_SIZE; i++)
{
__disable_interrupt();
__PGMTIM = 0x7B; // valid for 10MHz crystal only
poke_ram( i, __read_flash_byte( i + FLASH_START ));
__enable_interrupt();
};
}
void copy_ram_to_flash( void )
{ unsigned int i;
unsigned char data;
unsigned int address;
for (i=0; i < RAM_SIZE; i++)
{
address = i + FLASH_START;
data = peek_ram(i);
if ((i & 0x7F) == 0)
{
__disable_interrupt();
__PGMTIM = 0x7B; // valid for 10MHz crystal only
__page_flash_erase( address );
__enable_interrupt();
};
__disable_interrupt();
__PGMTIM = 0x7B; // valid for 10MHz crystal only
__write_flash_byte( address, data );
__enable_interrupt();
};
}
static ram_pointer_t cache_address = RAM_SIZE+1;
static unsigned char cache_data = 255;
unsigned char peek_ram(ram_pointer_t address)
{
if (address == cache_address)
return cache_data;
else
{
cache_address = address;
LCD_command(SET_ADDRESS_POINTER, address & 0xFF, address >> 8);
LCD_command( DATA_READ_INCREMENT, 0, 0 );
return cache_data = LCD_read();
};
}
void poke_ram(ram_pointer_t address, unsigned char data)
{
if( !((address == cache_address) && (data == cache_data)) )
{
cache_data = data;
cache_address = address;
LCD_command( SET_ADDRESS_POINTER, address & 0xFF, address >> 8);
LCD_command( DATA_WRITE_INCREMENT, 0, data );
};
}
unsigned char peek_flash(flash_pointer_t address)
{ unsigned char retval;
__disable_interrupt();
__PGMTIM = 0x7B; // valid for 10MHz crystal only
retval = __read_flash_byte( address + FLASH_START );
__enable_interrupt();
return retval;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -