Пример #1
0
/**
 * @param wAddress Endereço de 2 bytes da memória EEPROM onde iniciará a escrita da linha.
 * @param wName[3] Nome de 3 caracteres a ser escrito na linha.
 * @param wScore Score a ser escrito na memória logo após o nome.
 */
void WriteLine(uint16_t wAddress, uint8_t wName[3], uint8_t wScore)
{
	EEPROM_write(wAddress, wName[0]);	//Escreve primeiro caractere.
	EEPROM_write(wAddress+1, wName[1]);	//Escreve o segundo caractere na próxima posição.
	EEPROM_write(wAddress+2, wName[2]);	//Escreve o terceiro caractere na posição seguinte.
	EEPROM_write(wAddress+3, wScore);	//Escreve o score na última posição da linha.
}
static void do_save_eeprom_settings(void)
{
    EEPROM_write( EEPROM_CONF_MODBUS_ADDR, modbus_our_address );

    EEPROM_write( EEPROM_CONF_UART_SPEED_LO, uart_speed & 0xFF );
    EEPROM_write( EEPROM_CONF_UART_SPEED_HI, (uart_speed >> 8) & 0xFF );

    EEPROM_write( EEPROM_CONF_VALID, 0 );
}
Пример #3
0
void
EEPROM_write_int(eeprom_addr_t address, unsigned int data)
{
	// C18 uses little-endian and int are 16 bit wide
	// Split data into 2 unsigned char and save them with the appropriate function
	unsigned char lsb = (data & 0x00FF);
	unsigned char msb = (data & 0xFF00) >> 8;
	EEPROM_write(address, lsb);
	EEPROM_write(address + 1, msb);
}
Пример #4
0
/* EEPROM write string into EEPROM at specific address */
void EEPROM_writeString(uint16_t uiAddress, uint8_t *ucData){
	
	do{
		EEPROM_write(uiAddress,*ucData);
		ucData++;
		uiAddress++;
	}while((*(ucData-1)) =! 0);
}
Пример #5
0
/*!
 *******************************************************************************
 *  Update timer storage for dow and slot
 *
 *  \note
 ******************************************************************************/
void eeprom_timers_write_raw(uint8_t offset, uint16_t value)
{
    if (offset>=(uint8_t)(sizeof(ee_timers)/sizeof(ee_timers[0][0])))
		return; // EEPROM protection
    uint16_t eeaddr = (uint16_t)offset * (uint16_t)sizeof(ee_timers[0][0]) + (uint16_t)ee_timers;
    EEPROM_write(eeaddr, value&0xff); //litle endian
    EEPROM_write(eeaddr+1 , (value>>8)); //litle endian
}
Пример #6
0
	/* Write logical one to EEMPE */
	EECR |= (1<<EEMPE);
	/* Start eeprom write by setting EEPE */
	EECR |= (1<<EEPE);
}

