ing (unsigned char *s)
{
while (*s != \0)
{
UART0_SendByte(*s++);
}
}
(2)、main.c源文件
#include"includes.h"
volatile unsigned long SysTickCnt;
unsigned char LedOnMeg[] = "Led 1 On!\r\n";
unsigned char LedOffMeg[] = "Led all Off!\r\n";
unsigned char KeyMeg[] = "key push down \r\n";
unsigned char OpenString[][50] = {
"**********************************************\r\n",
"****--欢迎光临--****\r\n",
"****小野兽的小草窝^_^****\r\n",
"**** http://blog.ednchina.com/ytfdhb/****\r\n",
"****我是懒猫爱飞,我的口号是:****\r\n",
"****每天进步一点点,开心多一点^_^****\r\n",
"**********************************************\r\n"
};
unsigned int key_sta = 0;
unsigned int key_pre = 1;
unsigned int key_old = 1;
unsigned int led_flag = 0;
unsigned intStepCnt = 0;
void SysTick_Handler (void)
{
SysTickCnt++;
}
void DelayMs (unsigned long tick)
{
unsigned long systickcnt;
systickcnt = SysTickCnt;
while ((SysTickCnt - systickcnt) < tick);
}
void PortInit(void)
{
GPIO1->FIODIR = 0xB0000000;
GPIO2->FIODIR = 0x0000007C;
LedAllOff();
}
void KeyScan()
{
key_pre = KEY_EN ;
if(!KEY_EN )
{
if(key_old)
{
if(key_pre == 0)
{
key_sta = 1;
}
}
}
key_old = key_pre;
}
void KeyHandle(void)
{
if(key_sta == 1)
{
StepCnt++;
if(StepCnt == 9)
{
UART0_SendString (LedOffMeg);
}
if(StepCnt < 9)
{
LedOnMeg[4] = StepCnt+0x30;
UART0_SendString (LedOnMeg);
}
key_sta = 0;
}
}
void LedHandle()
{
switch(StepCnt)
{
case 1:Led1On();
break;
case 2:Led2On();
break;
case 3:Led3On();
break;
case 4:Led4On();
break;
case 5:Led5On();
break;
case 6:Led6On();
break;
case 7:Led7On();
break;
case 8:Led8On();
break;
case 9:LedAllOff();
StepCnt = 0;
break;
default:break;
}
}
int main(void)
{
unsigned int i = 0;
SystemInit();
SysTick_Config(SystemFrequency/1000 - 1);
PortInit();
UARTInit(0,19200);
for(i=0;i<7;i++)
{
UARTSend(0,OpenString[i],50);
}
//LedOnMeg[4] = 4+0x30;
//UART0_SendString (KeyMeg);
while(1)
{
KeyScan();//按键扫描
KeyHandle(); //按键处理
LedHandle(); // Led处理程序
}
}
程序不是太难,只是简单的实验,各个部分都有详细的注释,这里不在总结,下面是挨靠结果串口调试助手截图:
图1-2串口助手截图
好了,先总结到这吧,最近手头上的事有点多,所以写日志的时间就有点紧张,不过,工作归工作,该学习的东东还是要坚持学习的,没有足够的时间,那就见缝插针的学吧。