工具与软件:
为什么 main ()不跳到 l_delay ()? 请注意 l_delay()子例程中的 while (1)。 这会导致程序崩溃。 但 无论对 l_delay ()执行什么操作、主循环仍然以65kHz 的频率运行。
此操作在使用 ICC 编译器的 Atmel 处理器(及其端口和位标签)上按预期运行。 多年来、我一直使用类似这样的粗略延迟例程。
#define bit_tst(A,B) (A & B)
#define bit_set(A,B) A |= B
#define bit_clr(A,B) A &= ~B
#define bit_tog(A,B) A ^= B
#include <msp430f149.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
//#include "ILI9163lcd.c"
// button ports
#define BUTN_ENTER !P6IN,BIT0
#define BUTN_UP !P6IN,BIT1
#define BUTN_DOWN !P6IN,BIT2
#define BUTN_LEFT !P6IN,BIT3
#define BUTN_RIGHT !P6IN,BIT4
#define RUN_LED_ON() bit_set(P2OUT,BIT7)
#define RUN_LED_OFF() bit_clr(P2OUT,BIT7)
static init_ports(void)
{
P1DIR = 0xFF;
P2DIR = 0xFF;
P6DIR = 0x0;
P1OUT = 0x0;
P2OUT = 0x0;
P6OUT = 0x1F; // pull ups
}
void l_delay(int d)
{
int a,b;
while(1);
for (a = 0; a < d; a++)
for (b = 0; b < d; b++);
}
int main()
{
WDTCTL = (WDTPW | WDTHOLD); // stop watchdog timer
init_ports();
// init_uart();
RUN_LED_OFF();
// ILI9163_init(0);
RUN_LED_ON();
while(1)
{
l_delay(1000);
RUN_LED_OFF();
l_delay(1000);
RUN_LED_ON();
}
}
