⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 eeprom.c

📁 AD9850 DDS chip driver
💻 C
字号:
/*
 *	EEPROM calibration store for OH2NLT DDS Synthesizer board
 *
 * 	Juha Niinikoski 03.04.2004
 */



//	EEPROM_WRITE(adr,val);
//	temp = EEPROM_READ(adr);

/* dump EEPROM to serial port */

void dump_eeprom(void)
	{
	char x,temp;

	sio_putst("\nEEPROM data:");
	for(x=0; x<128; x++)
		{
		if(x%16 == 0)
			{
			sio_putst("\n");
			sio_putchhex(x);
			sio_putst(",  ");
			}
		temp = EEPROM_READ(x);
		sio_putchhex(temp);
		sio_putch(' ');
		}
	}

/* calculate EEPROM structure checksum */

unsigned char calc_csum(void)
	{
	unsigned char x;
	unsigned char cs;

	cs = 0;
	for(x=0; x<(sizeof(eedata.eeprom)-1); x++)
		{
		cs = cs + eedata.eeprom[x];
		}
	return cs;
	}

/* store EEPROM structure */

void cal_store(void)
	{
	char x;

	for(x=0; x<sizeof(eedata.eeprom); x++)
		{
		EEPROM_WRITE(x,eedata.eeprom[x]);
		}
	}

/* read EEPROM structure */

void cal_read(void)
	{
	char x;

	for(x=0; x<sizeof(eedata.eeprom); x++)
		{
		eedata.eeprom[x] = EEPROM_READ(x);
		}
	}

/* set default values */

void load_defaults()
	{
	eedata.caldata.osc_freq = CLKIN;	// DDS clock

	set_pw_data(DEFAULT_FREQ);		// load default frequency
	dds.dds_regs.dds_freq = DEFAULT_FREQ;

	step_idx = 1;
	f_step = f_steps[step_idx];		// step 1k

	d_mode = DEF_MODE;			// freq display

	dac = DEF_INT;				// back light half brigth
	set_bl(dac);
	pw_ready = 1;				// force freq load, this must be corrected
	clear_lcd();
	}


/* collect and write operating variables to EEPROM */

void write_eeprom_data(void)
	{
	sio_putst("\nStore to EEPROM");
	eedata.caldata.start_freq = dds.dds_regs.dds_freq;		// collect data to be saved
	eedata.caldata.start_step = step_idx;
	eedata.caldata.start_dmode = d_mode;
	eedata.caldata.start_dac = dac;

	eedata.eeprom[(sizeof(eedata.eeprom)-1)] = calc_csum();		// set checksum
	cal_store();
	sio_putst("\nok.");
	}

/* read operating data from EEPROM if checksum is correct */

void read_eeprom_data(void)
	{
	unsigned char ctemp;
	sio_putst("\nRead from  EEPROM\nCsum = ");
	cal_read();						// read stored operating values
	ctemp = calc_csum();					// calculate checksum
	sio_putchhex(calc_csum());

	if(ctemp == eedata.eeprom[(sizeof(eedata.eeprom)-1)])	// use values if checksum match
		{
		sio_putst(" Match.");

		set_pw_data(eedata.caldata.start_freq);		// set frequency
		dds.dds_regs.dds_freq = eedata.caldata.start_freq;
		step_idx = eedata.caldata.start_step;
		f_step = f_steps[step_idx];
		d_mode = eedata.caldata.start_dmode;
		dac = eedata.caldata.start_dac;
		set_bl(dac);
		redraw = 1;					// force first display update
		clear_lcd();
		}
	else							// load default values if bad checksum
		{
		sio_putst(" Error!");
		clear_lcd();
		putst("Cheksum Error");
		set_cur_lcd(LINE2);				
		putst("SW2 = Defaults");

		while(SW2)
			;
		load_defaults();				// set "factory defaults"
		write_eeprom_data();				// store to EEPROM
		}
	}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -