📄 main.c
字号:
#include "systemInit.h"
#include "uartGetPut.h"
#include <stdio.h>
#include <string.h>
// 定义LED
#define LED_PERIPH SYSCTL_PERIPH_GPIOG
#define LED_PORT GPIO_PORTG_BASE
#define LED_PIN GPIO_PIN_2
// 主函数(程序入口)
int main(void)
{
char s[40];
int size;
jtagWait(); // 防止JTAG失效,重要!
clockInit(); // 时钟初始化:晶振,6MHz
uartInit(); // UART初始化
SysCtlPeriEnable(LED_PERIPH); // 使能LED所在的GPIO端口
GPIOPinTypeOut(LED_PORT, LED_PIN); // 设置LED所在管脚为输出
uartPuts("Please input a command with <Enter>:\r\n"); // 请输入一个命令,按回车执行
uartPuts("\t on = LED turns on\r\n"); // 输入on点亮LED
uartPuts("\t off = LED turns off\r\n"); // 输入off熄灭LED
for (;;)
{
uartPuts("cmd>");
size = uartGets(s, sizeof(s)); // 从UART接收命令字符串
if (size > 0)
{
if (!strcmp(s, "on")) // 如果输入on
{
GPIOPinWrite(LED_PORT, LED_PIN, 0x00); // 点亮LED
}
else if (!strcmp(s, "off")) // 如果输入off
{
GPIOPinWrite(LED_PORT, LED_PIN, 1 << 2); // 熄灭LED
}
else
{
uartPuts("Error command\r\n"); // 错误命令
}
uartPuts("OK\r\n");
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -