Example #1
0
void EEPROM_ByteWrite(u16 Address, u08 Data)
// Description:
//   Byte Write Operation. The communication via the I2C bus with an EEPROM
//   (2465) is realized. A data byte is written into a user defined address.
{

	/* i2c por SW */
#if (defined I2C_SW &&  I2C_SW == 1)
	sw_i2c_start();							// Send start signal
	sw_i2c_write(EEPROMAddress & 0b11111110);// Send identifier I2C address     0xA0 = 10100000b
	delay_time(I2C_DELAY);
	sw_i2c_write((unsigned char)(high_byte(Address)));// Send address to EEPROM (high byte address)
	delay_time(I2C_DELAY);
	sw_i2c_write((unsigned char) Address);// Send address to EEPROM  (low byte address) 
	delay_time(I2C_DELAY);
	sw_i2c_write(Data);// Send low byte to EEPROM  (data to write)
	delay_time(I2C_DELAY);// Delay a period of time to write   
	sw_i2c_stop();	   // Send I2C Stop Transfer
	delay_time(20);	   // Delay a period of time to write
	DelayTask(WRITE_CYCLE_TIME);
#else
	/* i2c por HW */

	IIC_transmite(EEPROMAddress, Address, &Data);

#endif
}
void game_exit(void)
{
    char choose;

    printf("\t\t\t:::::::::::::::::::\n");
    printf("\t\t\t:: You are dead! ::\n");
    printf("\t\t\t:::::::::::::::::::\n");
    delay_time(1);

    while(1)
    {
        printf("\n\t\tYou wanna play other time? (y/n):");
        scanf("%c", &choose);
        fflush(stdin);

        switch(choose)
        {
        case 'y':
            remove_garbage();
            player_data();
            game_start();
            break;
        case 'n':
            printf("\n\t\tThanks for play the game!\n");
            delay_time(1);
            clean_console();
            exit(1);

            break;
        default:
            printf("\n\t\tPlease input a valid option! (y/n)\n");
            break;
        }
    }
}
Example #3
0
void Alarm(void)
{
	   if((tempshuzhi>=70||dianya_zhi>=440||dianya_zhi<=340)&&alarm_lock==0)
	   	{   
                                           if(mybox.master==1)//主机发布通知延时信息
								  {
								       delay_time(80);
								  }
					GPIO_SetBits(GPIOA,GPIO_Pin_0);
					delay_us(100000);
                    GPIO_SetBits(GPIOA,GPIO_Pin_8);
		       set_now_mystatus(mystatus.myid,mystatus.size[0],mystatus.size[1],2,2,0,0);
		       LIGHT(mystatus.work_status[0],mystatus.work_status[1]);//过温常态
		       alarm_lock=1;

	   }
	 else if(tempshuzhi<70&&dianya_zhi<440&&dianya_zhi>340&&alarm_lock==1)
	 {
                             if(mybox.master==1)//主机
				 {    
				      delay_time(80);
				}
		    set_now_mystatus(mystatus.myid,mystatus.size[0],mystatus.size[1],0,0,0,0);
		    LIGHT(mystatus.work_status[0],mystatus.work_status[1]);//恢复常态
		    alarm_lock=0;
	 }

}
Example #4
0
/*---------------------------------------------------------------------------*/
INT8U RTC_RandomRead(INT8U Address)
// Description:
//   Random Read Operation. Data is read from the RTC. The RTC
//   address is defined with the parameter Address.
{

	INT8U data_in;
#if (defined I2C_SW &&  I2C_SW == 1)
	CRITICAL_SECTION_START();
	sw_i2c_start();							// Send start signal

	sw_i2c_write(DS1307Address);		// Send identifer I2C address  (10100000b)
	delay_time(I2C_DELAY);
	sw_i2c_write((INT8U) Address);			// Send address to EEPROM
	delay_time(I2C_DELAY);
	sw_i2c_start();							// Send I2C Start Transfer
	sw_i2c_write(DS1307Address | 1);	// Send identifer I2C address  (10100001b)
	delay_time(I2C_DELAY);
	data_in = sw_i2c_read(0);			// Read byte
	sw_i2c_stop();			 // Send I2C Stop Transfer
	
	CRITICAL_SECTION_END();
#else
	IIC_transmite(DS1307Address, Address, NULL);
	IIC_recebe(DS1307Address, &data_in);
#endif
	return data_in;

}
Example #5
0
/*---------------------------------------------------------------------------*/
u08 EEPROM_RandomRead(u16 Address)
// Description:
//   Random Read Operation. Data is read from the EEPROM. The EEPROM
//   address is defined with the parameter Address.
{

	char data_in;
#if (defined I2C_SW &&  I2C_SW == 1)
	sw_i2c_start();							// Send start signal

	sw_i2c_write(EEPROMAddress);// Send identifer I2C address  (10100000b)
	delay_time(I2C_DELAY);
	sw_i2c_write((unsigned char) (high_byte(Address)));// Send address to EEPROM
	delay_time(I2C_DELAY);
	sw_i2c_write((unsigned char) Address);// Send address to EEPROM
	delay_time(I2C_DELAY);
	sw_i2c_start();// Send I2C Start Transfer
	sw_i2c_write(EEPROMAddress + 1);// Send identifer I2C address  (10100001b)
	delay_time(I2C_DELAY);
	data_in = sw_i2c_read(0);// Read byte
	sw_i2c_stop();			 // Send I2C Stop Transfer
#else

	/* Dummy write: Transmite NULL depois gera um sinal de start repeated */
	IIC_transmite(EEPROMAddress, Address, NULL);
	IIC_recebe(EEPROMAddress, &data_in);
	

#endif
	return data_in;

}
Example #6
0
int  main()
{
	string localfile[100],project;
	string temp = "PROJECT\\";
	string path_file;
	int pro_num=18;
	int control = 0;
	

	localfile[0]="echo Y | ";
	localfile[1]="copy  ";//¿½±´ÃüÁî
	localfile[2]=" "+project+"\\configfile_all\\";//all_config dir
	localfile[3]=" "+project+"\\config_not_read\\";//config not read dir
	localfile[4]=" "+project+"\\config_read\\";//config already read dir
	localfile[5]="move  ";//Òƶ¯ÃüÁî
	localfile[6]="E:\\version\\P809V50\\P809V50.zip";//±¾µØ°æ±¾´æ·ÅÎļþ¼Ð(ĬÈÏ)
	localfile[7]=" "+project+"\\config_not_test\\";//δ²âÊԵİ汾·¾¶
	localfile[8]="10.63.220.2";
	localfile[9]="mw1101";
	localfile[10]="mw1101";
	localfile[11]="..\\Config_upload\\";
	localfile[12]="del ";
	localfile[13]="\\CI_version\\config_files";
	localfile[14]="M_P809V50*";
	localfile[15]="infofile.info";
	localfile[16]="infofile_open.info";
	localfile[17]="-";


	while(1)
	{
		open_project_config_ini(localfile);
		pro_num=18;
		control = open_project_config_ini(localfile);
		while(control >= 0){//if has the project name
			cout<<"<-- This is the "+localfile[pro_num]+" Project !"<<endl;
			project = temp + localfile[pro_num];
			localfile[2]=" "+project+"\\configfile_all\\";//all_config dir
			localfile[3]=" "+project+"\\config_not_read\\";//config not read dir
			localfile[4]=" "+project+"\\config_read\\";//config already read dir
			localfile[7]=" "+project+"\\config_not_test\\";//δ²âÊԵİ汾·¾¶
			config_ftp_mail(localfile,project,path_file);
			pro_num ++;
			control--;
			delay_time(10);
		}
		

		cout<<"<-- in this 100s , you can add the new project in the PROJECT dir -->"<<endl;
		delay_time(DELAY_TIME);
		
	}
	return 0;
}
Example #7
0
//------------------------------------------------------------------------------
// MAIN FUNCTION 
//------------------------------------------------------------------------------
void main (void)
{
	unsigned int eeprom_address;

	initialize_system();					// Initialize RS-232 and rest of system

	printf("\n\rKeil Software, Inc.\n\r");	// Display starup message
	printf("LPC764 MCU I2C Example Test Program\n\r");
	printf("Version 1.0.0\n\r");
	printf("Copyright 2000 - Keil Software, Inc.\n\r");
	printf("All rights reserved.\n\n\r");

	P1M1  = 0x0C;							// Set Port 1 Open Drain
	P1M2  = 0x0C;

	I2CFG = 0x22;							// Config byte: 0 MAS CLRT1 T1, 00 CC  (page 16)
											// In our case the config byte is:
										 	// Slave bit 	(7): 0 (we are not a slave)
										 	// Master bit 	(6): 0 (we are a master)
										 	// Clear T1 	(5): 1 (Clear TI) 
										 	// TI Run 		(4): 0 (set TI to run)
										 	// Not used		(3): 0 		
											// Not used		(2): 0 
										 	// CT 1			(1): 1 (Set for highest CPU clock rate)
											// CT 0			(0): 0 



	printf("Writing data to EEPROM....");
	for (eeprom_address = 0; eeprom_address < 75; eeprom_address++)
		write_byte((unsigned char)eeprom_address + 0x30, eeprom_address);

	printf("Done!\n\r");
	printf("Reading from EEPROM...ASCII table!\n\r");


	while (TRUE)							// Infinite loop, never exits
	{
		for (eeprom_address = 0; eeprom_address < 75; eeprom_address++)
		{
			delay_time(DELAY_BLINK);		// Blink LED with delay
			LED = ON;
			delay_time(DELAY_BLINK);
			LED = OFF;

			printf("Address: %3u	Character: %c\n\r", eeprom_address, read_byte(eeprom_address));
		}
	}
}
Example #8
0
void unload_power(status_list_node *list_1,status_list_node *list_2)
{
 u8 i,j;
 s8 label_busy1,label_busy2;
  turn_flag=1;
  led_on_off(0);
for(i=1;i<33;i++)inquiry_slave_status(i);
 label_busy2=sort_busynode_list_asc(sort_busy_list_2,list_2);
 label_busy1=sort_busynode_list_asc(sort_busy_list_1,list_1);


	for(j=1;j<=label_busy1&&label_busy1>0;j++)
		{
                     delay_time(5);
			myled();//计算功率,电压电流与显示按键分开
		   if(gonglvshishu<95)break;
		   else {	
						if((wugong_computer-wugong_95)>sort_busy_list_1[label_busy1].size)
				   {order_trans_rs485(mybox.myid,sort_busy_list_1[label_busy1].myid,1,1,0);delay_us(10000);label_busy1--;}

						if((wugong_computer-wugong_95)<=sort_busy_list_1[j].size)
				   {order_trans_rs485(mybox.myid,sort_busy_list_1[j].myid,1,1,0);delay_us(10000);}

		          }
	    }

if(gonglvshishu>95)
 {
	for(j=1;j<=label_busy2&&label_busy2>0;j++)
		{
                        delay_time(5);
	                 myled();//计算功率,电压电流与显示按键分开
		   if(gonglvshishu<95)break;
		   else{	                               
                                						if((wugong_computer-wugong_95)>sort_busy_list_2[label_busy2].size)
				   {order_trans_rs485(mybox.myid,sort_busy_list_2[label_busy2].myid,1,2,0);delay_us(10000);label_busy2--;}

			   if((wugong_computer-wugong_95)<=sort_busy_list_2[j].size)
		   	       {order_trans_rs485(mybox.myid,sort_busy_list_2[j].myid,1,2,0);delay_us(10000);}
                            

		           }
        }

}
				led_on_off(1);

}
//用于测试某些特殊情况的代码。
int test_timer_expire2(int /*argc*/, char * /*argv*/ [])
{
    ZCE_Timer_Queue_Base::instance(new ZCE_Timer_Wheel(1024));

    Test_Timer_Handler test_timer[10];
    int timer_id[10];
    ZCE_Time_Value delay_time(1, 0);
    ZCE_Time_Value interval_time(1, 0);
    for (size_t i = 0; i < TEST_TIMER_NUMBER; ++i)
    {
        delay_time.sec(i);
        timer_id[i] = ZCE_Timer_Queue_Base::instance()->schedule_timer(&test_timer[i],
            &TEST_TIMER_ACT[i],
            delay_time,
            interval_time);
    }

    //一些特殊情况下,定时器很长时间无法触发,导致的问题
    for (size_t j = 0; j < 100000; j++)
    {
        ZCE_LIB::sleep(60);
        ZCE_Timer_Queue_Base::instance()->expire();
        
    }
    ZCE_UNUSED_ARG(timer_id);
    return 0;
}
Example #10
0
//------------------------------------------------------------------------------
// Procedure:	write_byte
// Inputs:		data out, address
// Outputs:		none
// Description:	Writes a byte to the EEPROM given the address 
//------------------------------------------------------------------------------
void write_byte (unsigned char data_out, unsigned int address)
{
  	send_slave_address_I2C(0xA0); 			// Send I2C Start Transfer
       					         			// Send identifier I2C address
   	write_byte_I2C(high_byte(address)); 	// Send address to EEPROM
   	write_byte_I2C((unsigned char)address); // Send address to EEPROM
   	write_byte_I2C(data_out);          		// Send low byte to EEPROM
   	stop_I2C();                   			// Send I2C Stop Transfer
   	delay_time(DELAY_WRITE);       			// Delay a period of time to write
}
Example #11
0
TEST(ForkedProcessTest, TryWait)
{
	std::chrono::milliseconds delay_time(100);
	std::chrono::milliseconds for_time(200);
	slib::posix::forked_process fproc([delay_time]{
		std::this_thread::sleep_for(delay_time);
		return 0;
	});
	std::this_thread::sleep_for(for_time);
	ASSERT_TRUE(fproc.try_wait());
}
Example #12
0
TEST(ForkedProcessTest, Wait)
{
	std::chrono::milliseconds delay_time(100);
	auto before = slib::posix::monotonic_clock::now();
	slib::posix::forked_process fproc([delay_time]{
		std::this_thread::sleep_for(delay_time);
		return 0;
	});
	fproc.wait();
	auto after = slib::posix::monotonic_clock::now();
	ASSERT_LE(delay_time, after - before);
}
/* Run all modules of game */
game_modules(void)
{
    clean_console();
    goto_apple();
    move_modules();
    show_game();
    //set_key();

    delay_time(config.game_level); // Nivel.

    return (0);
}
Example #14
0
void RTC_ByteWrite(INT8U Address, INT8U Data)
// Description:
//   Byte Write Operation. The communication via the I2C bus with an EEPROM
//   (2465) is realized. A data byte is written into a user defined address.
{

#if (defined I2C_SW &&  I2C_SW == 1)
	CRITICAL_SECTION_START();
	sw_i2c_start();							// Send start signal
	sw_i2c_write(DS1307Address & 0b11111110);// Send identifier I2C address     0xA0 = 10100000b
	delay_time(I2C_DELAY);
	sw_i2c_write((INT8U) Address);// Send address to RTC  (byte address) 
	delay_time(I2C_DELAY);
	sw_i2c_write(Data);					// Send low byte to RTC  (data to write)
	delay_time(I2C_DELAY); // Delay a period of time to write   
	sw_i2c_stop();	   // Send I2C Stop Transfer
	delay_time(20);	   // Delay a period of time to write
	CRITICAL_SECTION_END();
#else
	IIC_transmite(DS1307Address, Address, &Data);
#endif
}
//------------------------------------------------------------------------------
// MAIN FUNCTION 
//------------------------------------------------------------------------------
void main (void)
{
	unsigned char index, voltage_out;

	initialize_system();

	printf("\n\rKeil Software, Inc.\n\r");	// Display starup message
	printf("MCB517 MCU I²C Example Test Program\n\r");
	printf("Version 1.0.0\n\r");
	printf("Copyright 2000 - Keil Software, Inc.\n\r");
	printf("All rights reserved.\n\n\r");

	printf("P8591 Test Program....Reading from ADC channel 0, Writing to DAC!\n\r");

	while (TRUE)
	{
		for (voltage_out = 0; voltage_out < 0xFF; voltage_out++)
		{

			write_dac(voltage_out);			// Write voltage value to DAC

											// Blink LEDs in sequence
			for (index = 0x01; index < 0x80; index <<=1)
			{
				P4 = index;
				delay_time(DELAY_BLINK);
			}
	  		for (index = 0x80; index > 0x01; index >>=1)
			{
				P4 = index;
				delay_time(DELAY_BLINK);
		   	}

											// Read voltage (ADC 0) and display results
   			printf("DAC output: %3bu     ADC Channel 0: %3bu\n\r", voltage_out, read_adc_channel(0x00));
		}
	}
}
Example #16
0
TEST(ForkedProcessTest, GetExitStatus)
{
	std::chrono::milliseconds delay_time(100);
	auto before = slib::posix::monotonic_clock::now();
	slib::posix::forked_process fproc([delay_time]{
		std::this_thread::sleep_for(delay_time);
		return EXIT_SUCCESS;
	});
	auto es = fproc.get_exit_status();
	auto after = slib::posix::monotonic_clock::now();
	ASSERT_LE(delay_time, after - before);
	ASSERT_EQ(es.type, slib::posix::exit_status::EXITED);
	ASSERT_EQ(es.code, EXIT_SUCCESS);
}
Example #17
0
TEST(ForkedProcessTest, WaitUntil)
{
	std::chrono::milliseconds delay_time(100);
	auto before = slib::posix::monotonic_clock::now();
	auto until_time = before + std::chrono::milliseconds(200);
	slib::posix::forked_process fproc([delay_time]{
		std::this_thread::sleep_for(delay_time);
		return 0;
	});
	ASSERT_TRUE(fproc.wait_until(until_time));
	auto after = slib::posix::monotonic_clock::now();
	ASSERT_LE(delay_time, after - before);
	ASSERT_GE(until_time, after);
}
/* Game Start */
void game_start(void)
{
    clean_console();
    player_data();
    printf("\n\t\t%s\n\t\t\t%s\n", game_name, author);
    delay_time(2);

    while(1)
    {
        /* Check if snake is dead */
        if(config.snake_status == 1) game_exit();

        game_modules();
        printf("\n");
    }
}
    virtual int timer_timeout(const ZCE_Time_Value &now_timenow_time,
                               const void *act)
    {
        char time_str[128];
        int timer_action = *(int *)act;
        std::cout << now_timenow_time.timestamp(time_str, 128) << " " << "Timer action =" << timer_action << std::endl;
        ZCE_Timer_Queue_Base::instance()->cancel_timer(this);

        ZCE_Time_Value delay_time(1, 0);
        ZCE_Time_Value interval_time(0, 0);

        int time_id = ZCE_Timer_Queue_Base::instance()->schedule_timer(this,
            &TEST_TIMER_ACT[timer_action-1],
            delay_time,
            interval_time);
        std::cout << now_timenow_time.timestamp(time_str, 128) << " " << "Timer id =" << time_id << std::endl;

        return 0;
    }
Example #20
0
INT8U RTC_DS1307_Init(void)
{
#if (defined I2C_SW &&  I2C_SW == 1)
	INT8U ret = NO_I2C_ACK;
	CRITICAL_SECTION_START();
		sw_i2c_init();
	CRITICAL_SECTION_END();
	
	sw_i2c_start();							// Send start signal
	ret = sw_i2c_write(DS1307Address);		// Send identifer I2C address  (10100000b)
	delay_time(I2C_DELAY);
	sw_i2c_stop();	
	
	return ((ret == OK_I2C_ACK) ? TRUE : FALSE);
	
#else
	IIC_init();
#endif

}
Example #21
0
void app_rgb_led(void)
{
		red_on();
		delay_time(BLINK_DELAY);	/* Red */
		red_off();
		green_on();
		delay_time(BLINK_DELAY);	/* Green */
		green_off();
		blue_on();
		delay_time(BLINK_DELAY);	/* Blue */
		red_on();
		delay_time(BLINK_DELAY);	/* Blue + Red */
		green_on();
		blue_on();
		delay_time(BLINK_DELAY);	/* Red + Green */
		red_off();
		blue_on();
		delay_time(BLINK_DELAY);	/* Green + Blue */
		red_on();
		delay_time(BLINK_DELAY);	/* Green + Blue + Red */
		green_off();
		blue_off();
}
Example #22
0
void offset_idlepower()  //功率补偿函数,三个参数 无功功率 功率因数 空闲队列
{
 u8 i,j;
 s8 label_idle1,label_idle2;
  turn_flag=1;
  led_on_off(0);
for(i=1;i<33;i++)inquiry_slave_status(i);
 label_idle1=sort_idlenode_list(sort_idle_list_1,system_status_list_1);
  label_idle2=sort_idlenode_list(sort_idle_list_2,system_status_list_2);

	for(j=1;j<=label_idle1;j++)
		{
                         if(done_list1_flag==0)
                            {

				   for(i=0;i<33;i++)
				   	    {
                                          idle_done_nodelist_1[i]=0;

				           }
				   done_list1_flag=1;
			       }
			delay_time(5);
				myled();
		              if(gonglvshishu>90)break;
		                 else{
                    if((wugong_computer)>=(sort_idle_list_1[j].size))
			             {    if(idle_done_nodelist_1[sort_idle_list_1[j].myid]==0)
			                   {
			                   order_trans_rs485(mybox.myid,sort_idle_list_1[j].myid,1,1,1);delay_us(10000);
                                          idle_done_nodelist_1[sort_idle_list_1[j].myid]=1;
					    }
					}
					done_count_1++;
					if(done_count_1==label_idle1)
						{done_count_1=0;done_list1_flag=0;}
		   	                  }
		   }

	
 	if(gonglvshishu<90)
 		{
	for(j=1;j<=label_idle2;j++)
		{
		                         if(done_list2_flag==0)
                            {

				   for(i=0;i<33;i++)
				   	    {
                                          idle_done_nodelist_2[i]=0;

				           }
				   done_list2_flag=1;
			       }

                                     delay_time(5);
                                     myled();
		   if(gonglvshishu>90)break;
		   else{
                          if((wugong_computer)>=(sort_idle_list_2[j].size))
                          	            {  if(idle_done_nodelist_2[sort_idle_list_2[j].myid]==0)
                          	                {     
						  order_trans_rs485(mybox.myid,sort_idle_list_2[j].myid,1,2,1);delay_us(10000);
                                                 idle_done_nodelist_2[sort_idle_list_2[j].myid]=1;
                          	                }
						  done_count_2++;
						  	if(done_count_2==label_idle2)
						  		{done_count_2=0;done_list2_flag=0;}
						  
						  }
		   	 }
	    }

 		}
		led_on_off(1);

}