📄 main.c
字号:
/*
* Copyright (c) 2007 EISLAB - Lulea University of Technology.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
* SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
* OF SUCH DAMAGE.
*
* The purpose of this program is to toggle LED via external interrupt
*
*/
#include "sema.h"
#include "hardware.h"
#include "inthandler.h"
typedef unsigned char uint8;
typedef unsigned short uint16;
typedef unsigned int uint32;
sema_t semaphores[3] = {0};
int main (void)
{
uint8 toggle_led = 0;
#if MULLE_BOARD == MULLEv1
PD8.BIT.PD8_0 = OUTPUT; /* setting port P80 as OUTPUT port*/
P8.BIT.P8_0 = LOW; /* set LED on port P80 ON initially*/
sema_unset(INT1_SEM); /* unset semaphore initially */
PUR2.BIT.PU20 = 1;
INT1IC.BYTE = 0x03; /* enable interrupt1, level 3, rising edge */
#elif MULLE_BOARD == MULLEv3
PD8.BIT.PD8_0 = OUTPUT; /* setting port P80 as OUTPUT port*/
P8.BIT.P8_0 = HIGH; /* set LED on port P80 ON initially*/
sema_unset(INT4_SEM); /* unset semaphore initially */
PD1.BIT.PD1_6 = INPUT;
INT4IC.BYTE = 0x03; /* enable interrupt4, level 3, rising edge */
#endif
asm("fset i"); /* enable interrupts if any */
/* main loop */
for (;;) {
/* check if semaphore status is set*/
#if MULLE_BOARD == MULLEv1
if(sema_status(INT1_SEM) == SEMA_SET) {
sema_unset(INT1_SEM);
#elif MULLE_BOARD == MULLEv3
if(sema_status(INT4_SEM) == SEMA_SET) {
sema_unset(INT4_SEM);
#endif
if(toggle_led == 0) {
P8.BIT.P8_0 = LOW; /* set LED on port P80 on */
toggle_led = 1;
} else {
P8.BIT.P8_0 = HIGH; /* set LED on port P80 off */
toggle_led = 0;
}//end else
}//end if
}//end main loop
}//end main
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -