赶紧撸串代码把点亮个流水灯吧,不然怎么好意思睡觉啊,SOC keil插件安装和keil配置部分不再啰嗦了,直接上代码: 红蓝流水灯代码:你爱我我爱你,流水似情,永远不分离...................... /************************** led.c文件*************************************/
#include "bsp/led.h"
sbit Led_R = P4^6;
sbit Led_B = P4^7;
// LED点亮
// 参数:LED_R LED_B
void Led_ON(Led_TypeDef led)
{
if(led ==LED_R)
Led_R = 0;
else if(led ==LED_B)
Led_B = 0;
}
// LED熄灭
// 参数:LED_R LED_B
void Led_OFF(Led_TypeDef led)
{
if(led ==LED_R)
Led_R = 1;
else if(led ==LED_B)
Led_B = 1;
}
//LED翻转操作
// 参数:LED_R LED_B
void Led_Toggle(Led_TypeDef led)
{
if(led ==LED_R)
{
Led_R==1?(Led_R=0):(Led_R=1);
}
else if(led ==LED_B)
{
Led_B?(Led_B=0):(Led_B=1);
}
}
/************************** led.h文件*************************************/
Led.h文件
#ifndef _LED_H_
#define _LED_H_
#include "H/SC95F861x_C.H"
typedef enum
{
LED_R = 0,
LED_B = 1
}Led_TypeDef;
void Led_ON(Led_TypeDef led);
void Led_OFF(Led_TypeDef led);
void Led_Toggle(Led_TypeDef led);
#endif
/************************** main.c文件*************************************/
#include "H/Function_Init.H"
#include "bsp/led.h"
void main(void)
{
IO_Init();
Timer_Init();
while(1)
{
}
}
/************************************************/
//定时器0中断
void timer0() interrupt 1
{
unsigned int count;
TL0 = (65536 - 16000)%256;
TH0 = (65536 - 16000)/256;
count++;
if(count == 1000)
{
count = 0;
Led_Toggle(LED_R);
Led_Toggle(LED_B);
}
}
|