📄 lpc2129_paypass_ttal1_functions.c
字号:
}
}
//-----------------------------------------------------------------------------
// Function name : GetPowerTwo
//-----------------------------------------------------------------------------
// Description : This function get 2 raised to power "p_lTimeout"
//
// IN : p_lTimeout : power value
// OUT : result of operation -
// RETURN : - none -
// Notes : This function
//-----------------------------------------------------------------------------
long GetPowerTwo(long p_lTimeout)
{
long Result,i,temp=2;
if(p_lTimeout==0) {return 1;}
if(p_lTimeout==1) {return 2;}
for(i=1;i<p_lTimeout;i++)
{
Result=temp*2;
temp=Result;
}
return Result;
}
//-----------------------------------------------------------------------------
// Function : v_fnDefineTimeout(unsigned char p_bTimeout)
//-----------------------------------------------------------------------------
// Description : Define TMR0 initialization (Set the timeout value into Timer 0 Matching register)
//
// IN : p_bTimeOut : If p_bTimeOut <0E, Timeout will be set according to :
// 0x00 TimeOut = 302祍
// 0x01 TimeOut = 604祍
// 0x02 TimeOut = 1,24ms
// 0x03 TimeOut = 2,42ms
// 0x04 ...etc...
//
// If p_bTimeOut >=0E, TimeOut= p_bTimeOut(a value in 祍)
//
// OUT : - none -
//
// RETURN : - none -
//
// Notes : Here Timer 0 of the LPC2129 is used
// -This function set the Timer 0 Matching Register value of the LP2129 as the time out value :
// -If p_lTimeout<0x0E ---> "Timer 0 Matching register value" = (Timer value of 1祍)*pow(2,p_lTimeout)
// -If p_lTimeout>=0x0E ---> "Timer 0 Matching register value" = p_lTimeout(in 祍)
// -A value of 530 祍 is added at each timeout definition to concider
// communication timings between MCU and Picoread (only if p_lTimeout<0x0E)
//-----------------------------------------------------------------------------
void v_fnDefineTimeout(unsigned long p_lTimeout)
{
//extern double pow(double,double);
unsigned long l_lTimeout=0x0FFF;
if(p_lTimeout<=0x0E)
{
// 0x3FF as been defined according to 13.56MHz Oscillator and should correspond to 302祍 for each PLL settings
l_lTimeout=ONE_U_SECOND*0x12E*GetPowerTwo(p_lTimeout);
//Add Offset of 530祍
// 0x706 as been defined according to 13.56MHz Oscillator and should correspond to 530祍 for each PLL settings
l_lTimeout+=ONE_U_SECOND*0x212; // Process TimeOut according to XTAL and PLL settings
}else
{
l_lTimeout =(unsigned long)(p_lTimeout * ONE_U_SECOND);
}
//STOP TIMER0
T0TCR = (unsigned long)0x02; // Timer0 Disable
T0TC = (unsigned long)0x00000000; // Reset TC
T0MCR = (unsigned long)0x00000001; // Interrupt on MR0 and reset TC on match
T0MR0 = (unsigned long)l_lTimeout; // TC Init //ASSIGN TIME OUT
T0IR = (unsigned long)0x01; // Clear interrupt flag
T0PR = TIMER_0_PRESCALER ; // Prescale 0
}
//-----------------------------------------------------------------------------
// Function name : v_fnTimeOutStart
//-----------------------------------------------------------------------------
// Description : This function starts the TIMER0.--> Start Timeout Timer.
//
// IN : - none -
// OUT : - none -
// RETURN : - none -
// Notes : This function use the timer 0 of the LP2129
// This function is used in association with v_fnDefineTimeout function
//-----------------------------------------------------------------------------
void v_fnTimeOutStart()
{
//START TIMER0
T0TCR = 1;
}
//-----------------------------------------------------------------------------
// Function name : v_fnConfigPorts
//-----------------------------------------------------------------------------
// Description : This function initialize IO mode and state, peripherals, ....
//
// IN : - none -
// OUT : - none -
// RETURN : - none -
// Notes : - none -
//-----------------------------------------------------------------------------
void v_fnInitRegsAndPorts()
{
VPBDIV=0x01; // PCLK= CCLK/4
//
//
MAMCR=0x2; //MAM Control Register : Fully Enabled
MAMTIM=0x4; //MAM Timing : 4 clock cycles
/* Init PLL */
//XTAL @ 13.56 MHz
/*-------HERE IS THE CODE THAT AS TO BE MODIFIED ACCORDING TO THE TARGET AND USER NEEDS------- */
PLLCFG=0x23; // PLL x4 div 1
PLLCON=0x03; // PLL Enable
if ((PLLCON& 0xFF)==0) // If PLL x1 /1
{
PLLCFG=0x00; // Disconnect PLL
}
PLLFEED=0xAA; //Activate
PLLFEED=0x55; //And connect PLL
while((PLLSTAT & 0x0400)== 0x0000); // Wait PLL to Lock
//DEFINE IO MODES
// initialize the serial interface
PINSEL0 = 0x00050005; // Enable RxD0 and TxD0 Enable RxD1 and TxD1
/*Choosen UART is UART0 for the Console*/
// UART0 Setting
U0LCR = 0x83; // 8 bits, no Parity, 1 Stop bit
/*For 9600 baud rate */
// U0FDR=0x10;
switch(VPBDIV)
{
case 0x00: APBDivider=4; break;
case 0x01: APBDivider=1; break;
case 0x02: APBDivider=2; break;
}
U0DLM = 0x01;
U0DLL = 352;
//13.56M *(PLL MSEL+1)/(PLL PSEL+1) /4(Peripheral Prescaler) /16(Baud Rate Generator Divider) / U1DLL = 9600 (approx) for a 13.56MHz VPB Clock
// DLAB = 0
U0LCR = 0x03; // DLAB = 0
//Initialize GPIO PORT
//Initialize GPIO PORT
IODIR0 = CS_MASK | SCK_MASK | SDO_MASK ;//| DEBUGPIN_MASK | DEBUGPIN2_MASK ;
//P0.10 Output SDO 礐
//P0.11 Input SDI 礐
//P0.12 Output SCK 礐
//P0.13 Output CS 礐
//P0.8 Output DEBUG Pin
//P0.16 Output DEBUG Pin 2
IOSET0 = SDO_MASK ; //P0.10 @1 Set SDO,SSEL0,READY at 1 others to 0
//IOCLR0 = DEBUGPIN2_MASK;
//------------------------------------------------------------------------------------
//************************************************************************************
// HERE ADD IO SETTINGS ACCORDING TO YOUR BOARD DESIGN, AND YOUR NEEDS
//************************************************************************************
//------------------------------------------------------------------------------------
}
//-----------------------------------------------------------------------------
// Function name : _getkey
//-----------------------------------------------------------------------------
// Description : This function receive a byte from UART0 RBR register
//
// IN : - none -
// OUT : - none -
// RETURN : - byte value -
// Notes : - none -
//-----------------------------------------------------------------------------
int _getkey (void)
{ /* Read character from Serial Port */
while (!(U0LSR & 0x01));
return (U0RBR);
}
//-----------------------------------------------------------------------------
// Function name : putchar
//-----------------------------------------------------------------------------
// Description : This function send a byte from UART0 THR register
//
// IN : - byte to send -
// OUT : - none -
// RETURN : - byte sent -
// Notes : - none -
//-----------------------------------------------------------------------------
int putchar (int ch)
{ // Write character to Serial Port
if (ch == '\n')
{ // expand LF into CR + LF
while (!(U0LSR & 0x20));
U0THR = '\r'; // output CR
}
while (!(U0LSR & 0x20));
return (U0THR = ch);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -