This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

[参考译文] MSP430G2553:MSP430简单红外通信

Guru**** 2553260 points


请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

https://e2e.ti.com/support/microcontrollers/msp-low-power-microcontrollers-group/msp430/f/msp-low-power-microcontroller-forum/795562/msp430g2553-msp430-simple-ir-communication

器件型号:MSP430G2553

大家好、我是 MSP430的乞丐。

我想通过使用 IR 按下两个不同的按钮来创建两个不同的 LED。

我认为发送器工作正常、但接收器有问题。  

RX:

#include 

void init (void);
void configClock (void);

void configTimer (void);
void startTimer (void);
void stopTimer (void);
void clearTimer (void);
unsigned int readTimer (void);
void listen_IR (void);
unsigned int time_in_low;
unsigned int time_in_high;
int a;


int main (void)
{
WDTCTL = WDTPW | WDTHOLD;//停止看门狗计时器
P1DIR = BIT0|BIT6;
P1REN = BIT3;
P1OUT = BIT3;
init();

while (1)
{
listen_IR();
}



void listen_IR (void)
{
if ((P1IN & BIT3)!=BIT3){//下降沿
起始计时器();}
if ((P1IN & BIT3)=BIT3){//

上升沿= readTimer (stopa); //读取计时器以检测 PWM 长度
clearTimer();
}

如果(a>8000 && a<10000){//如果发送器发送9ms PWM
P1OUT^=0x01;
__DELAY_CYCLS (500000);
}
如果(a>3000 && a<6000){
P1OUT






INIT^=0x40;//如果发送器发送4.5ms PWM_CONFIGCLK 周期(







void);
{=500MHz CLC1MHz);// CC1MHz (void Clock =
0x1MHz);{=CLC1MHz (p1)
//设置范围
DCOCTL = CALDCO_1MHz;//设置 DCO 步骤+调制
}

void configTimer (void)
{
TACCR1 = 20000;
}

void clearTimer (void)
{
TACTL |= TACLR;
}

void stopTimer (void)
{
TACTL = 0;
}

void startTimer (void)
{
TACCTL1 &=~CCIFG; //清除超时标志
TACTL = tassel_2 + MC_2;//时钟源:SMCLK,模式2:最多计数0xFFFF
}
无符号 int readTimer (void)
{
返回 TAR;
} 

    TX:

#include 

void init (void);
void configClock (void);
void configTimer (void);
void startTimer (void);
void stopTimer (void);
void clearOUT 计时器(void);
unsigned int readTimer (void);
void listen_IR (void);



int main (void)
{
WDTCTL = WDTPW | WDTHOLD;//停止看门狗计时器
BCSCTL1 = CALBC1_1MHz;//设置范围
DCOCTL = CALDCO_1DIR
= 0x00;
P2REN
= 0x00;P2REDIR
= 0x00;P2RETP0;

int i;

while (1)
{
if (!(P1IN & 0x08)){
for (i=0;i<692;i++){// 38kHz、9ms %50 dutycycle PWM 信号周期=26us
P2OUT^=0x01;
__delay_cycles (10);





delay}if (!(P1IN & 0x01);I p2381ms);I p2out^周期=50ms);I = 0x381+(0+);I p2p2pn = 50ms)



  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。
    您好!

    您需要使用示波器检查 TX 波形是否正确、而不是检查"A"是否正确。