基本信息
源码名称:基于瑞萨单片机的触摸按键驱动
源码大小:0.12M
文件格式:.rar
开发语言:C#
更新时间:2016-03-29
友情提示:(无需注册或充值,赞助后即可获取资源下载链接)
嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):78630559
本次赞助数额为: 3 元×
微信扫码支付:3 元
×
请留下您的邮箱,我们将在2小时内将文件发到您的邮箱
源码介绍
基于瑞萨单片机的触摸按键驱动
基于瑞萨单片机的触摸按键驱动
基于瑞萨单片机的触摸按键驱动
基于瑞萨单片机的触摸按键驱动
/***********************************************************************************************************************
* DISCLAIMER
* This software is supplied by Renesas Electronics Corporation and is only intended for use with Renesas products.
* No other uses are authorized. This software is owned by Renesas Electronics Corporation and is protected under all
* applicable laws, including copyright laws.
* THIS SOFTWARE IS PROVIDED "AS IS" AND RENESAS MAKES NO WARRANTIESREGARDING THIS SOFTWARE, WHETHER EXPRESS, IMPLIED
* OR STATUTORY, INCLUDING BUT NOT LIMITED TO WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NON-INFRINGEMENT. ALL SUCH WARRANTIES ARE EXPRESSLY DISCLAIMED.TO THE MAXIMUM EXTENT PERMITTED NOT PROHIBITED BY
* LAW, NEITHER RENESAS ELECTRONICS CORPORATION NOR ANY OF ITS AFFILIATED COMPANIES SHALL BE LIABLE FOR ANY DIRECT,
* INDIRECT, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES FOR ANY REASON RELATED TO THIS SOFTWARE, EVEN IF RENESAS OR
* ITS AFFILIATES HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
* Renesas reserves the right, without notice, to make changes to this software and to discontinue the availability
* of this software. By using this software, you agree to the additional terms and conditions found by accessing the
* following link:
* http://www.renesas.com/disclaimer
*
* Copyright (C) 2011, 2015 Renesas Electronics Corporation. All rights reserved.
***********************************************************************************************************************/
/***********************************************************************************************************************
* File Name : r_main.c
* Version : CodeGenerator for RL78/G13 V2.03.01.03 [30 Jan 2015]
* Device(s) : R5F101FC
* Tool-Chain : CCRL
* Description : This file implements main function.
* Creation Date: 2016/2/18
***********************************************************************************************************************/
/***********************************************************************************************************************
Includes
***********************************************************************************************************************/
#include "r_cg_macrodriver.h"
#include "r_cg_cgc.h"
#include "r_cg_port.h"
#include "r_cg_timer.h"
#include "r_cg_wdt.h"
/* Start user code for include. Do not edit comment generated here */
/* End user code. Do not edit comment generated here */
#include "r_cg_userdefine.h"
/***********************************************************************************************************************
Pragma directive
***********************************************************************************************************************/
/* Start user code for pragma. Do not edit comment generated here */
u8 KEY_VALUE = 0;
u8 keyvalue_test = 0;
extern u8 guc_KeyCheckTimer;
void R_MAIN_UserInit(void);
/* End user code. Do not edit comment generated here */
/***********************************************************************************************************************
Global variables and functions
***********************************************************************************************************************/
/* Start user code for global. Do not edit comment generated here */
#define AIR_R_PORT P7_bit.no0
#define AIR_G_PORT P7_bit.no1
#define AIR_B_PORT P7_bit.no2
/***********************************************************************************************************************
* Function Name: void KeyLed(u8 keytype,u8 time)
* Description :
* Arguments : None
* Return Value : None
***********************************************************************************************************************/
void delay2(u16 i)
{
u16 j = 0;
for(;i>0;i--)
{
NOP();
NOP();
NOP();
}
}
void delay(u16 i)
{
for(;i>0;i--)
{
NOP();
NOP();
NOP();
NOP();
NOP();
NOP();
NOP();
NOP();
NOP();
NOP();
NOP();
NOP();
NOP();
NOP();
NOP();
NOP();
NOP();
NOP();
NOP();
NOP();
NOP();
NOP();
NOP();
NOP();
NOP();
NOP();
NOP();
NOP();
NOP();
NOP();
NOP();
NOP();
NOP();
NOP();
NOP();
NOP();
}
}
u8 keyvalue = 0xff;
/***********************************************************************************************************************
* Function Name: void Key_Init()
* Description :
* Arguments :
* Return Value : None
***********************************************************************************************************************/
u8 GetKeyData(void)
{
//
u8 i = 0;
PM6_bit.no3 = 1;
delay2(500);
//KEY_CLK_PORT = 1;
//KEY_SDA_PORT = 1;//MCU引脚为输入
KEY_CLK_PORT = 0;//CLK引脚始终为输出
delay2(100);
//KEY_CLK_PORT = 1;//CLK引脚始终为输出
if(KEY_SDA_PORT == 1)
{
KEY_CLK_PORT = 1;
return 0xff;
}
KEY_CLK_PORT = 1;
delay2(500);
do
{
keyvalue >>= 1;
KEY_CLK_PORT = 0;
delay2(500);
if(KEY_SDA_PORT == 1)
{
keyvalue |= 0x80;
}
//
if(KEY_SDA_PORT == 0)
{
keyvalue &= 0x7f;
}
KEY_CLK_PORT = 1;
delay2(500);
i ;
}
while(i<8);
KEY_CLK_PORT = 0;
delay2(500);
KEY_CLK_PORT = 1;
delay2(500);
if(keyvalue == 0xff)
{
return 0;
}
return(keyvalue);
}
/***********************************************************************************************************************
* Function Name: void Key_Init()
* Description :
* Arguments :
* Return Value : None
***********************************************************************************************************************/
void SetSubtleSP(u8 subtle)
{
u8 i = 0;
//PM6_bit.no3 = 0;
//PM6_bit.no2=0;//??
KEY_SDA_PORT = 0;
KEY_CLK_PORT = 0;
delay2(500);
KEY_CLK_PORT = 1;
delay2(500);
do
{
if((subtle & 0x01) == 0)
{
KEY_SDA_PORT = 0;
}
else
{
KEY_SDA_PORT = 1;
}
KEY_CLK_PORT = 0;
delay2(500);
KEY_CLK_PORT = 1;
delay2(500);
subtle >>= 1;
i ;
}
while(i<8);
//KEY_SDA_PORT = 1;
//KEY_CLK_PORT = 0;
PM6_bit.no3 = 1;
delay2(500);
KEY_CLK_PORT = 0;
//delay2(1);
//PM6_bit.no3 = 1;
//while(KEY_SDA_PORT==0);
}
u16 keytime = 0;
u8 keyvalue_old = 0;
u8 invalidkeyflag = 0;
/***********************************************************************************************************************
* Function Name: void Key_Handle(u8 keyduration,u8 keytype)
* Description : ????,????????????
* Arguments : u8 keyduration????,u8 keytype????
* Return Value : None
***********************************************************************************************************************/
u8 TurntoSingleKeyCheck(u8 keyvalue)
{
static u8 validshortkey = 0;/*??????*/
// static u16 keytime = 0;
// static u8 keyvalue_old = 0;
u8 keyduration = 0;
static num = 0;
// static u8 invalidkeyflag = 0;//????,??????,?1????????????
static u8 validkeyflag = 0;//??????,????LED
/*==============================================================*/
/*???????,????3???*/
if(invalidkeyflag == 0)
{
if(keyvalue == 0)
{
if(num >= 5)
{
invalidkeyflag = 1;
num = 0;
return 0;
}
num ;
}
else
{
num = 0;
return 0;
}
}
/*======================================*/
/*???10ms????????,??????*/
if((keytime == 0)&&(keyvalue != 0))
{
keyvalue_old = keyvalue;
keytime ;
}
/*????10ms*/
else if(keytime != 0)
{
/*??????????????*/
if(keyvalue_old == keyvalue)
{
if((keytime >= 3)&&(validkeyflag == 0))
{
validkeyflag = 1;
//KeyLedCheck(keyvalue_old);
}
if(keytime >= 300)
{
keyduration = 2;
validshortkey = 0;
}
keytime ;
}
/*?????????????????????*/
else if(keyvalue_old != keyvalue)
{
if(keytime < 3)
{
keyduration = 0;
keyvalue_old = 0;
keytime = 0;
validshortkey = 0;
validkeyflag = 0;
invalidkeyflag = 0;
return 0;
}
else if(keytime < 300)
{
keyduration = 1;
validshortkey = 1;
}
else if(keytime < 600)
{
validshortkey = 0;
keyduration = 2;
}
}
}
/*======================================*/
/*????????????*/
if(keyduration)//????
{
keyvalue_old = 0;
keytime = 0;
validkeyflag = 0;
invalidkeyflag = 0;
return validshortkey;
}
}
u8 KeyCheck(void)
{
u8 keyflag = 0;
u8 keyvalue = 0;
/*?15ms???????*/
if(guc_KeyCheckTimer >= 10)
{
guc_KeyCheckTimer = 0;
keyvalue = GetKeyData();
if(keyvalue == 0x01)
{
AIR_R_PORT = 0;
AIR_G_PORT = ~AIR_G_PORT;
AIR_B_PORT = 0;
}
/*zhi pan duan shi fou you dan jian an xia,you ze biao zhi wei zhi 1,
yong lai zhong duan zheng zai zhi xing de while*/
if(keyvalue == 0x03)
{
;//TurntoGroupKeyCheck(keyvalue);
}
else
{
keyflag = TurntoSingleKeyCheck(keyvalue);
}
}
/*zai you while deng dai de han shu zhong diao yong gai han shu ,
fan hui zhi yong yu pan duan shi fou xu yao ti qian zhong duan while,
ru HumiCheck() he BuzzerTone()*/
return keyflag;
}
/* End user code. Do not edit comment generated here */
void R_MAIN_UserInit(void);
/***********************************************************************************************************************
* Function Name: main
* Description : This function implements main function.
* Arguments : None
* Return Value : None
***********************************************************************************************************************/
void main(void)
{
R_MAIN_UserInit();
/* Start user code. Do not edit comment generated here */
R_TAU0_Channel0_Start();
guc_KeyCheckTimer = 0;
while(guc_KeyCheckTimer <= 100)
{
NOP();
}
SetSubtleSP(28);
guc_KeyCheckTimer = 0;
while(guc_KeyCheckTimer <= 50)
{
NOP();
}
while (1)
{
R_WDT_Restart() ;
(void)KeyCheck();
/*
if(guc_KeyCheckTimer >= 15)
{
guc_KeyCheckTimer = 0;
KEY_VALUE = GetKeyData();
if(KEY_VALUE == 0x80)
{
AIR_R_PORT = 0;
AIR_G_PORT = 0;
AIR_B_PORT = 1;
}
if(KEY_VALUE == 0x81)
{
AIR_R_PORT = 1;
AIR_G_PORT = 0;
AIR_B_PORT = 0;
}
R_WDT_Restart() ;
}
*/
}
/* End user code. Do not edit comment generated here */
}
/***********************************************************************************************************************
* Function Name: R_MAIN_UserInit
* Description : This function adds user code before implementing main function.
* Arguments : None
* Return Value : None
***********************************************************************************************************************/
void R_MAIN_UserInit(void)
{
/* Start user code. Do not edit comment generated here */
EI();
/* End user code. Do not edit comment generated here */
}
/* Start user code for adding. Do not edit comment generated here */
/* End user code. Do not edit comment generated here */