📄 pio.c
字号:
{
case APD_PIOA: *muxdata1 = *(volatile unsigned long *)(mux1_reg);
*muxdata2 = *(volatile unsigned long *)(mux2_reg);
break;
case APD_PIOB: *muxdata1 = *(volatile unsigned long *)(mux1_reg);
*muxdata2 = *(volatile unsigned long *)(mux2_reg);
break;
case APD_PIOC: *muxdata1 = *(volatile APD_USHORT *)(mux1_reg);
*muxdata2 = *(volatile APD_USHORT *)(mux2_reg);
break;
case APD_PIOD: *muxdata1 = *(volatile APD_USHORT *)(mux1_reg);
break;
default: break;
}
}
/******************************************************************************
@@ [Name] : apd_PIOSetAsInput
@@ [Summary] : This function set the specified pins as input for the PIO port
@@ [Argument] : port: specify the PIO port number
@@ APD_PIOA for portA
@@ APD_PIOB for portB
@@ APD_PIOC for portC
@@ APD_PIOD for portD
@@ portvalue: specify which pins in the port is to be set as input
@@ Valid range is 0 to 0xFFFFFFFF
@@ [Return] : None
@@ [Desc] : Set the specified pins as input.
@@ [Note] : (1) For LH79531: APD_PIOF is not valid because it cannot be used as a PIO function.
@@ (2) For LH79532 and LH79533: APD_PIOE and APD_PIOF are not used.
@@ [History] :
@@ [END]
******************************************************************************/
void apd_PIOSetAsInput(APD_PIO_PORT port, unsigned long port_value)
{
unsigned long control_reg;
control_reg = APD_PIOBASE + (port * APD_PIOCH_OFST) + APD_PIOCTRL_OFST;
*(volatile unsigned long *)control_reg &= ~port_value;
}
/******************************************************************************
@@ [Name] : apd_PIOSetAsOutput
@@ [Summary] : This function set the specified pins as output for the PIO port
@@ [Argument] : port: specify the PIO port number
@@ APD_PIOA for portA
@@ APD_PIOB for portB
@@ APD_PIOC for portC
@@ APD_PIOD for portD
@@ portvalue: specify which pins in the port is to be set as output
@@ Valid range is 0 to 0xFFFFFFFF
@@ [Return] : None
@@ [Desc] : Set the specified pins as output.
@@ [Note] : (1) For LH79531: APD_PIOF is not valid because it cannot be used as a PIO function.
@@ (2) For LH79532 and LH79533: APD_PIOE and APD_PIOF are not used.
@@ [History] :
@@ [END]
******************************************************************************/
void apd_PIOSetAsOutput(APD_PIO_PORT port, unsigned long port_value)
{
unsigned long control_reg;
control_reg = APD_PIOBASE + (port * APD_PIOCH_OFST) + APD_PIOCTRL_OFST;
*(volatile unsigned long *)control_reg |= port_value;
}
/******************************************************************************
@@ [Name] : apd_PIOSetPortData
@@ [Summary] : This function writes the port value into the specified PIO port
@@ [Argument] : port: specify the PIO port number
@@ APD_PIOA for portA
@@ APD_PIOB for portB
@@ APD_PIOC for portC
@@ APD_PIOD for portD
@@ portvalue: specify the value to be written in the port
@@ Valid range is 0 to 0xFFFFFFFF
@@ [Return] : None
@@ [Desc] : Writes the port value into the specified port
@@ [Note] : (1) For LH79531: APD_PIOF is not valid because it cannot be used as a PIO function.
@@ (2) For LH79532 and LH79533: APD_PIOE and APD_PIOF are not used.
@@ [History] :
******************************************************************************/
void apd_PIOSetPortData(APD_PIO_PORT port, unsigned long port_value)
{
unsigned long data_reg;
data_reg = APD_PIOBASE + (port * APD_PIOCH_OFST) + APD_PIODATA_OFST;
*(volatile unsigned long *)data_reg = port_value;
}
/******************************************************************************
@@ [Name] : apd_PIOSetBit
@@ [Summary] : This function sets a bit of the specified port to 1
@@ [Argument] : port: specify the PIO port number
@@ APD_PIOA for portA
@@ APD_PIOB for portB
@@ APD_PIOC for portC
@@ APD_PIOD for portD
@@ APD_PIOE for portE (For LH79531 only)
@@ bit_num: specify which bit to set to 1
@@ Valid range is 0 to 31
@@ [Return] : None
@@ [Desc] : Set a sinlge bit to 1 for the specific PIO port.
@@ [Note] : (1) For LH79531: APD_PIOF is not valid because it cannot be used as a PIO function.
@@ (2) For LH79532 and LH79533: APD_PIOE and APD_PIOF are not used.
@@
@@ [History] : 10/11/2000 Tan WK Version 1.0
******************************************************************************/
void apd_PIOSetBit(APD_PIO_PORT port, unsigned char bit_num)
{
unsigned long dataset_reg;
dataset_reg = APD_PIOBASE + (port* APD_PIOCH_OFST) + APD_PIODATASET_OFST;
*(volatile unsigned long *)dataset_reg = APD_PIO_BITSHIFT << bit_num;
}
/******************************************************************************
@@ [Name] : apd_PIOClrBit
@@ [Summary] : This function clears a bit of the specified port to 0
@@ [Argument] : port: specify the PIO port number
@@ APD_PIOA for portA
@@ APD_PIOB for portB
@@ APD_PIOC for portC
@@ APD_PIOD for portD
@@ APD_PIOE for portE (For LH79531 only)
@@ bit_num: specify which bit to clear to 0
@@ Valid range is 0 to 31
@@ [Return] : None
@@ [Desc] : Clear a sinlge bit to 0 for the specific PIO port.
@@ [Note] : (1) For LH79531: APD_PIOF is not valid because it cannot be used as a PIO function.
@@ (2) For LH79532 and LH79533: APD_PIOE and APD_PIOF are not used.
@@ [History] : 10/11/2000 Tan WK Version 1.0
@@ 18/01/2001 Tan WK Version 1.1 Remove OR function, write
@@ bitnum into PIODataSet directly
@@ 19/02/2001 Tan WK Version 1.2 Calculate address.
@@ 01/06/2001 Tan WK Version 2.0 No change
@@ 29/08/2001 Teo LL Version 3.0 No change for LH79533
@@ [END]
******************************************************************************/
void apd_PIOClrBit(APD_PIO_PORT port, unsigned char bit_num)
{
unsigned long datareset_reg;
datareset_reg = APD_PIOBASE + (port * APD_PIOCH_OFST) + APD_PIODATARESET_OFST;
*(volatile unsigned long *)datareset_reg = APD_PIO_BITSHIFT << bit_num;
}
/*****************************************************************************
project Jn-00 PIO initial
set PIOA,PIOB,PIOC,PIOD as output/input or function1,2,3
*****************************************************************************/
void apd_PIOInit(void)
{
unsigned long mux_data2;
unsigned long mux_data1;
mux_data1=0x0007fff; //PIOA 0~14 as LCD driver.(CASIO)
mux_data2=0x1fb8000; //Reg: PIOA 19~24 as function3(CASIO)
/* setup PIOA */
apd_PIOSetMuxFunc(APD_PIOA,mux_data1,mux_data2);
/* set PIOA output & input */
apd_PIOSetAsOutput(APD_PIOA,0x1147ff4);
apd_PIOSetAsInput(APD_PIOA,0x0eb800b);
/* setup PIOB */
apd_PIOSetMuxFunc(APD_PIOB,0x40070,0x6000);
/* set PIOB output &input */
apd_PIOSetAsOutput(APD_PIOB,0xadff08);
apd_PIOSetAsInput(APD_PIOB,0x5200f7);
/* setup PIOC */
apd_PIOSetMuxFunc(APD_PIOC,0x04,0x00);
/* set PIOC output & input */
apd_PIOSetAsOutput(APD_PIOC,0x3447);
apd_PIOSetAsInput(APD_PIOC,0xcbb8);
/* setup PIOD */
apd_PIOSetMuxFunc(APD_PIOD,0x00,0xffff);
/* set PIOD output & input */
apd_PIOSetAsOutput(APD_PIOD,0x00);
apd_PIOSetAsInput(APD_PIOD,0xffff);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -