📄 led.c
字号:
/*=============================================================================
Cyan Technology Limited
FILE - LED.c
Example eCOG1 application.
DESCRIPTION
Uses a general purpose timer to control the flashing of LEDs connected
to GPIO pins.
MODIFICATION DETAILS
=============================================================================*/
/******************************************************************************
Project level include files.
******************************************************************************/
#include <ecog1.h>
#include <stdio.h>
#include "driver_lib.h"
/******************************************************************************
Include files for public interfaces from other modules.
******************************************************************************/
/******************************************************************************
Declaration of public functions.
******************************************************************************/
/******************************************************************************
Private constants and types.
******************************************************************************/
#define LED0 0
#define LED1 1
#define LED2 2
#define LED3 3
/******************************************************************************
Declaration of static functions.
******************************************************************************/
static void pattern(void);
/******************************************************************************
Global variables.
******************************************************************************/
/******************************************************************************
Module global variables.
******************************************************************************/
static unsigned int do_pattern;
/******************************************************************************
Definition of API functions.
******************************************************************************/
/******************************************************************************
NAME
main
SYNOPSIS
int main(int argc, char * argv[])
FUNCTION
Sit in a loop and call function pattern when the interrupt signals.
RETURNS
Exit code.
******************************************************************************/
int main(int argc, char * argv[])
{
lcd_rst();
lcd_puts("Example: led");
printf("\r\n\nExample: led\r\n");
// Start tick timer and enable interrupt
rg.tim.ctrl_en = TIM_CTRL_EN_CNT1_CNT_MASK;
rg.tim.int_en1 = TIM_INT_EN1_CNT1_EXP_MASK;
while (1)
{
if (1 == do_pattern)
{
pattern();
do_pattern = 0;
}
}
return (0);
}
/******************************************************************************
NAME
tick_handler
SYNOPSIS
void __irq_entry tick_handler(void)
FUNCTION
Interrupt handler that signals to user mode code via the do_leds variable.
RETURNS
Nothing.
******************************************************************************/
void __irq_entry tick_handler(void)
{
fd.tim.int_clr1.cnt1_exp = 1;
do_pattern = 1;
}
/******************************************************************************
NAME
pattern
SYNOPSIS
static void pattern(void)
FUNCTION
Put the next pattern on the LEDs and the LCD.
RETURNS
Nothing.
******************************************************************************/
static void pattern(void)
{
static unsigned int count;
count = (count+1) % 16;
putchar('\r');
putchar(' ');
lcd_xy(5, 2);
if (count & 8)
{
gpio_wr(LED3, 0);
lcd_putc('O');
putchar('O');
}
else
{
gpio_wr(LED3, 1);
lcd_putc('X');
putchar('X');
}
putchar(' ');
lcd_xy(7, 2);
if (count & 4)
{
gpio_wr(LED2, 0);
lcd_putc('O');
putchar('O');
}
else
{
gpio_wr(LED2, 1);
lcd_putc('X');
putchar('X');
}
putchar(' ');
lcd_xy(9, 2);
if (count & 2)
{
gpio_wr(LED1, 0);
lcd_putc('O');
putchar('O');
}
else
{
gpio_wr(LED1, 1);
lcd_putc('X');
putchar('X');
}
putchar(' ');
lcd_xy(11, 2);
if (count & 1)
{
gpio_wr(LED0, 0);
lcd_putc('O');
putchar('O');
}
else
{
gpio_wr(LED0, 1);
lcd_putc('X');
putchar('X');
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -