Files
2025-02-MPX/ccs/ir.c
2025-12-10 02:26:47 +09:00

51 lines
930 B
C
Executable File

#include "ir.h"
#include "Clock.h"
void ir_init(void) {
P5->SEL0 &= ~0x08;
P5->SEL1 &= ~0x08;
P5->DIR |= 0x08;
P5->OUT &= ~0x08;
P9->SEL0 &= ~0x04;
P9->SEL1 &= ~0x04;
P9->DIR |= 0x04;
P9->OUT &= ~0x04;
P7->SEL0 &= ~0xff;
P7->SEL1 &= ~0xff;
P7->DIR &= ~0xff;
}
void ir_read_ready() {
P7->DIR = 0xff;
P7->OUT &= ~0xff; /* initially offed */
P5->OUT |= 0x08;
P9->OUT |= 0x04;
P7->OUT |= 0xff; /* init charge the caps */
Clock_Delay1us(10);
P7->DIR = 0x00; /* set input */
}
void ir_read_value(uint8_t *value) {
int i;
*value = P7->IN;
}
void ir_read_off() {
P5->OUT &= ~0x08;
P9->OUT &= ~0x04;
}
void test_ir(void) {
uint8_t ir_value;
while (1) {
ir_ready_ready();
Clock_Delay1us(1000); // 1ms
ir_read_value(&ir_value);
print_binary(ir_value);
printf("\n");
ir_read_off();
}
}