亲爱的StackOverflowers:
我有兴趣做一个声悬浮DIY项目,但我有一个esp 32 qC,我不知道等效的DDRC寄存器。下面的代码:
//made by milespeterson101
//published on 6/17/2022
//heres the code (:
byte TP = 0b10101010; // Every other port receives the inverted signal
void setup() {
DDRC = 0b11111111; // Set all analog ports to be outputs
// Initialize Timer1
noInterrupts(); // Disable interrupts
TCCR1A = 0;
TCCR1B = 0;
TCNT1 = 0;
OCR1A = 200; // Set compare register (16MHz / 200 = 80kHz square wave -> 40kHz full wave)
TCCR1B |= (1 << WGM12); // CTC mode
TCCR1B |= (1 << CS10); // Set prescaler to 1 ==> no prescaling
TIMSK1 |= (1 << OCIE1A); // Enable compare timer interrupt
interrupts(); // Enable interrupts
}
ISR(TIMER1_COMPA_vect) {
PORTC = TP; // Send the value of TP to the outputs
TP = ~TP; // Invert TP for the next run
}
void loop() {
// Code ends here (:
}
有关该项目的更多详细信息,请访问:https://create.arduino.cc/projecthub/milespeterson101/ultrasonic-levitation-acoustic-levitation-experiment-8050f8
提前感谢!
我原以为它不需要任何代码修改就能工作,但不幸的是,我在这一点上卡住了。
1条答案
按热度按时间ncecgwcz1#
我不确定是否可以用中断来完成,但是这个代码应该和你的代码做的差不多。40Khz信号的时间周期是12.5uS,所以检查是否已经超过了12uS应该关闭。