本帖最后由 sinanjj 于 2010-9-19 09:25 编辑
用lpcxpress编译程序如下.#include "LPC11xx.h"
int main(void)
{
SystemInit();
unsigned char aaa[1000];
unsigned long p;
#define BAUDRATE 115200
NVIC_DisableIRQ(UART_IRQn);
LPC_IOCON->IO1_6 = 0xc1; // UART RXD
LPC_IOCON->IO1_7 = 0xc1; // UART TXD
LPC_SYSCON->SYSAHBCLKCTRL |= (1<<12); // Enable UART clock
LPC_SYSCON->UARTCLKDIV = 0x1; // divided by 1
LPC_UART->LCR = 0x83; // 8 bits, no Parity, 1 Stop bit
uint32_t Fdiv;
Fdiv = (((SystemCoreClock/LPC_SYSCON->SYSAHBCLKDIV)/LPC_SYSCON->UARTCLKDIV)/16)/BAUDRATE;
LPC_UART->DLM = Fdiv/256;
LPC_UART->DLL = Fdiv%256;
LPC_UART->LCR = 0x03; // DLAB = 0
LPC_UART->FCR = 0x07; // Enable and reset TX and RX FIFO.
Fdiv = LPC_UART->LSR; // Read to clear the line status.
p=&p;
LPC_UART->THR = p;LPC_UART->THR = p>>8;LPC_UART->THR = p>>16;LPC_UART->THR = p>>24;
unsigned char i;
p=&i;
LPC_UART->THR = p;LPC_UART->THR = p>>8;LPC_UART->THR = p>>16;LPC_UART->THR = p>>24;
unsigned char i1;
p=&i1;
LPC_UART->THR = p;LPC_UART->THR = p>>8;LPC_UART->THR = p>>16;LPC_UART->THR = p>>24;
unsigned char i2;
p=&i2;
LPC_UART->THR = p;LPC_UART->THR = p>>8;LPC_UART->THR = p>>16;LPC_UART->THR = p>>24;
LPC_UART->THR = i;LPC_UART->THR = i1;LPC_UART->THR = i2;
LPC_IOCON->IO2_6 = 0x000000c0; // Hi-Z
LPC_GPIO3->DIR = 0x00000030; // GPIO3_4, GPIO3_5 output. now 1
LPC_GPIO3->MASKED_ACCESS[0x030] = 0x00000000; // GPIO3_5, GPIO3_4 output 0
for (;;) {
if (LPC_GPIO2->MASKED_ACCESS[0x040] == 0x00000000) LPC_GPIO3->MASKED_ACCESS[0x010] = 0xffffffff; // GPIO3_4 output 1
else LPC_GPIO3->MASKED_ACCESS[0x010] = 0x00000000; // GPIO3_4 output 0
}
}
重点在这里:
- p=&p;
- LPC_UART->THR = p;LPC_UART->THR = p>>8;LPC_UART->THR = p>>16;LPC_UART->THR = p>>24;
- unsigned char i;
- p=&i;
- LPC_UART->THR = p;LPC_UART->THR = p>>8;LPC_UART->THR = p>>16;LPC_UART->THR = p>>24;
- unsigned char i1;
- p=&i1;
- LPC_UART->THR = p;LPC_UART->THR = p>>8;LPC_UART->THR = p>>16;LPC_UART->THR = p>>24;
- unsigned char i2;
- p=&i2;
- LPC_UART->THR = p;LPC_UART->THR = p>>8;LPC_UART->THR = p>>16;LPC_UART->THR = p>>24;
- LPC_UART->THR = i;LPC_UART->THR = i1;LPC_UART->THR = i2;
检测变量的地址. 通过串口打印
运行, 跑到 LPC_UART->THR = i;LPC_UART->THR = i1;LPC_UART->THR = i2;这里必死.
串口结果! 如图:
lpc1111的ram地址是0x1000 0000开始, 到0x1000 0800结束!
关键的问题是: 变量的地址变化: D0-D7-D6-D5 后边分配变量跑死..... |