๐ ์๋ ํ์ธ์ Dexter ์ ๋๋ค.
์ค๋์ ์ํธ๋ฉ๊ฐ128 ๋ฐ์ดํฐ๋ฉ๋ชจ๋ฆฌ์ธ EEPROM ์๋ํด ์์๋ณด๊ณ ์ค์ต๊น์ง ํด๋ณด๊ฒ ์ต๋๋ค.
๋ณธ๋ฌธ PDF์๋ฃ๋ ์ฒจ๋ถํ์ผ์ ์์ต๋๋ค.
= 2^2 x 2^10 x 1byte
= 2^12 x 1byte
= ์ฃผ์๋ 4096๊ฐ (0 ํฌํจ)
EEPROM = DATA Memory์ด๋ค.
Ex) 1๋ฒ ํค ๋๋ฅด๋ฉด EEPROM์ ๋ฐ์ดํฐ ๊ธฐ๋ก, 8๋ฒ ํค ๋๋ฅด๋ฉด clear ํ๋ ํ๋ก๊ทธ๋จ
#include <L.h>
#define KEY_IN PINC
#define FND_DDR DDRE
#define FND_OUT PORTE
int main()
{
unsigned char ch = 0;
init_FND();
initTC0_overflow();
init_switch();
for (unsigned int i=0; ; i++) {
ch = KEY_IN;
if (ch == 0b11111110) { // 1๋ฒ์ค์์น๋ฅผ๋๋ฅด๋ฉดEEPROM์๋์ดํฐ๊ธฐ๋ก
ch = 0;
for (unsigned int a = 0; a<10; a++) {
eeprom_write(a, ch++);
}
ch = 9;
for (unsigned int b = 0; b<10; b++) {
eeprom_write(10+b, ch--);
}
}
if (ch == 0b01111111) { // 8๋ฒ์ค์์น๋ฅผ๋๋ฅด๋ฉดEEPROM๋ฐ์ดํฐ์ด๊ธฐํ
ch = 0;
for (unsigned int c = 0; c<20; c++) {
eeprom_write(c, ch);
}
}
ch = eeprom_read(i);
FND_OUT = ch; // ์ฝ์ด์จ๋ฐ์ดํฐ๋ฅผFND์์ถ๋ ฅ
if (i == 19) {
i = 0;
}
sleep(200);
}
return 1;
}
์์ ) ์ค์ต ๋ฌธ์
๐ก ์๊ตฌ์ฌํญ
#include <L.h>
#define KEY_IN PINC
#define FND_DDR DDRF
#define FND_OUT PORTF
int main(void)
{
unsigned char ch = 0;
unsigned char sh = 0xFF;
unsigned char le = 0xFF;
init_LED();
init_TC0();
init_switch();
for (unsigned int i=0;;i++) {
sh = KEY_IN;
le = FND_OUT & sh;
for (unsigned int a = 0; a<9; a++) {
FND_OUT = le;
if (le != 0xFF) {
eeprom_write(a,le);
}
}
ch = eeprom_read(i);
FND_OUT = ch;
if (FND_OUT == 0x00) {
FND_OUT = 0xFF;
}
if (i >= 8) {
i= 0;
}
sleep(200);
}
return 1;
}
ํค๋ํ์ผ์ ์ ์์ค๋ ๋์ผํฉ๋๋ค.
[ header ํ์ผ ] ↓
#define DDRE *((volatile unsigned char *)0x22)
#define PORTE *((volatile unsigned char *)0x23)
#define PINC *((volatile unsigned char *)0x33)
#define DDRC *((volatile unsigned char *)0x34)
#define PORTC *((volatile unsigned char *)0x35)
#define PINF *((volatile unsigned char *)0x20)
#define DDRF *((volatile unsigned char *)0x61)
#define PORTF *((volatile unsigned char *)0x62)
#define PIND *((volatile unsigned char *)0x30)
#define DDRD *((volatile unsigned char *)0x31)
#define TCCR0 *((volatile unsigned char *)0x53)
#define TCNT0 *((volatile unsigned char *)0x52)
#define TIMSK *((volatile unsigned char *)0x57)
#define SREG *((volatile unsigned char *)0x5F)
#define EEDR *((volatile unsigned char *)0x3D)
#define EEARH *((volatile unsigned int *)0x3F)
#define EEARL *((volatile unsigned int *)0x3E)
#define EECR *((volatile unsigned char *)0x3C)
#define EEAR *((volatile unsigned int *)0x3E)
#define EERE 0
#define EEWE 1
#define EEMWE 2
#define TOIE0 0
#define CPU_CLOCK 16000000
#define TICKS_PER_SEC 1000
#define PRESCALER 64
/* delay */
volatile unsigned int g_elapsed_time;
void sleep(unsigned int elapsed_time)
{
g_elapsed_time = 0;
for (;g_elapsed_time<elapsed_time;);
}
void __vector_16 (void) __attribute__ ((signal, used, externally_visible));
void __vector_16 (void)
{
TCNT0 = 6;
++g_elapsed_time;
}
/* ์ค์์น */
void init_switch(void)
{
DDRC = 0x00;
}
/* LED ์ด๊ธฐํ */
void init_LED(void)
{
DDRF = 0xFF;
PORTF = 0xFF;
}
/* FND ์ด๊ธฐํ */
void init_FND(void)
{
DDRE = 0xFF;
PORTE = 0xFF;
}
/* ์ ์ธ์ ์ผ์ */
void init_URS(void)
{
DDRD = 0x00;
}
/* Timer/counter Control regi์ด๊ธฐํ */
void init_TC0(void)
{
TCCR0 = 0x04;
TCNT0 = 6;
TIMSK = TIMSK | (1<<TOIE0);
/*์ ์ฒด์ธํฐ๋ฝํธํ์ฑํ*/
SREG = SREG | (1<<7);
}
/* eeprom Write */
void eeprom_write(unsigned int uiAddress, unsigned char ucData);
void eeprom_write(unsigned int uiAddress, unsigned char ucData)
{
while (EECR&(1<<EEWE));
EEAR = uiAddress;
EEDR = ucData;
EECR |= (1<<EEMWE);
EECR |= (1<<EEWE);
return ;
}
/* eeprom Read */
unsigned char eeprom_read(unsigned int uiAddress);
unsigned char eeprom_read(unsigned int uiAddress)
{
while(EECR&(1<<EEWE));
EEAR = uiAddress;
EECR |= (1<<EERE);
return EEDR;
}
๊ถ๊ธํ์ ์ ์ ๋๊ธ๋ก ๋จ๊ฒจ์ฃผ์ธ์. ๐ ์ค๋๋ ์ข์ ํ๋ฃจ ๋์ธ์.