Example #1
0
void main(void)
{
  RCC_HSECLKInit();
  WatchDogOn();
  SysInit();
  BootProc();
}
Example #2
0
void main(void) {
	uint8_t result;
	uint8_t timeout;

	OSCCON=0xFF;	//16 MHz
	ANSELA=0;
	ANSELC=0;
	nWPUEN=1;
	
#ifdef _1LCD	
	LCDInit();
	LCDCommand(0x01);	
#endif


#ifdef DEBUG_HILOCNT
	uint8_t	low1,low2,low3;
	uint8_t high1,high2,high3;
	uint8_t i,j;
	for (;;) {
		low1=low2=low3=0;
		high1=high2=high3=0;
		for (uint8_t i=1; i<7; i++) {
			CLRWDT();
			SetMode(i);
			if (adc1<10) low1++;
			if (adc2<10) low2++;
			if (adc3<10) low3++;
			if (adc1>245) high1++;
			if (adc2>245) high2++;
			if (adc3>245) high3++;
		}
	
		CLRWDT();
		SetLed(0);	for (j=0; j<100; j++) __delay_ms(10);
		CLRWDT();
		if (low1==0) low1=9; 
		SetLed(low1); __delay_ms(10);
		CLRWDT();
		SetLed(0);	for (j=0; j<30; j++) __delay_ms(10);
		CLRWDT();
		if (low2==0) low2=9; 
		SetLed(low2); __delay_ms(10);
		CLRWDT();
		SetLed(0);	for (j=0; j<30; j++) __delay_ms(10);
		CLRWDT();
		if (low3==0) low3=9; 
		SetLed(low3); __delay_ms(10);
		CLRWDT();
		SetLed(0);	for (j=0; j<30; j++) __delay_ms(10);
		CLRWDT();
		if (high1==0) high1=9; 
		SetLed(high1); __delay_ms(10);
		CLRWDT();
		SetLed(0);	for (j=0; j<30; j++) __delay_ms(10);
		CLRWDT();
		if (high2==0) high2=9; 
		SetLed(high2); __delay_ms(10);
		CLRWDT();
		SetLed(0);	for (j=0; j<30; j++) __delay_ms(10);
		CLRWDT();
		if (high3==0) high3=9; 
		SetLed(high3); __delay_ms(10);
		CLRWDT();
		SetLed(0);	for (j=0; j<30; j++) __delay_ms(10);
		CLRWDT();
	}	
#endif


	// Loop here forever - or at least until  we timeout and go into
	// permanent low-power sleep that can only be awakened by a reset
	timeout=TIMEOUT;
	for (;;) {
//		VREGPM=0; 	// Fast wakeup
		CLRWDT();
		WatchDogOn();
		// Try to identify the connected transistor
		result=Measure();
		CLRWDT();

		// If no transistor is found just briefly flash the power-on LED
		if (result==RES_NONE) {
			SetLed(LED_PWR);
		} else {
			// We have identified a transisor type and pinout, so flash the
			// right LEDs and also reset the timeout
			timeout=TIMEOUT;
			if (result&RES_NPN) SetLed(LED_NPN);
			if (result&RES_PNP) SetLed(LED_PNP);
			if (result&RES_NCH) SetLed(LED_NCH);
			__delay_ms(5);
			SetLed(result&0x0f);
			if (result&RES_NCH) {
				__delay_ms(5);
				SetLed(LED_PWR);
			}	
		}
		__delay_ms(5);
		SetLed(LED_OFF);

		// Check if it's time to shut down and go into a deep sleep
		// that will only be awakened by pressing the Reset/Power button
		if (--timeout==0) Shutdown();

		// Sleep for a few hundred mS to conserve power and then wake up by the watchdog
		// and make a new measurement
		CLRWDT();
		SLEEP();
	}


}