標(biāo)題: CC2530跑馬燈代碼 [打印本頁(yè)]

作者: 碩夜    時(shí)間: 2020-5-19 10:45
標(biāo)題: CC2530跑馬燈代碼
#include <ioCC2530.h>
#define uint unsigned int
#define uchar unsigned char
#define LED1 P1_0         //LED1 為 P1.0 口控制
#define KEY1 P0_1              //KEY1 為 P0.1 口控制
//函數(shù)聲明
void Delayms(uint);              //延時(shí)函數(shù)
void InitLed(void);              //初始化 LED1
void KeyInit();              //按鍵初始化
uchar KeyScan();              //按鍵掃描程序
/**************************** 延時(shí)函數(shù)*****************************/
void Delayms(uint xms)              //i=xms 即延時(shí) i 毫秒
{
uint i,j;
for(i=xms;i>0;i--)
for(j=587;j>0;j--);
}
/**************************** LED 初始化函數(shù)*****************************/
void InitLed(void)
{
P1DIR |= 0x01;              //P1_0 定義為輸出 LED1 = 1;              //LED1 燈熄滅
}
/**************************** 按鍵初始化函數(shù)*****************************/
void InitKey()
{
P0SEL &= ~0X2;              //設(shè)置 P01 為普通 IO 口
P0DIR &= ~0X2;              //按鍵在 P01 口,設(shè)置為輸入模式
}
/**************************** 按鍵檢測(cè)函數(shù)*****************************/
uchar KeyScan(void)
{
if(KEY1==0)
{
Delayms(10);
if(KEY1==0)
{
while(!KEY1);            
return 1;            
}
}
return 0;            
}
/*************************** 主函數(shù)***************************/
void main(void)
{
InitLed();              //調(diào)用初始化函數(shù) InitKey();
while(1)
{
if(KeyScan())              //按鍵改變 LED 狀態(tài) LED1=~LED1;
}
}






歡迎光臨 (http://www.torrancerestoration.com/bbs/) Powered by Discuz! X3.1