コード例 #1
0
ファイル: inits.c プロジェクト: Keik633/ruby-1.7.3
void
rb_call_inits()
{
    Init_sym();
    Init_var_tables();
    Init_Object();
    Init_Comparable();
    Init_Enumerable();
    Init_Precision();
    Init_eval();
    Init_String();
    Init_Exception();
    Init_Thread();
    Init_Numeric();
    Init_Bignum();
    Init_Array();
    Init_Hash();
    Init_Struct();
    Init_Regexp();
    Init_pack();
    Init_Range();
    Init_IO();
    Init_Dir();
    Init_Time();
    Init_Random();
    Init_signal();
    Init_process();
    Init_load();
    Init_Proc();
    Init_Math();
    Init_GC();
    Init_marshal();
    Init_version();
}
コード例 #2
0
ファイル: bus.c プロジェクト: Rogaven/megafries
void Init_MMU( void* Cartridge_p)
{
	assert( Cartridge_p != NULL);

	Cartridge = Cartridge_p;

	// Read_Map
	int i;
	for( i = 0; i < 0x40; i++)
		Read_Map[i] = &Read_Cartridge;

	Read_Map[0xA0] = &Read_z80;
	Read_Map[0xA1] = &Read_A1;
	Read_Map[0xC0] = &Read_VDP;

	Read_Map[0xFF] = &Read_RAM;

	// Write_Map
	Write_Map[0xA0] = &Write_z80;
	Write_Map[0xA1] = &Write_A1;
	Write_Map[0xC0] = &Write_VDP;

	Write_Map[0xFF] = &Write_RAM;

	// Init all components
	Init_IO();
	Init_VDP();

	my_M68k = M68k_Init( &Read_From_Memory, &Write_To_Memory, &Read_Interrupt_Controler);
}
コード例 #3
0
ファイル: a7common.c プロジェクト: 928dk/44k22-BRD2-a21
void Init44k22(void)
{
//OSC int 16MHz (62.5ns/inst.)
OSCCONbits.IRCF2 = 1;
OSCCONbits.IRCF1 = 1;
OSCCONbits.IRCF0 = 1;
while(!OSCCONbits.HFIOFS); //wait until ready

//Uart1
ANSELCbits.ANSC7 = 0; //Port C7 select som digital port
ANSELCbits.ANSC6 = 0; //Port C6 select som digital port

//Uart2
ANSELDbits.ANSD7 = 0; //Port D7 select som digital port
ANSELDbits.ANSD6 = 0; //Port D6 select som digital port

//Leds
ANSELAbits.ANSA3 = 0; //Port A3 select som digital port Red
ANSELEbits.ANSE1 = 0; //Port E1 select som digital port Green
ANSELEbits.ANSE2 = 0; //Port E2 select som digital port Blue

//InitTimer0();
InitTimer1();
//InitTimer2();
InitTimer3();

InitUart1();
InitUart2();

Init_IO();
}
コード例 #4
0
ファイル: main.c プロジェクト: 928dk/touchsense-18f26k20
void Init26k20(){

    //OSC int 16MHz (62.5ns/inst.)
OSCCONbits.IRCF2 = 1;
OSCCONbits.IRCF1 = 1;
OSCCONbits.IRCF0 = 1;
OSCCONbits.SCS1 = 1;

while(!OSCCONbits.IOFS); //wait until ready

//dioder

ANSEL=0x00; //set ports som digitale
ANSELH=0x00;

//input
//ANSELBbits.ANSB0 = 1; //Port B0 som analog
//ANSELBbits.ANSB1 = 1; //Port B1 som analog
//ANSELBbits.ANSB2 = 1; //Port B2 som analog


//InitTimer0();
InitTimer1();
//InitTimer2();
InitTimer3();

InitUart1();

Init_IO();


}
コード例 #5
0
ファイル: inits.c プロジェクト: MSch/MacRuby
void
rb_call_inits()
{
    Init_PreSymbol();
    Init_id();
    Init_var_tables();
    Init_Object();
    Init_Class();
    Init_VM();
    Init_Encoding();
    Init_Comparable();
    Init_Enumerable();
    Init_Precision();
    Init_String();
    Init_Symbol();
    Init_Exception();
    Init_eval();
    Init_jump();
    Init_Numeric();
    Init_Bignum();
    Init_syserr();
    Init_Array();
    Init_Hash();
    Init_ENV();
    Init_Struct();
    Init_Regexp();
    Init_pack();
    Init_marshal();
    Init_Range();
    Init_IO();
    Init_Dir();
    Init_Time();
    Init_Random();
    Init_signal();
    Init_process();
    Init_load();
    Init_Proc();
    Init_Binding();
    Init_Math();
    Init_GC();
    Init_Enumerator();
    Init_Thread();
    //Init_Cont();
    Init_Rational();
    Init_Complex();
    Init_version();
    Init_PostGC();
    Init_ObjC();
    Init_BridgeSupport();
    Init_FFI();
    Init_Dispatch();
    Init_Transcode();
    Init_sandbox();
    Init_PostVM();
}
コード例 #6
0
void Init(void)
{
    CLKPR = _BV(CLKPCE); // enable clock scalar update
    CLKPR = 0x00;	// set to 8Mhz
    PORTC = 0xff;	// all off
    DDRC  = 0xff; 	// show byte in leds
    usart0_init( 51 );	// 9600 baud at 8MHz

    Init_IO ();
    Spi_p_Init ();      // Initialization (polling)

}
コード例 #7
0
ファイル: if-main.c プロジェクト: urnest/urnest
   GMC_DCL(char**, argv)
{
   boolean Abort, NewFlag;
   int i;

   Init_IO();
   Init_Err();
   Init_Env();
   Init_Sigs(FALSE);
   IPC_Init();
   IPC_Action = TopLevelCI;

   if (IsServer) {
      Init_Sigs(TRUE);
      Read_DrvGrf();
      Init_Info(&NewFlag);
      Init_FilHdrs();
      Init_FilInps();
      Init_FilElms();
      Init_FilPrm();
      Init_FilHdrTree();
      Activate_Client(LocalClient);
      if (NewFlag) {
	 Write_ENV2(); }/*if*/; }/*if*/;

   if (IsClient) {
      IsTTY = GetIsTTY();
      Init_Vars();
      Init_CWD(); }/*if*/;

   Read_ENV2();

   if (IsClient) {
      if (VerifyLevel >= 1) Test_All();

      if (argc <= 1) {
	 Get_Commands(&Abort);
	 Exit((Abort?1:0)); }/*if*/;

      for (i=1; i<argc; i+=1) {
	 ;/*select*/{
	    if (strlen(argv[i]) == 0) {
	       Get_Commands(&Abort);
	    }else{
	       TopLevelCI(&Abort, argv[i]); };}/*select*/;
	 if (Abort) {
	    Exit(1); }/*if*/; }/*for*/;
      Exit(0); }/*if*/;

   IPC_Get_Commands(&Abort, (tp_Str)NIL);
   Exit((Abort?1:0));
   return 0; /*to make lint happy*/
   }/*main*/