void EEPROM_write_page(uint16_t start_address, uint8_t *data, uint16_t length)
{
Пример #7
0
void EERing_write(EE_Ring *Temp, unsigned char EData)
{
	char TDataAdr;
	TDataAdr=Temp->SAdress&0x0F|Temp->DtBuf_Start;                                        // Получаем адрес ячейки с данными, зависящий от адреса ячейки статуса
	if(EData!=EEPROM_read(TDataAdr)) EEPROM_write(TDataAdr, EData);      
	if(Temp->SAdress+1==Temp->StBuf_Start+Temp->Buf_Size)                                //Если достигли конечного адреса буфера статуса
	{
		Temp->SAdress=Temp->StBuf_Start;                                                 //Переходим в начало буфера
		EEPROM_write(Temp->SAdress, EEPROM_read(Temp->StBuf_Start+Temp->Buf_Size-1)+1); //Наращиваем значение буфера статуса
	} 
	else 
	{                                                                   //если еще не конец буфера
		Temp->SAdress++;                                                      //наращиваем адрес ячейки буфера                                                      
		EEPROM_write(Temp->SAdress, EEPROM_read(Temp->SAdress-1)+1);                //записываем по нему значение буфера статуса +1
	}

	 //возвращаем обновленный адрес последней записи в буфер
}
Пример #8
0
/* EEPROM write N number of Bytes into EEPROM at specific address */
void EEPROM_WriteNByte(uint16_t uiAddress, uint8_t *ucData,uint16_t uiNumberOfBytes)
{
	
	while(uiNumberOfBytes!=0){
		EEPROM_write(uiAddress,*ucData);
		ucData++;
		uiAddress++;
		uiNumberOfBytes--;
	}
}
Пример #9
0
/*  $Function   :   phone_work_save
==  ==============================================================================================
==  Description :   工作参数保存到eeprom
==  ==============================================================================================
==  Argument    :   
==  ==============================================================================================
==  Return      :   
==              :   
==  ===============================================================================================
==  History     : Modify by  ||    ID    ||     Date      ||     Contents
==              :   xul      ||          ||   2009/09/26  || Create this function
==  ===============================================================================================
*/
void phone_work_save(STWORK *p_mode)
{
  uint8 i;
  uint8 *p = (uint8*)p_mode;
  for(i = 0; i < sizeof(STWORK); i++)
  {
    if(p[i] != EEPROM_read(STWORK_ADD + i))
      EEPROM_write(STWORK_ADD + i, p[i]);
  }
}
static void temp_sens_write_record( int nRec, uint8_t record[EEPROM_MAP_REC_SZ] )
{
    if( (nRec >= N_TEMP_SENS_EEPROM_RECORDS) || (nRec < 0) ) return;

    uint8_t i;
    for( i = 0; i < EEPROM_MAP_REC_SZ; i++ )
    {
        EEPROM_write( EEPROM_MAP_BASE + (nRec*EEPROM_MAP_REC_SZ) + i, record[i] );
    }

}
Пример #11
0
WORD EEPROM_save(BYTE devaddr, WORD addr, const RDA_MEMORY *mem)
{
    BYTE b[1] = {0};
    WORD new_addr = 0;
    
    // Mark old one as deleted
    if(addr >= 0 && addr < EEPROM_MAX_ADDR)
        EEPROM_write(devaddr, addr, b, 1);
    
    // Calc new address
    if(addr < EEPROM_MAX_ADDR)
        new_addr = addr + sizeof(RDA_MEMORY);
    
    mem->valid = 0xFF;
    
    // write new registry
    EEPROM_write(devaddr, new_addr, mem->data, sizeof(RDA_MEMORY));
    
    return new_addr;
}
Пример #12
0
void key1_event (void)      // кнопка T-
{
  if (curent_mode==SETUP_MODE) 
  {
    set_temp--;  // в режиме установки температуры убавляет значение 
    if (set_temp<1)set_temp=1;
    EEPROM_write(EEPROM_ADDR,set_temp); // запоминаем установленное значение
  }
  if (curent_mode==IDLE_MODE)curent_mode=SHOW_MODE;
    else curent_mode=SETUP_MODE;
  sec_counter=0;
  led1_set(1); // зажигаем светодиод. тухнет он по времени sec_counter
}
Пример #13
0
void
EEPROM_write_block( uint8_t addr, const uint8_t *data, uint8_t size )
{
	while( size-- )
	{
		uint8_t old = EEPROM_read( addr );

		if( old == *data )
			continue;

		EEPROM_write( addr++, *data++ );
	}
}
Пример #14
0
/*  $Function   :   phone_num_save
==  ==============================================================================================
==  Description :   电话号码保存到eeprom   废弃!!!
==  ==============================================================================================
==  Argument    :   
==  ==============================================================================================
==  Return      :   
==              :   
==  ===============================================================================================
==  History     : Modify by  ||    ID    ||     Date      ||     Contents
==              :   xul      ||          ||   2009/09/24  || Create this function
==  ===============================================================================================
*/
void phone_num_save(uint8 sn, uint8* num, uint8 len)
{
  StPhSla st_phone;
  uint8 i;
  uint8 *p=(uint8*)(&st_phone);
  memcpy(st_phone.phone_num, num, len);
  st_phone.len = len;
  
  
  for(i = 0; i < sizeof(StPhSla); i++)
  {
     EEPROM_write(PN_ADD + i + (sn - 1)*sizeof(StPhSla), p[i]);
  }
}
Пример #15
0
/******************************************************
 * FunctionName : user_application
 * Description  : 用户APP程序段
 * Parameters   : none
 * Returns      : none
******************************************************/
void user_application()
{
	char buf[64];
	memset(buf,0,64);
	memcpy(buf,"Hello EEPROM..\n",15);
	EEPROM_SectorErase(0);  //擦除扇区0
	EEPROM_write(0,buf,15); //写EEPROM
	delay_ms(2000);  //延时
	memset(buf,0,64); //清空buf
	EEPROM_read(0,buf,15); //读取EEPROM
	UartwriteStr(buf,0);  //通过串口发送读取内容
	while(true)
	{
	}
}
Пример #16
0
void eeprom_save(void)
{
	struct eeprom_data e;

	e.main_pwm[0] = main_pwm[0];
	e.main_pwm[1] = main_pwm[1];
	e.main_pwm[2] = main_pwm[2];

	e.usart_pwm = usart_pwm;

	uint8_t wcsum = csum( (void *)&e, sizeof(e) );

	EEPROM_write_block( 1, (void *)&e, sizeof(e) );
	EEPROM_write( 0, wcsum );

}
Пример #17
0
//*****************************************************************************
// Copyright (C) 2007 DESY(Deutsches-Elektronen Synchrotron) 
//
// File Name	: fru.c
// 
// Title		: FRU device
// Revision		: 1.1
// Notes		:	
// Target MCU	: Atmel AVR series
//
// Author       : Vahan Petrosyan ([email protected])
// Modified by  : Markus Joos ([email protected])
//
// Description : FRU(Field Replaceable Unit) information and payload control.
//					
//
// This code is distributed under the GNU Public License
//		which can be found at http://www.gnu.org/licenses/gpl.txt
//*****************************************************************************


#include <avr/eeprom.h>
#include "avrlibdefs.h"
#include "timer.h"
#include "fru.h"
#include "project.h"
#include "ipmi_if.h"
#include "eeprom.h"
#include "user_code_select.h"

//*******************************************/
u08 ipmi_get_fru_inventory_area_info(u08* buf) //Called from ipmi_if.c
//*******************************************/
{
    u08 len = 0;

    buf[len++] = FRU_SIZE & 0xff;
    buf[len++] = FRU_SIZE >> 8;
    buf[len++] = 0x00; //byte access type

    return (len);
}

//**************************************************/
u08 ipmi_fru_data_read(u08* area, u08 len, u08* data) //Called from ipmi_if.c
//**************************************************/
{
    u16 address = 0;
    u08 i;

    if (len > MAX_BYTES_READ)
        return (0xff);

    address = area[0] | (area[1] << 8);

    if ((address + len) > FRU_SIZE)
        return (0xff);

    *data++ = len;

    for (i = 0; i < len; i++)
        *(data + i) = EEPROM_read(address + i);

    return(len + 1);   //MJ ipmi_if.c only looks at errors (0xff). Maybe it would be cleaner to return 0
}


//***************************************************/
u08 ipmi_fru_data_write(u08* area, u08* data, u08 len) //Called from ipmi_if.c
//***************************************************/
{
    u16 address;
    u08 i;

    address = area[0] | (area[1] << 8);

    if ((address + len) > FRU_SIZE)
        return(0xff);

    CRITICAL_SECTION_START;

    for (i = 0; i < len; i++)
        EEPROM_write(address + i, data[i]);

    CRITICAL_SECTION_END;
    return(len);    //MJ ipmi_if.c only looks at errors (0xff). Maybe it would be cleaner to return 0
}
Пример #18
0
/*--store the config to eeprom--*/
void FlightData::store_to_eeprom( void ){
    cli(); //turn off interrupts
    EEPROM_write_16(0, roll.p);
    EEPROM_write_16(2, roll.i);
    EEPROM_write_16(4, roll.d);
    EEPROM_write_16(6, pitch.p);
    EEPROM_write_16(8, pitch.i);
    EEPROM_write_16(10, pitch.d);
    EEPROM_write_16(12, yaw.p);
    EEPROM_write_16(14, yaw.i);
    EEPROM_write_16(16, yaw.d);
    //EEPROM_write_16(18, alt.p);
    //EEPROM_write_16(20, alt.i);
    //EEPROM_write_16(22, alt.d);
    
    EEPROM_write(24, config.flying_mode); //X_MODE or PLUS_MODE
    EEPROM_write_16(26, config.pitch_roll_tx_scale);
    EEPROM_write_16(28, config.yaw_tx_scale);
    
    EEPROM_write_16(36, config.led_mode); 
    sei(); //re-enable interrupts
}
Пример #19
0
/**
 * Method for set address of the slave
 * @data - address value
 */
void doProgramingMode(unsigned char data) {
    unsigned int i;
    unsigned int addr;

    REDON;
    GREENON;
    _delay_ms(1000);
     ALLOFF;
    _delay_ms(1000);

    for (i = 0; i < data; i++) {
        _delay_ms(250);
        GREENON;
        _delay_ms(250);
        ALLOFF;
    }

    REDON;
    _delay_ms(1000);

    EEPROM_write(0, data);
    addr = EEPROM_read(0);

    if (addr) {
        ALLOFF;
        _delay_ms(1000);
        for (i = 0; i < addr; i++) {
            ALLOFF;
            _delay_ms(250);
            GREENON;
            _delay_ms(250);
        }
        ALLOFF;
        MyAddr = addr;
    }
}
Пример #20
0
void main()
{
	u8 time_counter_for_cycle = 4;
    disable_all_interrupt();
	//设置输出口、中断
	require_delay_init();
	InitUart();
	init_system_component();
	//初始化端口
	P33 = 0;
	enable_all_interrupt();
	//检测当前状态
	detect_current_state();
    while(1) {
    	// Feed dog
    	reset_watch_dog();
    	// 驱动灯光开关
 //   	toggle_once();
   		// 5ms system tick-tock
    	if (INT_PROC & TICK_DUTY) {
    		cycle_based_adjust(counter_for_cycle);
            INT_PROC &= ~TICK_DUTY;
 //   		continue;
    	}

    	if (INT_PROC & EXINT_PROC) {
            EX0 = 0;
 //           SendData(time_counter>>8);
 //           SendData(time_counter);
    		if(time_counter <= 80)
            {
    			if(display_mode_set == combination)
                {
                    -- time_counter_for_cycle;
                }
                // 循环四次跳至下一个功能
                if(!time_counter_for_cycle)
                {
                    display_mode_logic++;
                    time_counter_for_cycle = 4;
                }
                if(display_mode_logic == 13)
                    display_mode_logic = 1;
 //               SendData(display_mode_logic);
                display_mode_set_changed();
            }
            if(display_mode_set == bi_directional_storbing)
    		{
    			if(time_counter >= 4000 && time_counter < 20000){
    				display_mode_logic ++;
                    if(display_mode_logic == 13)
                        display_mode_logic = 1;
                }
    			if(time_counter >= 40000)
    				display_mode_logic = 2;
                EEPROM_SectorErase(IAP_ADDRESS);
    			EEPROM_write(IAP_ADDRESS, display_mode_logic);
//                SendData(display_mode_logic);
    			display_mode_set_changed();
    		}
    		time_counter = 0;
    		INT_PROC &= ~EXINT_PROC;
            EX0 = 1;
    		continue;
    	}
    }
}
Пример #21
0
void EEPROM_write_buf(uintptr_t address, void *buf, size_t len) {
	for (uintptr_t i = 0; i < len; ++i) {
		EEPROM_write(address + i, ((uint8_t *)buf)[i]);
	}
}
Пример #22
0
//Records a 16-bit value (setting_value) to a given eeprom spot (setting_number
void record_setting(char setting_number, uint16_t setting_value)
{
	EEPROM_write(setting_number + 0, setting_value & 0xFF);
	EEPROM_write(setting_number + 1, setting_value >> 8);
}
Пример #23
0
// Saves the colors to memory
void save_colors(LED_color_t *color_ptr)
{
    EEPROM_write((uint8_t)COLOR_ADDR, color_ptr->red);
    EEPROM_write((uint8_t)(COLOR_ADDR+1), color_ptr->green);
    EEPROM_write((uint8_t)(COLOR_ADDR+2), color_ptr->blue);
}
Пример #24
0
int main (void)
{
	char temp;
	short b;

	
    ioinit(); //Setup IO pins and defaults
	USART_Init(10);//set up for 115200
	rprintf_devopen(put_char); /* init rrprintf */
	
	for (b = 0; b < 5; b++)
	{
		PORTB &= (~(1<<STAT));//stat on
		delay_ms(50);
		PORTB |= (1<<STAT);//stat off
		delay_ms(50);
	}
	
	asc = 0;
	auto_run = 0;
	
	//check for existing preset values==============================================================
	temp = EEPROM_read((unsigned int)FREQ_HIGH);
	
	if (temp == 255)//unwritten
	{
		cli();//Disable Interrupts
		
		EEPROM_write((unsigned int) FREQ_LOW, 100);//100Hz
		EEPROM_write((unsigned int) FREQ_HIGH, 0);
		EEPROM_write((unsigned int) SENSE_AR_MODE, 0);//1.5g, auto-run off, binary output
		EEPROM_write((unsigned int) ACT_CHAN, 0x3F);//all channels active
		
		sei();//Enable Interrupts
		
		freq = 100;
		asc = 0;//binary
		auto_run = 0;//auto run off
		//set for 1.5g sensitivity
		PORTB &= (~((1<<GS1) | (1<<GS2)));//GS1 low, GS2 low
	}
	
	//get presets
	else
	{
		b = EEPROM_read((unsigned int)FREQ_HIGH);
		b <<= 8;
		b |= EEPROM_read((unsigned int)FREQ_LOW);
		
		freq = (float)b;
		
		active_channels = EEPROM_read((unsigned int)ACT_CHAN);
		
		temp = EEPROM_read((unsigned int)SENSE_AR_MODE);
		
		if (temp & 0x08) PORTB |= (1<<GS2);//GS2 High
		if (temp & 0x04) PORTB |= (1<<GS1);//GS2 High
		
		if (temp & 0x02) auto_run = 1;
		if (temp & 0x01) asc = 1;
	}
	
	//main loop==================================================================
	while(1)
	{

		if (auto_run == 1)
		{
			while(1)
			{
				//This is the sampling loop. It runs in get_adc() until somebody stops it.
				get_adc();
				
				//If it dumps out of the sampling loop, go to the config menu.
				config_menu();
				
				//Bail out if auto run is off.
				if (auto_run == 0) break;
			}
		}

	
		if (UCSR0A & (1<<RXC0))//if something comes in...
		{
			  
			temp = UDR0;

			if (temp == 35)	//# to run
			{
				asc = 0;
				get_adc();
			
			}
		  
			else if (temp == 37)	//% to set range to 1.5g
			{
				//set for 1.5g sensitivity
				PORTB &= (~((1<<GS1) | (1<<GS2)));//GS1 low, GS2 low
			
			}
			
			else if (temp == 38)	//& to set range to 2g
			{
				PORTB |= (1<<GS1);//GS1 High
				PORTB &= (~(1<<GS2));//GS2 low   
			  
			}
			
			else if (temp == 39)	//' to set range to 4g
			{
				PORTB &= (~(1<<GS1));//GS1 low
				PORTB |= (1<<GS2);//GS2 High
			}
			
			else if (temp == 40)	//( to set range to 6g
			{
				PORTB |= ((1<<GS1) | (1<<GS2));//GS1, GS2 high
				
			}

		  else if (temp == 41) freq = 50;	//) to run at 50Hz
		  
		  else if (temp == 42)	freq = 100;// to run at 100Hz

		  else if (temp == 43)	freq = 150;//+ to run at 150Hz
		  
		  else if (temp == 44)	freq = 200;//, to run at 200Hz
		 
		  else if (temp == 45)	freq = 250;//- to run at 250Hz
		  
		  else if (temp == 32)	//
		  {
			  while(1)
			  {
				  config_menu();

				  if (auto_run == 0) break;

				  get_adc();

				 
			  }
		  }

		  temp = 0;

			  
		}
	}
	
	while(1);
	

}
int main (void)
{
	char x, y, temp, q;
    ioinit(); //Setup IO pins and defaults
	//USART_Init( MYUBRR);
	set_baud(6);//115200
	rprintf_devopen(put_char); /* init rrprintf */
	
	//check for existing preset values==============================================================
	temp = EEPROM_read((unsigned int)BPS);
	
	if ((temp < 1) | (temp > 6))//BPS will only be 1-6
	{
		cli();//Disable Interrupts
		
		EEPROM_write((unsigned int) BPS, 6);
		EEPROM_write((unsigned int) BACKLIGHT, 100);
		EEPROM_write((unsigned int) SPLASH, 1);
		EEPROM_write((unsigned int) REV, 0);
		
		sei();//Enable Interrupts
		
		BL_dutycycle = 100;
		baud_rate = 6;
		splash_screen = 1;
		reverse = 0;
	}
	
	else
	{
		baud_rate = temp;
		BL_dutycycle = EEPROM_read((unsigned int)BACKLIGHT);
		splash_screen = EEPROM_read((unsigned int)SPLASH);
		reverse = EEPROM_read((unsigned int)REV);
	}
	
	
	//Reset the display
	PORTC &= ~(1 << RESET);
	delay_ms(50);
	PORTC |= (1 << RESET);
	//delay_ms(500);

	
	clear_screen();

	set_page(0);
	
	set_x(0);
	
	display_on();
	
	//set display start line to 0
	//set control lines
	PORTC &= ~((1 << EN) | (1 << R_W) | (1 << RS));//down
	
	set_data(0xC0);
	//set_data(0xFF);
	delay();
	PORTC |= (1 << EN);//up
	delay();
	PORTC &= ~(1 << EN);//down
	delay();
	PORTC |= ((1 << EN) | (1 << R_W) | (1 << RS));//all high
	
	delay();
	
	x_offset = 0;

	set_page(0);
	
	DDRB |= (1<<BL_EN);//set PB2 as output
	
	set_backlight(BL_dutycycle);
	
	//Logo==========================================================
	if (splash_screen == 1)
	{
		y = 40;
		
		for (q = 0; q < 30; q++)
		{
			temp = logo[q];
			for (x = 56; x < 64; x++)
			{
				if (temp & 0x80) pixel(1,x,y);
				
				temp <<= 1;
			}
			
			q++;
			
			temp = logo[q];
			for (x = 64; x < 72; x++)
			{
				if (temp & 0x80) pixel(1,x,y);
				
				temp <<= 1;
			}
			y--;
	
		}	
	}
	
	pixel(0,0,0);//cheat
	
	RX_in = 0;
	
	delay_ms(1000);
	clear_screen();
	
	if (RX_in > 0)//revert to 115200
	{
		print_char(1,'1');
		print_char(1,'1');
		print_char(1,'5');
		print_char(1,'2');
		print_char(1,'0');
		print_char(1,'0');
		
		baud_rate = 6;
		set_baud(6);//115200
		
		cli();
		
		EEPROM_write((unsigned int) BPS, 6);
		
		sei();//Enable Interrupts
	}
	
	else (set_baud(baud_rate));
	
	delay_ms(1000);
	clear_screen();
	
	//main loop===================================================
	while(1)
	{
		if(RX_in != RX_read)
		{
			x = RX_array[RX_read];
			RX_read++;
			if(RX_read >= 416) RX_read = 0;
			
			//Backspace===================================================
			if(x == 8) del_char(0);
			
			//Special commands
			else if (x == 124)
			{	
				//make sure the next byte is there
				while(RX_in == RX_read);
				
				//0, clear screen======================================================
				if(RX_array[RX_read] == 0)//^@
				{
					clear_screen();
					RX_read++;
					if(RX_read >= 416) RX_read = 0;
				}
				
				//demo mode
				else if(RX_array[RX_read] == 4)//^d
				{
					RX_in = 0, RX_read = 0;
					demo();
					clear_screen();
					RX_in = 0;
				}
				
				
				//reverse mode
				else if(RX_array[RX_read] == 18)//^r
				{
					reverse ^= 1;
					clear_screen();
					RX_read++;
					if(RX_read >= 416) RX_read = 0;
					
					cli();
					EEPROM_write((unsigned int) REV, reverse);
					sei();
				}
				
				
				//toggle spasl screen
				else if(RX_array[RX_read] == 19)//^s
				{
					splash_screen ^= 1;
					//clear_screen();
					RX_read++;
					if(RX_read >= 416) RX_read = 0;
					
					cli();
					EEPROM_write((unsigned int) SPLASH, splash_screen);
					sei();
				}
				
				else
				{
					//set backlight (0 to 100)=========================================================
					if(RX_array[RX_read] == 2)//^b
					{
						RX_read++;
						if(RX_read >= 416) RX_read = 0;
						while(RX_in == RX_read);//wait for byte
						BL_dutycycle = RX_array[RX_read];
						
						RX_read++;
						if(RX_read >= 416) RX_read = 0;
						
						set_backlight(BL_dutycycle);
						
						cli();
						EEPROM_write((unsigned int) BACKLIGHT, BL_dutycycle);
						sei();
						
						

					}
					
					
					//change baud rate=========================================================
					if(RX_array[RX_read] == 7)//^g
					{
						RX_read++;
						if(RX_read >= 416) RX_read = 0;
						while(RX_in == RX_read);//wait for byte
						//if (RX_array[RX_read] == '1') USART_Init( 1000000/2400-1);//4800
						//else if (RX_array[RX_read] == '2') USART_Init( 1000000/4800-1);//9600
						//else if (RX_array[RX_read] == '3') USART_Init( 1000000/9600-1);//19200
						//else if (RX_array[RX_read] == '4') USART_Init( 1000000/19200-1);//38400
						//else if (RX_array[RX_read] == '5') USART_Init( 1000000/28800-1);//57600
						//else if (RX_array[RX_read] == '6') USART_Init( 1000000/57600-1);//115200
						
						if ((RX_array[RX_read] > '0') * (RX_array[RX_read] < '7')) baud_rate = (RX_array[RX_read]) - 48;
						
						set_baud(baud_rate);
						
						cli();
						EEPROM_write((unsigned int) BPS, baud_rate);
						sei();
						
						RX_read++;
						if(RX_read >= 416) RX_read = 0;
						
					}	
					
					
					//set x or y=========================================================
					if((RX_array[RX_read] == 24) | (RX_array[RX_read] == 25))//^x or ^y
					{
						RX_read++;
						if(RX_read >= 416) RX_read = 0;
						while(RX_in == RX_read);//wait for byte
						if (RX_array[RX_read-1] == 24) x_offset = RX_array[RX_read];
						else if (RX_array[RX_read-1] == 25) y_offset = RX_array[RX_read];
						
						RX_read++;
						if(RX_read >= 416) RX_read = 0;
						
						if (x_offset > 159) x_offset = 159;
						if (y_offset > 127) y_offset = 127;

					}

					//set pixel=========================================================
					if (RX_array[RX_read] == 16)//^p
					{
						//need 3 bytes
						for (y = 0; y < 3; y++)
						{
							RX_read++;
							if(RX_read >= 416) RX_read = 0;
							while(RX_in == RX_read);//wait for byte
						}
						
						pixel(RX_array[RX_read], RX_array[RX_read-2], RX_array[RX_read-1]);
						
						RX_read++;
						if(RX_read >= 416) RX_read = 0;

					}

					
					//<ctrl>c, circle======================================================
					if(RX_array[RX_read] == 3)//^c
					{
						//need 4 bytes
						for (y = 0; y < 4; y++)
						{
							RX_read++;
							if(RX_read >= 416) RX_read = 0;
							while(RX_in == RX_read);//wait for byte
						}
						
						circle(RX_array[RX_read], RX_array[RX_read-3], RX_array[RX_read-2], RX_array[RX_read-1]);
						
						RX_read++;
						if(RX_read >= 416) RX_read = 0;
					}
					
					
					//<ctrl>e, erase block======================================================
					if(RX_array[RX_read] == 5)//^e
					{
						//need 4 bytes
						for (y = 0; y < 4; y++)
						{
							RX_read++;
							if(RX_read >= 416) RX_read = 0;
							while(RX_in == RX_read);//wait for byte
						}
						
						erase_block(RX_array[RX_read-3], RX_array[RX_read-2], RX_array[RX_read-1], RX_array[RX_read]);
						
						RX_read++;
						if(RX_read >= 416) RX_read = 0;
					}
					
					
					//box======================================================
					if(RX_array[RX_read] == 15)//^o
					{
						//need 4 bytes
						for (y = 0; y < 4; y++)
						{
							RX_read++;
							if(RX_read >= 416) RX_read = 0;
							while(RX_in == RX_read);//wait for byte
						}
						
						box(RX_array[RX_read-3], RX_array[RX_read-2], RX_array[RX_read-1], RX_array[RX_read]);
						
						RX_read++;
						if(RX_read >= 416) RX_read = 0;
					}


					//line========================================================
					else if (RX_array[RX_read] == 12)//^l
					{
						//need 5 bytes
						for (y = 0; y < 5; y++)
						{
							RX_read++;
							if(RX_read >= 416) RX_read = 0;
							while(RX_in == RX_read);//wait for byte
						}
						
						line(RX_array[RX_read], RX_array[RX_read-4], RX_array[RX_read-3], RX_array[RX_read-2], RX_array[RX_read+-1]);
						RX_read++;
						if(RX_read >= 416) RX_read = 0;
					}
					
					
				}
	
			}
			
			//print character to the screen===============================================
			else
			{
				del_char(1);
				print_char(1, x);
			}
		}
		
	}
	
	//demo();
	


    
}
Пример #26
0
int main(void)
{
	
	unsigned int addr;
	unsigned char READBYTE;
	unsigned char Mystring[30];


	Serial_Init();
	print_string("\n\rSTART OF EEPROM TEST");
	
	READBYTE = 0x00;		/* readByte variable initialized to zero */


	print_string("\n\rREADING EEPROM");			/* print to serial */

	/* performing READ FROM EEPROM */
	cli();	/* disable global interrupt */
	READBYTE = EEPROM_read(0xA);		//read Byte from address 0xa
	sei();	/* Enable global interrupt */
	
	sprintf(Mystring,"\n\rBYTE AT Address 0xA = 0x%02x",(unsigned int)READBYTE);	/* set the string to be printed on serial */
	print_string(Mystring);			/* print to serial */

	print_string("\n\rWRITING EEPROM");			/* print to serial */

	/* performing WRITE TO EEPROM */
	cli();	/* disable global interrupt	*/
	EEPROM_write(0xA,0x55);		/* write 0x55 at address 0xa */
	sei();	/* Enable global interrupt */
	

	READBYTE = 0x00;		/* readByte variable initialized to zero */

	print_string("\n\rREADING EEPROM");			/* print to serial */

	/* performing READ FROM EEPROM */
	cli();	/* disable global interrupt */
	READBYTE = EEPROM_read(0xA);		/* read Byte from address 0xa */
	sei();	/* Enable global interrupt */

	sprintf(Mystring,"\n\rBYTE AT Address 0xA = 0x%02x",(unsigned int)READBYTE);	//set the string to be printed on serial
	print_string(Mystring);			/* print to serial */

	/* reading from address 0x0000 to 0x000F */
	print_string("\n\r READING IN LOOP from address 0x0000 to 0x000F ");
		for(addr=0x0;addr<0x000F;addr++)
		{
			if(!(addr%20))
			{
				sprintf(Mystring,"\n\r0x%04d	: ",addr);
				print_string(Mystring);
			}
			sprintf(Mystring,"%02x ",(unsigned char)EEPROM_read(addr));	//write Byte at Addr (address Startaddress)
			print_string(Mystring);
		}
	
	print_string("\n\r START WRITING SEQUENCE IN LOOP from address 0x0000 to 0x000F ");

	/* writing from address 0x0000 to 0x000F */
	EEPROM_WRITEFROM(0x0000,0x000F,1,0xA5);		/* NOTE in this sequence is ON so it will start writing data as 0 1 2 3 ...*/
	//EEPROM_WRITEFROM(0x0000,0x000F,0,0xA5);	/*NOTE in this sequence is OFF so it will write data given in call */
	/* reading from address 0x0000 to 0x000F */
	for(addr=0x0;addr<0x000F;addr++)
	{
		if(!(addr%20))
		{
			sprintf(Mystring,"\n\r0x%04d	: ",addr);
			print_string(Mystring);
		}
		sprintf(Mystring,"%02x ",(unsigned char)EEPROM_read(addr));	//write Byte at Addr (address Startaddress)
		print_string(Mystring);
	}

	print_string("\n\rEND OF EEPROM TEST");

	while(1);		/* wait forever */
}
Пример #27
0
// Now we have the main procedure.
void main()
{
  unsigned char CANdata[8];
  unsigned char A, B; // scratch-pad variables
  long id;
  unsigned short send_flag, dt, len, read_flag;
  float chargeInc=0;
  float energyInc=0;
  float x,y,E,Q;  // floats used for energy and charge calcs.
 
  // Set up the structures for the CANbus messages that are transmitted
  // by this node. See manual. These relate to its the system status, and
  // the total charge and energy used.
  struct CAN
  {
         long id;
         short len;
         unsigned char mdata[8];
  }errors, totals;
   errors.id=1024;
   errors.len=2;
   totals.id=1025;
   totals.len=3;
   
// Get the CANbus ready
send_flag = _CAN_TX_PRIORITY_0 & _CAN_TX_NO_RTR_FRAME;
CANbus_setup();
// Set up and start the timing interrupts
setup_interrupts();
// setup the ports
TRISA =0xFF;  // PORTA is input
ADCON1 =0x07;  // Configure AN pins 0-3 as digital I/O, page 242
TRISC = 0;   // PORT C is for output

// Read the energy and charge values out of EEPROM.
charge=EEPROM_Read(1);
delay_ms(20);
A = EEPROM_Read(2); //LSB of energy value
delay_ms(20);
B = EEPROM_Read(3); //MSB of energy value
energy = (B*256) + A;

E=energy;   // Convert charge and energy to float
Q=charge;


  for(;;)     /* Endless loop   */
  {
     WhatState();
     IndicateState();
     SetErrorFlags();
     OperateRL3();
     // See if any CAN messages in.
     dt = CANRead(&id, CANdata, &len, &read_flag);
            if (dt>0) { /*Message received     */
                   if (id==128){
                   FN_flags= CANdata[2]; // Map Fn errors
                   Accel = CANdata[0];  // Accel postion, 0-200
                   }
                   if (id==150){
                      I=(CANdata[0] + (CANdata[1]<<8));   // NB V and I are x10
                      V=(CANdata[2] + (CANdata[3]<<8));
                   }
                   if (id==512) brakelight=CANdata[0];
                   if  (id==1026){
                      T1=CANdata[0];
                      T2=CANdata[1];
                   }
                   if (id==1280){
                      energy=0, E=0, energyInc=0;
                      charge=0, Q=0, chargeInc=0;
                   }
             } // end of dealing with messages.
             
     if (Tcount1Hz>1000){   // Do this at 1 Hz
        Tcount1Hz=0;
        // Update float values of energy and charge totals.
        // E is in 10th of Watt hours, and Q is in 10th of Ah.
        E = E + (energyInc/360);
        energyInc=0;
        Q = Q + ((chargeInc/100)/360);
        chargeInc=0;
        // And udate low res integer values as well
        energy=E;
        charge=Q;
        // Send out the two CAN messages.
        errors.mdata[1]=state;
        errors.mdata[0]=ERR_FLAG;
        CANWrite(errors.id, errors.mdata, errors.len, send_flag);
        // Now set up the CAN charge and energy message, and write the data
        // to EEPROM.
        totals.mdata[0]=charge;
        EEPROM_write(1,charge);
        totals.mdata[1]=energy;
        EEPROM_write(2,totals.mdata[1]);
        totals.mdata[2]=energy>>8; // MS byte second
        EEPROM_write(3,totals.mdata[2]);
        CANWrite(totals.id, totals.mdata, totals.len, send_flag);
          } // end of 1 Hz actions
     if (Tcount10Hz>100) { // Do this at 10Hz
        Tcount10Hz=0;
        x = I;  // Be careful to do anything tricky while float
        chargeInc = (chargeInc + x);
        // chargeInc is in coulombs, and x100
        // Remember that I and V are both x10
        y = V;
        energyInc = (energyInc + ((x*y/1000)));
        // energyInc is the energy in Joules
        } // end of 10Hz energy and charge calculations.
     } /* End of endless loop    */
Пример #28
0
int main(void) {
    
    i=EEPROM_read(Address); // de vazut adresele cum sunt puse!
    
    //timer_1(1000); // set value in ms
    
    DDRD = 0xf8;
    DDRB = 0xff;
    
    // set external interrupt on digital PIN 2
    cli();
    
    PORTD |= (1 << PORTD2);    // turn On the Pull-up
    
    EICRA |= (1 << ISC00);    //
    EICRA |= (1 << ISC01);    // set INT0 to trigger on rising edge
    
    EIMSK |= (1 << INT0);     // Turns on INT0 - external interrupt mask register
    
    sei();
    
    clear(2);
    clear(1);
    
    while(1){
        
            if(i<100 && i>=1){
    
                nr_2=i%10;
                nr_1=i/10;
                
                if(nr_1>=1){
                    if(nr_1==0){
                        zero(1);
                    }
                    if(nr_1==1){
                        one(1);
                    }
                    if(nr_1==2){
                        two(1);
                    }
                    if(nr_1==3){
                        three(1);
                    }
                    if(nr_1==4){
                        four(1);
                    }
                    if(nr_1==5){
                        five(1);
                    }
                    if(nr_1==6){
                        six(1);
                    }
                    if(nr_1==7){
                        seven(1);
                    }
                    if(nr_1==8){
                        eight(1);
                    }
                    if(nr_1==9){
                        nine(1);
                    }
                }
                
                if(nr_2==0){
                    zero(2);
                }
                if(nr_2==1){
                    one(2);
                }
                if(nr_2==2){
                    two(2);
                }
                if(nr_2==3){
                    three(2);
                }
                if(nr_2==4){
                    four(2);
                }
                if(nr_2==5){
                    five(2);
                }
                if(nr_2==6){
                    six(2);
                }
                if(nr_2==7){
                    seven(2);
                }
                if(nr_2==8){
                    eight(2);
                }
                if(nr_2==9){
                    nine(2);
                }
                
            }
            else{
                i=0;
                clear(2);
                clear(1);
                
            }
        
            EEPROM_write(Address, i);
        
    }
    
	return 0;     
}
Пример #29
0
int main(){

	first_time_boot(); //first time boot parameters
	read_config(); //nuskaitom config is eeprom	
	
	
	//------------- I/O nustatymai ------------------
	
	//LED
	PORTDDR(LED_PORT) |= _BV(LED1_BIT); 
	LED_PORT &= ~_BV(LED1_BIT); 
	PORTDDR(LED_PORT) |= _BV(LED2_BIT); 
	LED_PORT &= ~_BV(LED2_BIT); 
	PORTDDR(LED_PORT) |= _BV(LED3_BIT); 
	LED_PORT &= ~_BV(LED3_BIT); 

	PORTDDR(LCD_LED_PORT) |= _BV(LCD_LED_BIT); //LCD pasvietimas
	LCD_LED_PORT |= _BV(LCD_LED_BIT); //ijungiam LCD pasvietimas

	//USART
	DDRD|=_BV(PD1); //TX
	PORTD|=_BV(PD1);
	DDRD&=~_BV(PD0); //RX

	//ROT ENCODER
	DDRD&=~_BV(PD3); //INT1 
	PORTD|=_BV(PD3);
	DDRD&=~_BV(PD4); 
	PORTD|=_BV(PD4);
	//ROT ENCODER BUTTON
	DDRB&=~_BV(PB6); 
	PORTB|=_BV(PB6);


	//PIR
	DDRD&=~_BV(PD2); //INT0
//	PORTD|=_BV(PD2);

	//PWM OUT
	DDRB|=_BV(PB3); 
 
	//----------------- initai -----------------------------

	init_uart(UBRR_VAL);
	lcd_init(LCD_DISP_ON);
	INT_init();
	ADC_init();

	timer_init_0();
	timer_init_1();

	start_timer1();
//	TIMSK |=(_BV(OCIE1A)); //iddle timmer on


	apie();	
	
	
	//puslapiai();


	//Nustatom PWM mode
//	TCCR2=0x6B;     //6E;

//	OCR2=EEPROM_read(24); // OCR2 is EEPROM




	
	work_mode=EEPROM_read(25);
	wmode(work_mode);
	
	show_work_mode();
	
#if debug_mode
send_string("OCR2 eeprome: ");
send_string(itoa(OCR2, buff, 10));
send_string("\n\r");
#endif

	//naudojam ADC nuskaitymui
	
//	start_timer0();
	
	_delay_ms(200);
	LCD_LED_PORT &= ~_BV(LCD_LED_BIT); //isjungiam LCD pasvietima	

sei();

//fade_in();

//fade_out();




	


while(5){


	PORTDDR(LED_PORT)^= (1<<LED3_BIT);
//	_delay_ms(50);

//-------------------- to go into main menu 00--------------------

//		if (bit_is_clear(PINB, PB6)){	
//		lcd_light=1;
//		}
		
		
		if(meniu==0 && config==0 && read_keypad()==1){
			
		#if debug_mode 
		PORTDDR(LED_PORT)^= (1<<LED2_BIT);
		send_string("nuspausta knopke\n\r");	
		#endif
		
		if(lcd_light==0) {	
							clock_second=0;
							clock_millisecond=0;
							lcd_light=1;
							LCD_LED_PORT |= _BV(LCD_LED_BIT); //ijungiam LCD pasvietima	
						 }
		else{

		LCD_LED_PORT |= _BV(LCD_LED_BIT); //ijungiam LCD pasvietima	

		meniu=1; 
		menu_page=0; 
		sub_menu_page=0;
	
		lcd_light=0; 

		puslapiai();
		
		}		

		#if debug_mode 
		debug_meniu();	
		#endif
			
		}
	
//-------------------- main and sub menu routine --------------
	
	while(meniu!=0 && config==0){

	
		if(read_keypad()==1){

			if(meniu==1 && config==0){
				
					if(menu_page<4){ //2inis configas (on/off tipo)
						meniu=2;
						sub_menu_page=0; 
						puslapiai_2();
					
						#if debug_mode 
						debug_meniu();					
						#endif
					}				

					else if (menu_page==4){	//isejimas i configa		
						meniu=3;
						config=1;
						read_config(); //nuskaitom config parametrus is eeprom
						puslapiai_config();										

						#if debug_mode 
						debug_meniu();	
						#endif
					}
					//exit meniu punktas
					else if (menu_page==5){ //iseijimas i work_mode();
						meniu=0;
						config=0;

						show_work_mode();

						LCD_LED_PORT &= ~_BV(LCD_LED_BIT); //isjungiam LCD pasvietima

						#if debug_mode 
						debug_meniu();	
						#endif		
					}

					else meniu=meniu;
			}
//-------------------- end of main menu routine --------------

	
//-------------------- start of sub menu routine --------------		
		
		else if (meniu==2 && config==0){ //2inis configas
		
			if(sub_menu_page==1) { //OFF vektorius visiems meniu			
				if(menu_page!=4){ 
				meniu=1; 
				work_mode=0;	 //OFF - wmode
				EEPROM_write(25, work_mode);
				wmode(work_mode);		
				puslapiai(); 
				
				#if debug_mode 
				debug_meniu();	
				#endif	
				}
		

			}
			
			else if (sub_menu_page==0){ //ON vektorius
				if(menu_page==0){		//ON/OFF meniu punkte
				work_mode=1;			//ON - wmode
				EEPROM_write(25, work_mode);
				meniu=0;
				wmode(work_mode);
				show_work_mode();
				

				_delay_ms(200);
				LCD_LED_PORT &= ~_BV(LCD_LED_BIT); //isjungiam LCD pasvietima
				
				#if debug_mode 
				debug_meniu();	
				#endif	
				}
				
				else if (menu_page==1){		//PIR meniu punktas
				work_mode=2;				//PIR - wmode
				EEPROM_write(25, work_mode);
				meniu=0;
				show_work_mode();
				wmode(work_mode);				
				

				_delay_ms(200);
				LCD_LED_PORT &= ~_BV(LCD_LED_BIT); //isjungiam LCD pasvietima
				}				

				else if (menu_page==2){		//PIR/LDR meniu punktas
				work_mode=3;				//PIR/LDR - wmode
				EEPROM_write(25, work_mode);
				meniu=0;
				show_work_mode();
				wmode(work_mode);				
				

				_delay_ms(200);
				clock_second=0;
				clock_millisecond=0;
				lcd_light=1;
				
				//LCD_LED_PORT &= ~_BV(LCD_LED_BIT); //isjungiam LCD pasvietima
				
				#if debug_mode 
				debug_meniu();	
				#endif	
				}

				else if (menu_page==3){		//LDR meniu punktas
				work_mode=4;				//LDR - wmode
				EEPROM_write(25, work_mode);
				meniu=0;
				show_work_mode(); 
				wmode(work_mode);
				
				

				_delay_ms(200);
				LCD_LED_PORT &= ~_BV(LCD_LED_BIT); //isjungiam LCD pasvietima
				
				#if debug_mode 
				debug_meniu();	
				#endif	
				}
			}

			else meniu=meniu;
		}
		}
	}
//-------------------- end of sub menu routine --------------



//-------------------------- config ---------------------
	while(meniu!=0 && config==1){

		
		if(read_keypad()==1){	

		#if debug_mode
		PORTDDR(LED_PORT)^= (1<<LED1_BIT);
		send_string("nuspausta knopke confige\n\r");
		#endif

			//config meniu vaiksciojimas: arba iseinam i main meniu arba nueinam i sub config meniu
			if(meniu==3 && config==1){
			
					//exit meniu punktas
					if (config_menu_page==config_menu_page_max){ //iseijimas i work_mode();
						meniu=1;
						config=0;
						config_menu_page=0;	
						puslapiai();

						#if debug_mode 
						debug_meniu();	
						#endif		
					}
					
					//nuejimas i sub config meniu (minPWM, maxPWM, timeOUT ir LDRth nustatymai)
					else if (config_menu_page!=config_menu_page_max){
					meniu=3;
					config=2;
					
					//nuostato nustatymas (pasiziurim, kelintas fadein[] elementas atinka minPWM/maxPWM reiksme EEProme
					if (config_menu_page==0) nuostatas=nuostato_radimas(minPWM);
					else if (config_menu_page==1) nuostatas=nuostato_radimas(maxPWM);
					else nuostatas=nuostatas;

					puslapiai_config_2();
					
					#if debug_mode
					debug_meniu();
					#endif
				//	break;
					}

			
			}

			else config=config;
		}

	}

//---------------------- end of config -----------------------

//---------------------- sub config routine -------------------------

	while(meniu!=0 && config==2){

		
		if(read_keypad()==1){	

		#if debug_mode
		PORTDDR(LED_PORT)^= (1<<LED1_BIT);
		send_string("nuspausta knopke sub confige\n\r");
		#endif

		//isejimas is sub configo
		
		meniu=3;
		config=1;
		nuostatas=0;
		puslapiai_config();

		write_config();
		//OCR2=EEPROM_read(24);
		timer2_set(EEPROM_read(24));
		wmode(work_mode); //kad liktu tikrasis work_mode
		}

		else config=config;
	}

//---------------------- end of sub config routine ------------------

}

}