示例#1
0
int read_ir_pulses(void)
{
	uint16_t highpulse, lowpulse; // temporary storage timing

	currentpulse = 0;
	if(IRDATA) {
		return(0);
	}
	for(;;) {
		highpulse = lowpulse = 0; // start out with no pulse length

		while(IRDATA) {
			highpulse++;
			TIMER_Delay(TIMER2, RESOLUTION);
			if (((highpulse >= MAXPULSE) /*&& (currentpulse != 0)*/) || currentpulse == NUMPULSES) {
				return currentpulse;
			}
		}
		pulses[currentpulse][0] = highpulse;

		while(IRDATA == 0) {
			lowpulse++;
			TIMER_Delay(TIMER2, RESOLUTION);
			if (((lowpulse >= MAXPULSE) /*&& (currentpulse != 0)*/) || currentpulse == NUMPULSES) {
				return currentpulse;
			}
		}
		pulses[currentpulse][1] = lowpulse;

		currentpulse++;
	}
}
示例#2
0
//lazy way to make a delay, could be vastly improved...
void delay_ms(uint32_t ms)
{
	while(ms >= 1000) {
		TIMER_Delay(TIMER2,1000 * 1000);
		ms -= 1000;
	}
	TIMER_Delay(TIMER2,ms);
}
示例#3
0
/**
 * @brief Send data in hex format to terminal.
 * @param buf Data buffer.
 * @param length Number of bytes to send.
 * @warning Uses blocking delays so as not to overflow buffer.
 */
void hexdump(uint8_t* buf, uint32_t length) {

  uint32_t i = 0;

  while (length--) {

    printf("%02x ", buf[i]);

    i++;
    // new line every 16 chars
    if ((i % 16) == 0) {
      printf("\r\n");
    }
    // delay every 50 chars
    if ((i % 50) == 0) {
      TIMER_Delay(100); // Delay so as not to overflow buffer
    }
  }
}
示例#4
0
int Timer_Delay_Example(void)
{
    /* Init System, IP clock and multi-function I/O
       In the end of SYS_Init() will issue SYS_LockReg()
       to lock protected register. If user want to write
       protected register, please issue SYS_UnlockReg()
       to unlock protected register if necessary */
    SYS_Init();

    /* Init UART to 115200-8n1 for print message */
    UART_Open(UART0, 115200);

    printf("\nThis sample code use timer to create a small delay \n");
    while(1) {
        printf("Delay 1 second\n");
        TIMER_Delay(TIMER0, 1000000);
    }

}