我刚刚开始学习单片机,有些问题无法解决。
我尝试通过外接一个信号来控制 Led 1 的闪烁。 一个高电位 LED 闪一下。
我该如何实现?
求 程序 。
求 讲解。
另求 学习 430 的一些好的书籍。 万分感谢!
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.
MJ pan,
你可以直接将连接外接信号的管脚配置为输入,读取其管脚的电平,若为高电平,则控制LED(对应管脚为输出)闪一下。另外,关于多长时间读取一下输入管脚的电平,你可以使用定时器定时读取,也可以用while(1) 循环读取。
如果假设P1.0控制LED,假设输出高电平,LED灯亮,输出低电平,LED灯灭。 P1.1作为外接信号的输入管脚。则你可以按如下方式写程序:
#include <msp430.h>
int main(void)
{
WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer
P1DIR |= BIT0; // Set P1.0 to output direction
P1DIR &=~BIT1; //P1.1 as input
while(1)
{
if(P1IN & BIT1)
{
P1OUT |= BIT0; //P1.0 output high level
__delay_cycles(500000);// 0.5s delay
P1OUT &=~ BIT0;//P1.0 output low level
__delay_cycles(500000);// 0.5s delay
}
}
}