| LM3S811使用心得—从零开始学Cortex-M3内核单片机(三) 关于EK_LM3S811不可不知的资料
 
 
 
 
 实验2 基于EK-LM3S811实现UART0通讯
 EK-LM3S811自带了Key、LED和FT2232D虚拟出来的串口。
 
 FT2232D虚拟出来的串口是已经跟LM3S811的uart0连接的,所以,基于uart0的程序都可以直接用这个Stellaris virtual serial COMport。
 
 1,Error: failed to execute 'BIN40\ArmCC'  运行Keil 时出现的问题?
 “C:\Keil\ARM\BIN40\ArmCC.EXE”这个程序不在了。重装了一次Keil,变得好用了。
 
 2,Project -> Option for Target……或者按快捷键Alt+F7。在Target标签里,Xtal输入板子对应的晶振6MHz,这个设置错了的话,可能会导致程序下载不了。C/C++标签里,在Include Paths里添加
 
 点击“…”按钮。
 
 点击StellarisWare_for_EK-LM3S811,因为inc/和driverlib/两个文件夹位于StellarisWare_for_EK-LM3S811文件夹内。然后确定。
 
 3,添加.lib文件的方法。
 
 前提:把TI给的StellarisWare_for_EK-LM3S811解压出来放在一起,我放在C:\TI\StellarisWare_for_EK-LM3S811。
 Lib文件位于C:\TI\StellarisWare_for_EK-LM3S811\driverlib\rvmdk
 使用lib文件,不需要提供源码c文件给别人,起到了一定的保密效果。只需要把lib及函数的说明和使用方法交给用户,用户直接调用即可。
 注意:.lib文件并没有包含宏定义等信息,所以,和.lib配套的.h文件是不能省掉的。
 
 
 源程序:
 
 #include"inc/hw_types.h"
 #include"inc/hw_memmap.h"
 #include"driverlib/gpio.h"
 #include"driverlib/uart.h"
 
 //防止JTAG失效,上电或者复位时按下板上的USER按键,进去此函数,板上LED一直闪烁。
 voidJtagWait(void)
 {
 
 unsigned long i;
 
 SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOC);
 // 使能KEY、LED所在的PC端口
 
 GPIOPinTypeGPIOInput(GPIO_PORTC_BASE,GPIO_PIN_4);
 // 设置KEY所在管脚PC4为输入
 
 GPIOPinTypeGPIOOutput(GPIO_PORTC_BASE,GPIO_PIN_5 );
 // 设置LED所在管脚PC5为输出
 
 if (GPIOPinRead(GPIO_PORTC_BASE,GPIO_PIN_4) == 0x00)
 // 若复位或上电时按下KEY,则进入
 
 {
 
 
 while(1)
 //死循环,以等待JTAG连接,LED闪烁
 
 {
 
 for(i=0;i<200000;i++);
 
 GPIOPinWrite(GPIO_PORTC_BASE,GPIO_PIN_5,GPIO_PIN_5);
 //点亮LED
 
 for(i=0;i<200000;i++);
 
 GPIOPinWrite(GPIO_PORTC_BASE,GPIO_PIN_5,~GPIO_PIN_5);
 //熄灭LED
 
 }
 
 }
 
 SysCtlPeripheralDisable(SYSCTL_PERIPH_GPIOC);
 // 禁止KEY所在的GPIO端口
 }
 
 // Send
 strings to the UART0.
 voidUart0SendStrings(unsigned char *pStr)
 {
 
 while((*pStr!='\0'))
 
 {
 
 //Sends the character ucData to thetransmit FIFO for the specified port.
 
 //If there is no space available inthe transmit FIFO, this
 
 //function will wait until there isspace available before return-ing.
 
 UARTCharPut(UART0_BASE, *(pStr++));
 //发送字符,若FIFO满,自动等待
 
 //Writes the character ucData tothe transmit FIFO for the speci?ed port.
 
 //This function does not block, soif there is no space available,
 
 //then a false is returned, and theapplication will have to retry the function later.
 
 //UARTCharPutNonBlocking(UART0_BASE,*(pStr++));
 //发送字符,若FIFO满,返回false
 
 }
 }
 
 //主函数
 int main(void)
 {
 
 //函数开始,调用Jtag防锁死程序
 
 JtagWait();
 
 // Set the clocking to run directly fromthe crystal.配置时钟
 
 SysCtlClockSet(SYSCTL_SYSDIV_1 |SYSCTL_USE_OSC | SYSCTL_OSC_MAIN |
 
 SYSCTL_XTAL_6MHZ);
 
 // Enable the peripherals used by thisexample.
 
 SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0);
 
 SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);
 
 // Set GPIO A0 and A1 as UART pins.
 
 GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0| GPIO_PIN_1);
 
 // Configure the UART for 9600, 8-N-1operation.
 
 UARTConfigSetExpClk(UART0_BASE,SysCtlClockGet(), 9600,
 
 (UART_CONFIG_WLEN_8 |UART_CONFIG_STOP_ONE |
 
 UART_CONFIG_PAR_NONE));
 
 //发送一串字符
 
 Uart0SendStrings("Hello,21ic!\n");
 
 Uart0SendStrings("I'mreayfei!\n");
 
 while(1)
 
 {
 
 ;
 
 }
 }
 |