// // IR Output Demo // -- defaults to 80MHz w/5MHz crystal #include #define MS_001 (CLKFREQ / 1000) void main() { for(;;) { ir_out(16, 38000, 5); pause(45); } } void ir_out(int pin, int freqout, int ms) { ms *= CLKFREQ / 1000; // convert to system ticks CTRA = (0b00100 << 26) | pin; // set counter for NCO FRQA = (0x8000_0000 / ((CLKFREQ >> 1) / freqout)); // set frqx for desired frequency setpin(pin, 0); // make pin output low waitcnt(CNT + ms); // hold ms milliseconds CTRA = 0; // counter off getpin(pin); // float pin } void pause(uint32_t ms) { uint32_t t, i; t = CNT; for(i = 0; i < ms; i++) { waitcnt(t += MS_001); } }