📄 main.c
字号:
/******************************************************************/
/*Copyright (C), 2008-2009, 力天电子,LiTian Tech.Co.Ltd. */
/* Module Name : GPIO */
/* File Name : main.c */
/* Author : 侯长波 */
/* Create Date : 2009/12/27 */
/* Version : 2.0 */
/* Function : */
/* Description : */
/* Support : www.LT430.com */
/******************************************************************/
/*****************头文件********************/
#include "DSP281x_Device.h"
#include "System.h"
/****************端口宏定义*****************/
#define S1 GpioDataRegs.GPEDAT.bit.GPIOE2
#define S2 GpioDataRegs.GPBDAT.bit.GPIOB8
#define S3 GpioDataRegs.GPBDAT.bit.GPIOB9
#define S4 GpioDataRegs.GPBDAT.bit.GPIOB10
/****************常量宏定义*****************/
/***************全局变量定义****************/
unsigned int temp;
/****************函数声明*******************/
void Init_LED(void);
void Scan_Key(void); //扫描键盘
void Manage_Key1(void); //按键1处理程序
void Manage_Key2(void); //按键2处理程序
void Manage_Key3(void); //按键3处理程序
void Manage_Key4(void); //按键4处理程序
/*------------------------------------------*/
/*形式参数:void */
/*返回值:void */
/*函数描述:主函数 */
/*------------------------------------------*/
void main(void)
{
InitSysCtrl(); // 系统初始化子程序,在DSP28_sysctrl.c中
Init_LED();
GpioDataRegs.GPBSET.all |=0x00FF;
temp=0x0001;
GpioDataRegs.GPBCLEAR.all |=temp;
while(1)
{
if((S1==0)|(S4==0))//扫描是否按键按下
Scan_Key();
}
}
/*------------------------------------------*/
/*形式参数:void */
/*返回值:void */
/*函数描述:扫描键值 */
/*------------------------------------------*/
void Scan_Key(void)
{
unsigned int i;
for(i=0;i<10000;i++); //键盘消抖动
if(S1==0)
Manage_Key1();
else if(S4==0)
Manage_Key4();
while((S1==0)|(S4==0));
}
/*------------------------------------------*/
/*形式参数:void */
/*返回值:void */
/*函数描述:按键的处理程序 */
/*------------------------------------------*/
void Manage_Key1(void) //左移
{
if(temp!=0x0080)
{
GpioDataRegs.GPBSET.all |=temp;
temp<<=1;
GpioDataRegs.GPBCLEAR.all |=temp;
}
}
void Manage_Key2(void)
{
}
void Manage_Key3(void)
{
}
void Manage_Key4(void)//右移
{
if(temp!=0x0001)
{
GpioDataRegs.GPBSET.all |=temp;
temp>>=1;
GpioDataRegs.GPBCLEAR.all |=temp;
}
}
/*------------------------------------------*/
/*形式参数:void */
/*返回值:void */
/*函数描述:初始化LED端口 */
/*------------------------------------------*/
void Init_LED(void)
{
EALLOW;
GpioMuxRegs.GPBDIR.all |=0x00FF;
EDIS;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -