圣龙扬特-AVR电子

 找回密码
 立即注册
搜索
热搜: 活动 交友 discuz
查看: 2595|回复: 2
打印 上一主题 下一主题

STM8S的电容触摸按键实验例程(板自带例程)

[复制链接]

26

主题

1

好友

3446

积分

超级版主

Rank: 8Rank: 8

UID
7
帖子
140
精华
0
注册时间
2013-2-26
在线时间
20 小时

突出贡献

跳转到指定楼层
楼主
发表于 2013-2-26 15:45:57 |只看该作者 |倒序浏览
本例程利用STM8S固件驱动库及STM8S RC触摸按键软件库为用户演示如何用触摸按键控制LED的功能。
说实话,这个例程笔者还没研究透。
/**
  ******************************************************************************
  * @file STM8_main.c
  * @brief RC Touch Sensing Library for STM8 CPU family.
  * Application example.
  * @author STMicroelectronics - MCD Application Team
  * @version V1.2.0
  * @date 24-MAR-2009
  ******************************************************************************
  *
  * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
  * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
  * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY
  * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
  * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
  * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
  *
  * <h2><center>&copy; COPYRIGHT 2009 STMicroelectronics</center></h2>
  * @image html logo.bmp
  ******************************************************************************
  */

#include "STM8_TSL_RC_API.h"

/* LD1 on STM8S EVALBOARD */
#define LED1_PIN_MASK  ((u8)0x08)
#define LED1_PORT_ODR  GPIOD->ODR
#define LED1_PORT_DDR  GPIOD->DDR
#define LED1_PORT_CR1  GPIOD->CR1

#define LED2_PIN_MASK  ((u8)0x04)
#define LED2_PORT_ODR  GPIOD->ODR
#define LED2_PORT_DDR  GPIOD->DDR
#define LED2_PORT_CR1  GPIOD->CR1

#define LED3_PIN_MASK  ((u8)0x01)
#define LED3_PORT_ODR  GPIOD->ODR
#define LED3_PORT_DDR  GPIOD->DDR
#define LED3_PORT_CR1  GPIOD->CR1

#define LED1_ON()  {LED1_PORT_ODR |= LED1_PIN_MASK; Led1State = ON;}
#define LED1_OFF() {LED1_PORT_ODR &= (u8)(~LED1_PIN_MASK); Led1State = OFF;}

#define LED2_ON()  {LED2_PORT_ODR |= LED2_PIN_MASK; Led2State = ON;}
#define LED2_OFF() {LED2_PORT_ODR &= (u8)(~LED2_PIN_MASK); Led2State = OFF;}

#define LED3_ON()  {LED3_PORT_ODR |= LED3_PIN_MASK; Led3State = ON;}
#define LED3_OFF() {LED3_PORT_ODR &= (u8)(~LED3_PIN_MASK); Led3State = OFF;}

typedef enum
{
  OFF = 0,
  ON = 1
} LedState_T;

LedState_T Led1State,Led2State,Led3State;


_Bool in_range;
_Bool p_valid;
char *ptr;

//--------    SECTION DEFINITION FOR THIS FILE   --------------
#if defined(__CSMC__) && defined(USE_PRAGMA_SECTION)
#pragma section [CONFIG_RAM]
#pragma section @tiny [CONFIG_RAM0]
#pragma section (CONFIG_CODE)
#pragma section const {CONFIG_CONST}
#endif

void ExtraCode_Init(void);
void ExtraCode_StateMachine(void);


/**
  ******************************************************************************
  * @brief Main function.
  * @par Parameters:
  * None
  * @retval void None
  * @par Required preconditions:
  * None
  ******************************************************************************
  */
void main(void)
{

/* Only if _stext routine is not used */
/*
#asm
                sim                // Disable interrupts               
        // To initialize the page 0
                clrw        x
loop0:
                clr        (x)
                incw        x
                cpw        x,#0x05FF
                jrne        loop0
#endasm
*/

  unsigned char value = 100;
  in_range = (value >= 10) && (value <= 20);
  p_valid = ptr;   /* p_valid is true if ptr not 0 */


        CLK->CKDIVR = 0x00; // Main freq divided by 1 = Full Freq

        TSL_Init();

  ExtraCode_Init();

  for (;;) {
   
                ExtraCode_StateMachine();
               
    TSL_Action();
   
        }
  
}


