CH552/projects/examples/GPIO/GPIO.C

119 lines
4.1 KiB
C++
Raw Normal View History

2018-10-17 05:37:36 +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>
*******************************************************************************/
2018-10-17 10:44:45 +02:00
#include "..\Public\CH554.H"
#include "..\Public\Debug.H"
#include "GPIO.H"
2018-10-17 05:37:36 +02:00
#include "stdio.h"
#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()
{
2018-10-17 10:44:45 +02:00
GPIO_IE &= ~bIE_IO_EDGE; //<2F><>/<2F>͵<EFBFBD>ƽ<EFBFBD><C6BD><EFBFBD><EFBFBD>
// GPIO_IE |= bIE_IO_EDGE; //<2F><><EFBFBD><EFBFBD>/<2F>½<EFBFBD><C2BD><EFBFBD><EFBFBD><EFBFBD>
// GPIO_IE |= bIE_RXD1_LO; //RXD1<44>͵<EFBFBD>ƽ<EFBFBD><C6BD><EFBFBD>½<EFBFBD><C2BD>ش<EFBFBD><D8B4><EFBFBD>
2018-10-17 05:37:36 +02:00
GPIO_IE |= bIE_P1_5_LO | bIE_P1_4_LO | bIE_P1_3_LO | bIE_RST_HI;
2018-10-17 10:44:45 +02:00
//P15\P14\P13<31>͵<EFBFBD>ƽ<EFBFBD><C6BD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>RST<53>ߵ<EFBFBD>ƽ<EFBFBD><C6BD><EFBFBD><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>
IE_GPIO = 1; //GPIO<49>жϿ<D0B6><CFBF><EFBFBD>
2018-10-17 05:37:36 +02:00
}
#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
{
2018-10-17 10:44:45 +02:00
#ifdef DE_PRINTF
printf("GPIO_STATUS: %02x\n",(UINT16)(PIN_FUNC&bIO_INT_ACT));
2018-10-17 05:37:36 +02:00
#endif
}
2018-10-17 10:44:45 +02:00
#endif
2018-10-17 05:37:36 +02:00