www.pudn.com > buttonTest.rar > main.c, change:2012-11-06,size:2089b


/* Copyright (C) Cambridge Silicon Radio Limited 2008-2012 */ 
/* Part of BlueLab 6.2.0.64 */ 
/* 
 * Blinking Lights - Part 1 
 */ 
 
#include <stdio.h> 
#include <message.h> 
#include <pio.h>		/* Peripheral Input/Output */ 
 
#define BUTTON1 	 (1<<0)    	/* bit 0 */ 
#define LED1     (1<<1) 		/* bit 1 */ 
 
#define DELAY1   1000 		/* ms */ 
#define DELAY2   500 		/* ms */ 
 
#define OUTPUT  0xFF    /* 1 corresponds to output */ 
#define INPUT   0       /* 0 corresponds to input */ 
#define HIGH    0xFF    /* 1 corresponds to high  */ 
#define LOW     0       /* 0 corresponds to low */ 
 
static void button_controller1( Task , MessageId , Message ); 
static void led_controller1( Task , MessageId , Message ); 
 
static TaskData button_controller1_task = { button_controller1 }; 
static TaskData led_controller1_task = { led_controller1 }; 
 
static void button_controller1( Task t, MessageId id, Message payload ) 
{ 
	PioSetDir32(BUTTON1, INPUT);         /* uint32 PioSetDir32( uint32 mask, uint32 dir ) */ 
 
	printf("*****debuy button_controller1-just*****\n"); 
	printf("pioget32  -----%lx\n", PioGet32()); 
	if(PioGet32() & BUTTON1) 
	{ 
		/* high-> wakeup: do nothing */ 
	} 
	else 
	{ 
		/* low-> sleep: wakeup the MCU */ 
		MessageSend( &led_controller1_task, 0, 0); 
	} 
 
	MessageSendLater( t, 0, 0, DELAY1 ); 
} 
 
static void led_controller1( Task t, MessageId id, Message payload ) 
{ 
 	PioSetDir32(LED1, OUTPUT);         /* uint32 PioSetDir32( uint32 mask, uint32 dir ) */ 
 
	printf("*****debuy led_controller1-just*****\n"); 
	PioSet32( LED1, (PioGet32() ^ LED1) ); 
	/* MessageSendLater( t, 0, 0, DELAY2 ); */  
} 
 
static void init(void) 
{ 
	PioSetDir32(BUTTON1, INPUT);         /* uint32 PioSetDir32( uint32 mask, uint32 dir ) */ 
 
	PioSetDir32(LED1, OUTPUT);         /* uint32 PioSetDir32( uint32 mask, uint32 dir ) */ 
	PioSet32(LED1, LOW);               /* Set LED1 off (0) */ 
} 
 
int main(void) 
{ 
	init(); 
	 
	MessageSend( &button_controller1_task, 0 , 0 ); 
	/* MessageSend( &led_controller2_task, 0 , 0 ); */ 
	MessageLoop(); 
	 
	return 0; 
}