/**
  ******************************************************************************
  * @brief Initialize all the keys, I/Os for LED
  * @par Parameters:
  * None
  * @retval void None
  * @par Required preconditions:
  * None
  ******************************************************************************
  */
void ExtraCode_Init(void)
{

  u8 i;

  /* All keys are implemented and enabled */

  for (i = 0; i < NUMBER_OF_SINGLE_CHANNEL_KEYS; i++)
  {
    sSCKeyInfo[i].Setting.b.IMPLEMENTED = 1;
    sSCKeyInfo[i].Setting.b.ENABLED = 1;
    sSCKeyInfo[i].DESGroup = 0x01; /* Put 0x00 to disable the DES on these pins */
  }

#if NUMBER_OF_MULTI_CHANNEL_KEYS > 0
  for (i = 0; i < NUMBER_OF_MULTI_CHANNEL_KEYS; i++)
  {
    sMCKeyInfo[i].Setting.b.IMPLEMENTED = 1;
    sMCKeyInfo[i].Setting.b.ENABLED = 1;
    sMCKeyInfo[i].DESGroup = 0x01; /* Put 0x00 to disable the DES on these pins */
  }
#endif

  /* Init I/O in Output Push-Pull to drive the LED */
        LED1_PORT_ODR |= LED1_PIN_MASK; /* LED1 is ON by default */
  LED1_PORT_DDR |= LED1_PIN_MASK;
  LED1_PORT_CR1 |= LED1_PIN_MASK;
  
  Led1State = ON;
  
  LED2_PORT_ODR |= LED2_PIN_MASK; /* LED1 is ON by default */
  LED2_PORT_DDR |= LED2_PIN_MASK;
  LED2_PORT_CR1 |= LED2_PIN_MASK;
  Led2State = ON;
  
  LED3_PORT_ODR |= LED3_PIN_MASK; /* LED1 is ON by default */
  LED3_PORT_DDR |= LED3_PIN_MASK;
  LED3_PORT_CR1 |= LED3_PIN_MASK;
  Led3State = ON;
  
  enableInterrupts();

}


/**
  ******************************************************************************
  * @brief Example of LED switching using touch sensing keys
  * KEY1: LED1 ON
  * KEY2: LED1 OFF
  * KEY3: LED1 ON then OFF after 1s delay
  * KEY4: LED1 ON then OFF after 200ms delay
  * KEY5: LED1 ON/OFF
  * @par Parameters:
  * None
  * @retval void None
  * @par Required preconditions:
  * None
  ******************************************************************************
  */
void ExtraCode_StateMachine(void)        {

        if ((TSL_GlobalSetting.b.CHANGED) && (TSLState == TSL_IDLE_STATE))
  {
   
                TSL_GlobalSetting.b.CHANGED = 0;
   
    if (sSCKeyInfo[0].Setting.b.DETECTED) /* KEY 1 touched */
    {
      if (Led1State == OFF)
      {
        LED1_ON();
      }
      else
      {
        LED1_OFF();
      }
    }
   
    if (sSCKeyInfo[1].Setting.b.DETECTED) /* KEY 2 touched */
    {
      if (Led2State == OFF)
      {
        LED2_ON();
      }
      else
      {
        LED2_OFF();
      }
    }
   
    if (sSCKeyInfo[2].Setting.b.DETECTED) /* KEY 3 touched */
    {
      if (Led3State == OFF)
      {
        LED3_ON();
      }
      else
      {
        LED3_OFF();
      }
    }
  }
}

/****************** (c) 2009  STMicroelectronics ******************************/
回复

使用道具 举报

26

主题

1

好友

3446

积分

超级版主

Rank: 8Rank: 8

UID
7
帖子
140
精华
0
注册时间
2013-2-26
在线时间
20 小时

突出贡献

沙发
发表于 2013-2-26 15:48:43 |只看该作者
全部文件打包如下,请高手指点:

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?立即注册

回复

使用道具 举报

0

主题

1

好友

3101

积分

超级版主

Rank: 8Rank: 8

UID
31
帖子
36
精华
0
注册时间
2013-2-27
在线时间
5 小时
板凳
发表于 2013-2-28 14:17:02 |只看该作者
表四鄙人纯属随机路过。。。顺带帮顶。。。
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

Archiver|手机版|圣龙扬特-AVR电子 ( 鲁ICP备05022832号 )

GMT+8, 2024-12-22 10:50 , Processed in 0.205287 second(s), 20 queries .

Powered by Discuz! X2.5

© 2001-2012 Comsenz Inc.

回顶部