cc2530设计性实验代码八
作者:互联网
主函数
#include<ioCC2530.h>
#include"common.h"
#define uint unsigned int
#define uchar unsigned char
#define slave_node
enum STATE{STOP_STATE,RUN_STATE};
enum STATE state=STOP_STATE;
uchar led1_flag=0,led2_flag=0,key1_flag=0,key2_flag=0;
void InitTimer1(void)
{
CLKCONCMD|=(0x01<<3);
T1CC0L=62500&0xff;
T1CC0H=((62500&0xff00)>>8);
T1STAT &=~0x02;
TIMIF |=0x40;
IEN1|=(0x01<<1);
T1CTL = 0x0F;
}
void InitExternalInterrupt(void)
{
P0INP|= 0x82;
PICTL|= 0x01;
P0IEN|= 0x02;
IEN1|= 0x20;
}
void Ledfun(){
if(led1_flag == 0&&led2_flag == 0){
LED1=0;LED2=0;
}
if(led1_flag == 1&&led2_flag == 0){
LED1=1;LED2=0;
}
if(led1_flag == 0&&led2_flag == 1){
LED1=0;LED2=1;
}
if(led1_flag == 1&&led2_flag == 1){
LED1=1;LED2=1;
}
}
void main(void)
{
InitLed();
SystemClockSourceSelect(XOSC_32MHz);
InitTimer1();
InitExternalInterrupt();
EA = 1;
while(1){
Ledfun();
}
}
#pragma vector=P0INT_VECTOR
__interrupt void EINT_ISR(void)
{
EA = 0;
if(P0IFG & 0x02)
{
while(!P0_1);
Delay(10);
while(!P0_1);
key1_flag=!key1_flag;
P0IFG &=~0x02;
}
if(P0IFG & 0x80)
{
while(!P0_7);
Delay(10);
while(!P0_7);
key2_flag=!key2_flag;
P0IFG &=~0x80;
}
EA=1;
}
#pragma vector=T1_VECTOR
__interrupt void T1_ISR(void)
{
T1STAT &=~0x20;
if(key1_flag)
led1_flag = !led1_flag;
else led1_flag = 0;
if(key2_flag)
led2_flag = !led2_flag;
else led2_flag = 0;
}
标签:led1,led2,void,STATE,while,flag,实验,cc2530,代码 来源: https://blog.csdn.net/FuckerGod/article/details/115448072