コード例 #8
0
void main(void)
{
    // Hardware Initialization
    TRISIO = 0xFF; // All IO are inputs to be safe
    GPIO = 0x00; // All IO to 0
    //ANSEL = 0x00; // Turn off ADC
    CMCON = 7; // Turn off Comparators

    Init_Timers(); // Initialize Timers (TMR0)

    Init_IO(); // Initialize In-and-Outputs

    while (On) // Infinite loop
    {
        CLRWDT();
    }
}
コード例 #9
0
ファイル: main.c プロジェクト: DanZhang6/NIM-A-Project
/*********************************
*            主函数
**********************************/
void main()
{ 
    //uchar i;
	Init_IO();                                    //I/O口初始化,
	Init_MCU();                                   //主函数初始化,T0定时器工作在方式1初始化,显示"请稍等,初始化中",GATE=0,
	Init_RAM();                                   //位变量初始化
	Init_Para();                                  //参数初始化,初始化参数,从IIC读取阈值等信息赋予给参量
	Init_Buf();									//并口通讯数组初始化
//	Select_Mast();                                //判断主从机	
	Init_Time0();	                             //开启定时器0。定时器0初始化,工作在方式一,定时初值:H:0xDC,L:0x00;中断计数初始化?定时5ms,NumT0=0;
    Lcd_Clear();								//LCD清屏
	Lcd_Start();								//显示"清华大学/n核能与新能源技术研究院"
	EX0=1;                                        //只允许外部0中断,中断0为键盘
	IT0=1;                                        //外部中断0 
	while(1)
	{  	
//	   BackUp_Display();	
	   Select_Mast();                                //判断主从机,写入主从机标志Flag_Mast=1(主机)0(从机)
	   key_function(); 								//按键功能,在while循环中不断检测按键标志,按键标志由按键外部中断来更改
	   if(Flag_Tim0)	                         //8253计数定时结束时,读取探头的计数,刚开始Flag_Tim0=0,仅当Flag8253Counting计数定时标识为1,且计数器中断次数大于设定的中断次数时,Flag_timo才会等于1
	    {										//Flag_Tim0为计数器结束标志,初始为0,开机打开定时器中断后,定时器5ms中断一次,检查Flag_Tim0一次,为一表示计数器计时结束
			Flag_Tim0 = 0;		                 //定时标志清0
			Flag_Warn = 0;		                 //报警标志清0
			GetAndDisdata(); 	                 //从8253的锁存器得到测量计数器结果,存入至buf数组
			ShowData();                          //显示测量数据 
			shortdelay(1000);	          		//
	        Transfer();                          //并行传输数据
//			bakeup_conv_data();           
			Init_8253();   						//初始化8253
			                                      //定时结束时,立刻又开始初始化进行计数
	   }
	    if(Flag_Tim0 == 0)                        //开启8253计数过程中,处理报警中断,报警有中断吗?
       {
			if(Flag_Warn_Flash == 1)                   //主机LED指示灯闪烁间隔定时,Flag_Warn_Flash为LED灯闪烁标志
			{
				Flag_Warn_Flash = 0;
	            Led_Flash();
			}
			if((Flag_Warn_Led==1) && (PCOLSIG==0))      //屏幕上红灯闪烁间隔定时,程序中没有找到PCOLSIG=0的程序段
			{	
				Flag_Warn_Led = 0;
				RedLed_Flash();							//灯闪烁
			 } 
	    }
	}             
}
コード例 #10
0
void
rb_call_inits()
{
    Init_sym();
    Init_id();
    Init_var_tables();
    Init_Object();
    Init_top_self();
    Init_Encoding();
    Init_Comparable();
    Init_Enumerable();
    Init_Precision();
    Init_String();
    Init_Exception();
    Init_eval();
    Init_jump();
    Init_Numeric();
    Init_Bignum();
    Init_syserr();
    Init_Array();
    Init_Hash();
    Init_Struct();
    Init_Regexp();
    Init_pack();
    Init_transcode();
    Init_marshal();
    Init_Range();
    Init_IO();
    Init_Dir();
    Init_Time();
    Init_Random();
    Init_signal();
    Init_process();
    Init_load();
    Init_Proc();
    Init_Binding();
    Init_Math();
    Init_GC();
    Init_Enumerator();
    Init_VM();
    Init_ISeq();
    Init_Thread();
    Init_Cont();
    Init_version();
}
コード例 #11
0
//=====================================================================================================================
int main (void)
{
	BYTE*	pReadBuffer;
	BYTE*	pWriteBuffer;
	DWORD	Version;

	PINSEL0		=	0;
	PINSEL1		=	0;

	Init_IO();
	CLK_Init();
	CLK_SetupTimer(cCLK_TimerBlink,	500,	Main_BlinkLED);

	CMD_Init((DWORD*)&pWriteBuffer,	(DWORD*)&pReadBuffer);


	IOCLR	=	cPB_LED1	+	cPB_LED2	+	cPB_LED3;
	while(1)
	{
		IOCLR	=	cPB_LED1;
		if	(!CMD_GetVersion((WORD*)(&Version)))
		{
			continue;
		}
		if	(!(CMD_Detect()))
		{	continue;	}
		IOSET	=	cPB_LED1;


		//等待But0按下,则开始写数据
		if	(IOPIN	&	cPB_BUT0)
		{	continue;	}

		DoTest2(pReadBuffer,	pWriteBuffer);

	}

}
コード例 #12
0
ファイル: main.cpp プロジェクト: ruifig/nutcracker
int main (int argc, char** argv)
{
	ENABLE_LEAK_CHECK();

#if defined(SHELL_PLATFORM_WINDOWS)
	SetConsoleTitle("Squirrel Shell " SHELL_VERSION_STR " (" SHELL_CPUARCH ")");
#else
	stderrIsRedirected = !isatty(2);
#endif

	// Parse command line arguments.
	const char* fileName	= NULL;
	bool		interactive = argc == 1;
	int			firstArg	= 0,
				i;
	bool isDebug = false;
	int debuggerPort = 0;
	for (i = 1; argv[i]; ++i)
	{
		char* arg = argv[i];

		if (!strcmp(arg, "-h") || !strcmp(arg, "--help"))
		{
			printf("Squirrel Shell %s for %s on %s (" __DATE__ ")\n"
				   SHELL_VERSION_COPYRIGHT "\n"
				   "\n"
				   "This is free software, and comes WITHOUT ANY WARRANTY; without even the implied\n"
				   "warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n"
				   "General Public License for more details.\n"
				   "\n"
				   "MD5 hash calculation code (c) Colin Plumb\n"
				   "PCRE (c) University of Cambridge\n"
				   "Squirrel (c) Alberto Demichelis\n"
				   "zlib (c) Jean-loup Gailly and Mark Adler\n"
				   "\n"
				   "Usage:\n"
				   "   squirrelsh [options] [script_file] [script_arguments]\n"
				   "\n"
				   "Options:\n"
				   "   -h, --help          Display this text\n"
				   "   -d<PORT>            Enable the debugger, in the specified port\n"
				   "   -i, --interactive   Run shell in interactive mode\n"
				   "                       If script file is specified, it will be executed before\n"
				   "                       entering this mode\n"
				   "   -s, --silent        Do not display error and warning messages\n"
				   "   -v, --version       Display shell version number\n"
				   "\n"
				   "Examples:\n"
				   "   squirrelsh                    Run shell in interactive mode\n"
				   "   squirrelsh foo.nut            Run foo.nut script without arguments\n"
				   "   squirrelsh -i foo.nut 1 2 3   Run foo.nut script with arguments \"1\", \"2\"\n"
				   "                                 and \"3\", and switch into interactive mode\n",
				   SHELL_VERSION_STR,
				   SHELL_PLATFORM,
				   SHELL_CPUARCH);

			return EXIT_SUCCESS;
		}
		else if (!strncmp(arg, "-d", 2))
		{
			// RVF +
			isDebug = true;
			debuggerPort = std::atoi(arg + 2);
			if (debuggerPort == 0)
			{
				printf("No debugger port specified\n");
				return EXIT_FAILURE;
			}
			// RVF -
		}
		else if (!strcmp(arg, "-i") || !strcmp(arg, "--interactive"))
			interactive = true;
		else if (!strcmp(arg, "-v") || !strcmp(arg, "--version"))
		{
			printf("%s\n", SHELL_VERSION_STR);
			return EXIT_SUCCESS;
		}
		else if (!strcmp(arg, "-s") || !strcmp(arg, "--silent"))
			silent = true;
		else
		{
			// First unreserved argument will be treated as script file name.
			fileName = arg;
			firstArg = i;
			break;
		}
	}

	if (!fileName && !interactive)
	{
		PrintError("ERROR: Script file not specified.\n");
		return EXIT_FAILURE;
	}

	// Initialize Squirrel.
	sqvm = sq_open(1024);
	if (!sqvm)
	{
		PrintError("ERROR: Failed to create Squirrel VM.\n");
		return EXIT_FAILURE;
	}

	sqstd_seterrorhandlers(sqvm);

	HSQREMOTEDBG rdbg = nullptr;
	if (isDebug)
	{
		rdbg = sq_rdbg_init(sqvm, debuggerPort, SQTrue);
		sq_enabledebuginfo(sqvm, SQTrue);

		//!! SUSPENDS THE APP UNTIL THE DEBUGGER CLIENT CONNECTS
		scprintf("Waiting for the debugger to connect...\n");
		if (!SQ_SUCCEEDED(sq_rdbg_waitforconnections(rdbg)))
		{
			PrintError("ERROR: Failed to connect to the debugger.\n");
			return EXIT_FAILURE;
		}
		scprintf(_SC("Connected to the debugger\n"));
	}


	//sq_setcompilererrorhandler(sqvm, SquirrelCompileError);

	_RPT0(_CRT_WARN, "--- Squirrel initialized\n");

	// Register some globals.
	SetSqString("SHELL_VERSION", SHELL_VERSION_STR, SQTrue);
	SetSqString("SQUIRREL_VERSION", SQUIRREL_VERSION_SHORT, SQTrue);
	SetSqString("PLATFORM", SHELL_PLATFORM, SQTrue);
	SetSqString("CPU_ARCH", SHELL_CPUARCH, SQTrue);

	// Initialize libraries.
	Init_Base();
	Init_IO();
	Init_File();
	Init_Math();
	Init_Util();
	Init_Hash();
	Init_RegExp();

	_RPT0(_CRT_WARN, "--- Libraries initialized\n");

	// Set up global variables...
	sq_pushroottable(sqvm);

	// RVF +
	// Initialize squirrel std libraries
	//sqstd_register_bloblib(sqvm);
	sqstd_register_iolib(sqvm); // We need this one because of the handy "dofile" function
	sqstd_register_stringfunctions(sqvm); // This registers only some string functions that are useful and don't clash with Squirrel Shell
	// NOTE: Not registering the other libraries, because there are name clashing between Squirrel Shell and SqStdLib
	//sqstd_register_systemlib(sqvm);
	//sqstd_register_mathlib(sqvm);
	//sqstd_register_stringlib(sqvm);
	// RVF -


	// ... number of command line arguments...
	sq_pushstring(sqvm, "__argc", -1);
	sq_pushinteger(sqvm, SQInteger(argc - firstArg));
	if (SQ_FAILED(sq_newslot(sqvm, -3, SQFalse)))
	{
		PrintError("ERROR: Failed to create \"__argc\" integer value.\n");
		Shutdown();
		return EXIT_FAILURE;
	}

	// ... and arguments themselves.
	sq_pushstring(sqvm, "__argv", -1);
	sq_newarray(sqvm, 0);
	for (i = firstArg; argv[i]; ++i)
	{
		sq_pushstring(sqvm, argv[i], -1);
		sq_arrayappend(sqvm, -2);
	}
	if (SQ_FAILED(sq_newslot(sqvm, -3, SQFalse)))
	{
		PrintError("ERROR: Failed to create \"__argv\" array.\n");
		Shutdown();
		return EXIT_FAILURE;
	}
	sq_pop(sqvm, 1);

	// Load and run script.
	SQInteger result = EXIT_SUCCESS;
	if (fileName && LoadScript(fileName))
	{
		sq_pushroottable(sqvm);
		if (SQ_FAILED(sq_call(sqvm, 1, SQTrue, isDebug ? SQTrue : SQFalse)))
		{
			if (!silent)
			{
				const SQChar* errMsg = "Unknown error.";
				sq_getlasterror(sqvm);
				if (sq_gettype(sqvm, -1) == OT_STRING)
					sq_getstring(sqvm, -1, &errMsg);

				PrintError("ERROR: %s\n", errMsg);
			}
			Shutdown();
			return EXIT_FAILURE;
		}

		// Get script execution result.
		if (sq_getvmstate(sqvm) == SQ_VMSTATE_SUSPENDED)
			result = retCode;
		else
		{
			if (sq_gettype(sqvm, -1) == OT_INTEGER)
				sq_getinteger(sqvm, -1, &result);
		}

		// Pop everything except root table.
		sq_settop(sqvm, 1);
	}

	// Enter interactive mode (if necessary).
	if (interactive)
	{
		SQChar cmd[MAX_CMD_LENGTH + 1];
		do
		{
#if defined(SHELL_PLATFORM_WINDOWS)
			GetCurrentDirectory(sizeof(cmd), cmd);
#else
			getcwd(cmd, sizeof(cmd));
#endif
			cmd[sizeof(cmd) - 1] = 0;

			printf("%s> ", ConvPath(cmd, SQFalse));
			fgets(cmd, MAX_CMD_LENGTH, stdin);
			if (SQ_FAILED(sq_compilebuffer(sqvm, cmd, SQInteger(strlen(cmd)), "", SQTrue)))
				continue;

			sq_pushroottable(sqvm);
			if (SQ_FAILED(sq_call(sqvm, 1, SQFalse, SQFalse)) && !silent)
			{
				const SQChar* errMsg = "Unknown error.";
				sq_getlasterror(sqvm);
				if (sq_gettype(sqvm, -1) == OT_STRING)
					sq_getstring(sqvm, -1, &errMsg);

				PrintError("ERROR: %s\n", errMsg);
			}
		} while(sq_getvmstate(sqvm) != SQ_VMSTATE_SUSPENDED);
		result = retCode;
	}

	if (isDebug)
	{
		sq_rdbg_shutdown(rdbg);
	}

	Shutdown();
	return int(result);
}
コード例 #13
0
void main()
{
  P6DIR|=BIT1;//发光二极管
  P6OUT|=BIT1;
    
  P1DIR|=BIT0;//给fpga的信号
  P1OUT&=~BIT0;
  
  
    WDTCTL = WDTPW + WDTHOLD;   //关闭看门狗
    Init_CLK();
    Ini_Lcd();
    Init_IO();
    Init_LDC1000();

 Port_init();  
   delay_ms(100);                         //延时100ms
  while(1)
    {



 Key_Scan();                       //键盘扫描,看是否有按键按下
      if(key!=0xff)                     //如果有按键按下,则显示该按键键值1~4
        {
	  {
            switch(key)
              {
	        case 1: LED8 = 0xFC; arange=key1;break;        //给不同的键赋键值,键值1,亮2个LED灯
                case 2: LED8 = 0xF3;arange=key2;break;        //给不同的键赋键值,键值2,亮2个LED灯
                case 3: LED8 = 0xCF;arange=key3;break;	 //给不同的键赋键值,键值3,亮2个LED灯
                case 4: LED8 = 0x3F;arange=key4;break;	 //给不同的键赋键值,键值4,亮2个LED灯
              }

          }
	
       }
     else
      {
        //LED=key;              	//没有按键的时候显示上次的键值
      }
      
        proximtyData[0]  = spi_readByte(LDC1000_CMD_PROXLSB);
        proximtyData[1]  = spi_readByte(LDC1000_CMD_PROXMSB);
        frequencyData[0] = spi_readByte(LDC1000_CMD_FREQCTRLSB);
        frequencyData[1] = spi_readByte(LDC1000_CMD_FREQCTRLSB+1);
        frequencyData[2] = spi_readByte(LDC1000_CMD_FREQCTRLSB+2);
        proximtyDataMAX = ((unsigned char) proximtyData[1]<<8) + proximtyData [0];
        frequencyDataMAX =((unsigned char)frequencyData[1]<<8) + frequencyData[0];
        disNum(proximtyDataMAX%10+0x30,0x86);
        disNum(proximtyDataMAX/10%10+0x30,0x85);
        disNum(proximtyDataMAX/100%10+0x30,0x84);
        disNum(proximtyDataMAX/1000%10+0x30,0x83);
        disNum(proximtyDataMAX/10000%10+0x30,0x82);
      
        a = spi_readByte(LDC1000_CMD_REVID);
  
        if(proximtyDataMAX>arange)
        {
          P6OUT&=~BIT1;//灯亮
          P1OUT|=BIT0;//给fpga高电平,表示发现硬币
        }
        else 
        {
          P6OUT|=BIT1;
          P1OUT&=~BIT0;
        }
        _NOP();
    }
}
コード例 #14
0
ファイル: Init.c プロジェクト: tnctroboconb/Program
void Init_Device(){
    Init_Frequency();
    Init_IO();
}
コード例 #15
0
ファイル: main.c プロジェクト: 928dk/44k22-BRD2-a21
int main(void)
{
Init44k22();
Init_HW();
Init_IO();

InitBlue();
//UART_Init();
//UART2_Init();
UART2IntInit();

//MENU.B = 1;

ENABLEGINT; //enable general interrupts
ENABLEPINT; //enable port interrupts

u16 counter = 0; //(maks 65535)
int counter2 = 0;

unsigned char chartemp;
unsigned char btbuffer[64]; //bluetooth buffer
unsigned char bt = 0; //en byte fra bluetooth (char)
unsigned char index = 0; //indeks // tæller

unsigned char rxstate=0; //modtage status
unsigned char dataok =0; //status for data

CheckBlueR2();

//SetPowerBlue(1);
Delay10x(10);

do //mainloop ... stuff runs forever in a circle
{
counter++;

//GetAddrR2();
//PORT_GREEN = !PORT_GREEN;

if (counter == 16383)//1/4 to max of counter
    {

    }


if (counter == 32767)//halfway to max of counter (sprintf/uart laver overflow med xc8 == -32737)
    {
     
    }

if (counter == 49151)// 3/4 to max of counter
    {
   counter2++;
        if (counter2 == 10) //kører hver 655 350 gang
        {
          
         //GetAddrR2();
         counter2 = 0;
        }
    }

if (counter == 65534) //almost at max
        {
       
//        ConnectBlue();
//        GetAddrR2();
//        CheckBlueR2();
        
        //ShowBlueConfig();
           

        }



if (!dataok)
                {
                bt = UART2IntGetChar(&chartemp);
                }
            else
                bt= 0;
       if(bt)
       {
           //Send_Wiegand(chTemp);
           //PORT_BLUE = !PORT_BLUE;
            switch (rxstate)
            {
                   case 0:
                          if (chartemp == 0x0D) //\r 0x0D CR
                            {
                            rxstate = 1;
                            }

                          break;
                    case 1:
                           if (chartemp == 0x0A) //\n 0x0A  LF
                            {
                            rxstate = 2;

                            }
                           else
                           {
                               rxstate = 0;
                           }
                           break;
                    case 2:
                    {
                         btbuffer[index] = chartemp; //overfør til buffer
                         if ((btbuffer[index -1] == 0x0D) && (btbuffer[index] == 0x0A) ) //\r 0x0D CR //\n 0x0A  LF
                            {
                             dataok = 1;
                             index = 0;
                             rxstate = 0;
                             break;
                         }

                         index++; // naeste placering

                    }
                    break;
             }
           }
        

if (dataok)
{

    do
    {

    Send_Wiegand(btbuffer[index]);
    index++;

    }
    while (btbuffer[index] != 0x0A);

    Send_Wiegand(btbuffer[index]);
    index = 0;
    dataok = 0;
}



if (counter == 65535) //counter has reached max
        {
        counter = 0;
        }

ClrWdt();

} while(1);

//forhaabentligt kommer vi aldrigt ud af while loekken
}