2020-09-21 08:39:00 +02:00
|
|
|
|
|
|
|
|
|
/********************************** (C) COPYRIGHT *******************************
|
|
|
|
|
* File Name : GPIO.C
|
|
|
|
|
* Author : WCH
|
|
|
|
|
* Version : V1.0
|
|
|
|
|
* Date : 2017/01/20
|
|
|
|
|
* Description : CH554 IO <EFBFBD><EFBFBD><EFBFBD>ýӿں<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>GPIO<EFBFBD>жϺ<EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
*******************************************************************************/
|
|
|
|
|
|
|
|
|
|
#include "CH554.H"
|
|
|
|
|
#include "common.h"
|
|
|
|
|
#include "GPIO.h"
|
|
|
|
|
#include "stdio.h"
|
|
|
|
|
#include "USB.h"
|
|
|
|
|
|
|
|
|
|
extern UINT8 Value_CH552[14];
|
|
|
|
|
UINT8 Power_y=0;
|
|
|
|
|
|
|
|
|
|
#pragma NOAREGS
|
|
|
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
|
* Function Name : Port1Cfg()
|
|
|
|
|
* Description : <EFBFBD>˿<EFBFBD>1<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
* Input : Mode 0 = <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>룬<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
1 = <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
2 = <EFBFBD><EFBFBD>©<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
3 = <EFBFBD><EFBFBD>51ģʽ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>©<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڲ<EFBFBD><EFBFBD><EFBFBD>·<EFBFBD><EFBFBD><EFBFBD>Լ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɵ͵<EFBFBD><EFBFBD>ߵĵ<EFBFBD>ƽ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
,UINT8 Pin (0-7)
|
|
|
|
|
* Output : None
|
|
|
|
|
* Return : None
|
|
|
|
|
*******************************************************************************/
|
|
|
|
|
void Port1Cfg(UINT8 Mode,UINT8 Pin)
|
|
|
|
|
{
|
|
|
|
|
switch(Mode){
|
|
|
|
|
case 0:
|
|
|
|
|
P1_MOD_OC = P1_MOD_OC & ~(1<<Pin);
|
|
|
|
|
P1_DIR_PU = P1_DIR_PU & ~(1<<Pin);
|
|
|
|
|
break;
|
|
|
|
|
case 1:
|
|
|
|
|
P1_MOD_OC = P1_MOD_OC & ~(1<<Pin);
|
|
|
|
|
P1_DIR_PU = P1_DIR_PU | (1<<Pin);
|
|
|
|
|
break;
|
|
|
|
|
case 2:
|
|
|
|
|
P1_MOD_OC = P1_MOD_OC | (1<<Pin);
|
|
|
|
|
P1_DIR_PU = P1_DIR_PU & ~(1<<Pin);
|
|
|
|
|
break;
|
|
|
|
|
case 3:
|
|
|
|
|
P1_MOD_OC = P1_MOD_OC | (1<<Pin);
|
|
|
|
|
P1_DIR_PU = P1_DIR_PU | (1<<Pin);
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
|
* Function Name : Port3Cfg()
|
|
|
|
|
* Description : <EFBFBD>˿<EFBFBD>3<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
* Input : Mode 0 = <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>룬<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
1 = <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
2 = <EFBFBD><EFBFBD>©<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
3 = <EFBFBD><EFBFBD>51ģʽ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>©<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڲ<EFBFBD><EFBFBD><EFBFBD>·<EFBFBD><EFBFBD><EFBFBD>Լ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɵ͵<EFBFBD><EFBFBD>ߵĵ<EFBFBD>ƽ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
,UINT8 Pin (0-7)
|
|
|
|
|
* Output : None
|
|
|
|
|
* Return : None
|
|
|
|
|
*******************************************************************************/
|
|
|
|
|
void Port3Cfg(UINT8 Mode,UINT8 Pin)
|
|
|
|
|
{
|
|
|
|
|
switch(Mode){
|
|
|
|
|
case 0:
|
|
|
|
|
P3_MOD_OC = P3_MOD_OC & ~(1<<Pin);
|
|
|
|
|
P3_DIR_PU = P3_DIR_PU & ~(1<<Pin);
|
|
|
|
|
break;
|
|
|
|
|
case 1:
|
|
|
|
|
P3_MOD_OC = P3_MOD_OC & ~(1<<Pin);
|
|
|
|
|
P3_DIR_PU = P3_DIR_PU | (1<<Pin);
|
|
|
|
|
break;
|
|
|
|
|
case 2:
|
|
|
|
|
P3_MOD_OC = P3_MOD_OC | (1<<Pin);
|
|
|
|
|
P3_DIR_PU = P3_DIR_PU & ~(1<<Pin);
|
|
|
|
|
break;
|
|
|
|
|
case 3:
|
|
|
|
|
P3_MOD_OC = P3_MOD_OC | (1<<Pin);
|
|
|
|
|
P3_DIR_PU = P3_DIR_PU | (1<<Pin);
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
|
* Function Name : GPIOInterruptCfg()
|
|
|
|
|
* Description : GPIO<EFBFBD>ж<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
* Input : None
|
|
|
|
|
* Output : None
|
|
|
|
|
* Return : None
|
|
|
|
|
*******************************************************************************/
|
|
|
|
|
void GPIOInterruptCfg()
|
|
|
|
|
{
|
|
|
|
|
GPIO_IE &= ~bIE_IO_EDGE; //<2F><>/<2F>͵<EFBFBD>ƽ<EFBFBD><C6BD><EFBFBD><EFBFBD> <20>͵<EFBFBD>ƽΪ<C6BD><CEAA>Ч<EFBFBD><D0A7>ƽ
|
|
|
|
|
// GPIO_IE |= bIE_IO_EDGE; //<2F><><EFBFBD><EFBFBD>/<2F>½<EFBFBD><C2BD><EFBFBD><EFBFBD><EFBFBD> <20>½<EFBFBD><C2BD>ش<EFBFBD><D8B4><EFBFBD>
|
|
|
|
|
//GPIO_IE |= bIE_RXD1_LO; //RXD1<44>͵<EFBFBD>ƽ<EFBFBD><C6BD><EFBFBD>½<EFBFBD><C2BD>ش<EFBFBD><D8B4><EFBFBD> <20><><EFBFBD><EFBFBD>1<EFBFBD><31><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD>ʹ<EFBFBD><CAB9>
|
|
|
|
|
GPIO_IE |= bIE_P1_5_LO | bIE_P1_4_LO | bIE_P1_3_LO | bIE_RST_HI;
|
|
|
|
|
//P15\P14\P13<31>͵<EFBFBD>ƽ<EFBFBD><C6BD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>RST<53>ߵ<EFBFBD>ƽ<EFBFBD><C6BD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>ش<EFBFBD><D8B4><EFBFBD>
|
|
|
|
|
//GPIO_IE |= bIE_P3_1_LO; //P31<33>͵<EFBFBD>ƽ<EFBFBD><C6BD><EFBFBD>½<EFBFBD><C2BD>ش<EFBFBD><D8B4><EFBFBD>
|
|
|
|
|
//GPIO_IE |= bIE_RXD0_LO; //RXD0<44>͵<EFBFBD>ƽ<EFBFBD><C6BD><EFBFBD>½<EFBFBD><C2BD>ش<EFBFBD><D8B4><EFBFBD> <09><><EFBFBD><EFBFBD>2<EFBFBD><32><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD>ʹ<EFBFBD><CAB9>
|
|
|
|
|
IE_GPIO = 1; //GPIO<49>жϿ<D0B6><CFBF><EFBFBD> <20><>չ<EFBFBD>ж<EFBFBD>ʹ<EFBFBD><CAB9>
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef GPIO_INTERRUPT
|
|
|
|
|
/*******************************************************************************
|
|
|
|
|
* Function Name : GPIOInterrupt(void)
|
|
|
|
|
* Description : GPIO <EFBFBD>жϷ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
*******************************************************************************/
|
|
|
|
|
void GPIOInterrupt( void ) interrupt INT_NO_GPIO using 1 //GPIO<49>жϷ<D0B6><CFB7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>,ʹ<>üĴ<C3BC><C4B4><EFBFBD><EFBFBD><EFBFBD>1
|
|
|
|
|
{
|
|
|
|
|
//#ifdef DE_PRINTF
|
|
|
|
|
// printf("GPIO_STATUS: %02x\n",(UINT16)(PIN_FUNC&bIO_INT_ACT));
|
|
|
|
|
//#endif
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
|
* Function Name : TheKeyQuery()
|
|
|
|
|
* Description : <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѯ
|
|
|
|
|
* like-20180605
|
|
|
|
|
*******************************************************************************/
|
|
|
|
|
void TheKeyQuery()
|
|
|
|
|
{
|
|
|
|
|
if(KEY0==0)
|
|
|
|
|
{
|
|
|
|
|
delayus(100);
|
|
|
|
|
if(KEY0==0)
|
|
|
|
|
{
|
|
|
|
|
TXflag=SENDK;
|
|
|
|
|
TXflagHandle(KEY_0);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if(KEY1==0)
|
|
|
|
|
{
|
|
|
|
|
delayus(100);
|
|
|
|
|
if(KEY1==0)
|
|
|
|
|
{
|
|
|
|
|
TXflag=SENDK;
|
|
|
|
|
TXflagHandle(KEY_1);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if(KEY2==0)
|
|
|
|
|
{
|
|
|
|
|
delayus(100);
|
|
|
|
|
if(KEY2==0)
|
|
|
|
|
{
|
|
|
|
|
TXflag=SENDK;
|
|
|
|
|
TXflagHandle(KEY_2);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if(KEY3==0)
|
|
|
|
|
{
|
|
|
|
|
delayus(100);
|
|
|
|
|
if(KEY3==0)
|
|
|
|
|
{
|
|
|
|
|
TXflag=SENDK;
|
|
|
|
|
TXflagHandle(KEY_3);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
/*******************************************************************************
|
|
|
|
|
* Function Name : TheKeyQuery()
|
|
|
|
|
* Description : <EFBFBD><EFBFBD>Դ<EFBFBD><EFBFBD>ѯ
|
|
|
|
|
* like-20180605
|
|
|
|
|
*******************************************************************************/
|
|
|
|
|
void PowerSupplyQuery()
|
|
|
|
|
{
|
|
|
|
|
if(Power==0&&Power_y==1)
|
|
|
|
|
{
|
|
|
|
|
TXflag=SENDK;
|
|
|
|
|
TXflagHandle(PowerOFF);
|
|
|
|
|
Power_y = 0;
|
|
|
|
|
}
|
|
|
|
|
else if(Power==1&&Power_y==0)
|
|
|
|
|
{
|
|
|
|
|
TXflag=SENDK;
|
|
|
|
|
TXflagHandle(PowerON);
|
|
|
|
|
Power_y = 1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|