?? lpclib.c.bak
字號:
#include "config.h"
#include "lpclib.h"
#define UART_BPS 115200 //串口通訊波特率
#define SETdatab 8
#define SETstopb 1
#define SETparity 0
extern void IRQ_Eint0 (void)__irq;
extern void IRQ_Eint1 (void)__irq;
extern void IRQ_Eint2 (void)__irq;
extern void IRQ_Eint3 (void)__irq;
extern void IRQ_TIME1 (void)__irq;
extern void IRQ_UART0 (void)__irq;
char str[140]; //串口取字符串緩沖區(qū)
//********第一軌*********************************************//
unsigned char buf1[100]; //已編碼待寫入的磁卡數(shù)據(jù)
volatile unsigned char num1; //待寫入的數(shù)據(jù)總長度
volatile unsigned char count_num1; //已寫入的字節(jié)數(shù)
volatile unsigned char befor1_flag; //上一周期寫的數(shù)據(jù)
volatile unsigned char w1_flag; //將寫寫入的數(shù)據(jù)位
volatile unsigned char bit_len1; //已寫入的數(shù)據(jù)位數(shù)
volatile unsigned char LRC1; //LRC校驗
volatile unsigned char EXT_FLAG1; //寫卡完畢標(biāo)志
//********第二軌*********************************************//
unsigned char buf2[70]; //已編碼待寫入的磁卡數(shù)據(jù)
volatile unsigned char num2; //待寫入的數(shù)據(jù)總長度
volatile unsigned char count_num2; //已寫入的字節(jié)數(shù)
volatile unsigned char befor2_flag; //上一周期寫的數(shù)據(jù)
volatile unsigned char w2_flag; //將寫寫入的數(shù)據(jù)位
volatile unsigned char int2_flag; //已寫入一次標(biāo)志位
volatile unsigned char bit_len2; //已寫入的數(shù)據(jù)位數(shù)
volatile unsigned char LRC2; //LRC校驗
volatile unsigned char EXT_FLAG2; //寫卡完畢標(biāo)志
//********第三軌*********************************************//
volatile unsigned char buf3[140]; //已編碼待寫入的磁卡數(shù)據(jù)
volatile unsigned char num3; //待寫入的數(shù)據(jù)總長度
volatile unsigned char count_num3; //已寫入的字節(jié)數(shù)
volatile unsigned char befor3_flag; //上一周期寫的數(shù)據(jù)
volatile unsigned char w3_flag; //將寫寫入的數(shù)據(jù)位
volatile unsigned char int3_flag; //已寫入一次標(biāo)志位
volatile unsigned char bit_len3; //已寫入的數(shù)據(jù)位數(shù)
volatile unsigned char LRC3; //LRC校驗
volatile unsigned char EXT_FLAG3; //寫卡完畢標(biāo)志
//--------------------------------------------------------------------------------------
//編碼數(shù)組
//code_23asci[16][3]=
//--------------------------------------------------------------------------------------
unsigned char const code_23asci[16][3]=
{0x30,'0', 0x10,// 0001 0000
0x31,'1', 0x01,// 0000 0001
0x32,'2', 0x02,// 0000 0010
0x33,'3', 0x13,// 0001 0011
0x34,'4', 0x04,// 0000 0100
0x35,'5', 0x15,// 0001 0101
0x36,'6', 0x16,// 0001 0110
0x37,'7', 0x07,// 0000 0111
0x38,'8', 0x08,// 0000 1000
0x39,'9', 0x19,// 0001 1001
0x3a,':', 0x1a,// 0001 1010
0x3b,';', 0x0b,// 0000 1011
0x3c,'<', 0x1c,// 0001 1100
0x3d,'=', 0x0d,// 0000 1101
0x3e,'>', 0x0e,// 0000 1110
0x3f,'?', 0x1f,// 0001 1111
};
//--------------------------------------------------------------------------------------
//編碼數(shù)組
//code_23asci[16][3]=
//--------------------------------------------------------------------------------------
unsigned char const code_1asci[64][3]=
{0x20,' ', 0x40,// 0100 0000
0x21,'!', 0x01,// 0000 0001
0x22,'"', 0x02,// 0000 0010
0x23,'#', 0x43,// 0100 0011
0x24,'$', 0x04,// 0000 0100
0x25,'%', 0x45,// 0100 0101
0x26,'&', 0x46,// 0100 0110
0x27,' ', 0x07,// 0000 0111
0x28,'(', 0x08,// 0000 1000
0x29,')', 0x49,// 0100 1001
0x2a,'*', 0x4a,// 0100 1010
0x2b,'+', 0x0b,// 0000 1011
0x2c,' ', 0x4c,// 0100 1100
0x2d,'-', 0x0d,// 0000 1101
0x2e,'.', 0x0e,// 0000 1110
0x2f,'/', 0x4f,// 0100 1111
0x30,'0', 0x10,// 0001 0000
0x31,'1', 0x51,// 0101 0001
0x32,'2', 0x52,// 0101 0010
0x33,'3', 0x13,// 0001 0011
0x34,'4', 0x54,// 0101 0100
0x35,'5', 0x15,// 0001 0101
0x36,'6', 0x16,// 0001 0110
0x37,'7', 0x57,// 0101 0111
0x38,'8', 0x58,// 0101 1000
0x39,'9', 0x19,// 0001 1001
0x3a,':', 0x1a,// 0001 1010
0x3b,';', 0x5b,// 0101 1011
0x3c,'<', 0x1c,// 0001 1100
0x3d,'=', 0x5d,// 0101 1101
0x3e,'>', 0x5e,// 0101 1110
0x3f,'?', 0x1f,// 0001 1111
0x40,'@', 0x20,// 0010 0000
0x41,'A', 0x61,// 0110 0001
0x42,'B', 0x62,// 0110 0010
0x43,'C', 0x23,// 0010 0011
0x44,'D', 0x64,// 0110 0100
0x45,'E', 0x25,// 0010 0101
0x46,'F', 0x26,// 0010 0110
0x47,'G', 0x67,// 0110 0111
0x48,'H', 0x68,// 0110 1000
0x49,'I', 0x29,// 0010 1001
0x4a,'J', 0x2a,// 0010 1010
0x4b,'K', 0x6b,// 0110 1011
0x4c,'L', 0x2c,// 0010 1100
0x4d,'M', 0x6d,// 0110 1101
0x4e,'N', 0x6e,// 0110 1110
0x4f,'O', 0x2f,// 0010 1111
0x50,'P', 0x70,// 0111 0000
0x51,'Q', 0x31,// 0011 0001
0x52,'R', 0x32,// 0011 0010
0x53,'S', 0x73,// 0111 0011
0x54,'T', 0x34,// 0011 0100
0x55,'U', 0x75,// 0111 0101
0x56,'V', 0x76,// 0111 0110
0x57,'W', 0x37,// 0011 0111
0x58,'X', 0x38,// 0011 1000
0x59,'Y', 0x79,// 0111 1001
0x5a,'Z', 0x7a,// 0111 1010
0x5b,'[', 0x3b,// 0011 1011
0x5c,'|', 0x7c,// 0111 1100
0x5d,']', 0x3d,// 0011 1101
0x5e,'^', 0x3e,// 0011 1110
0x5f,'_', 0x3f,// 0111 1111
};
//------------------------------------------------------------------------------------
//計算奇偶校驗
//unsigned char b_lrc (unsigned char dat)
//------------------------------------------------------------------------------------
unsigned char b_lrc (unsigned char dat)
{
unsigned char tmp;
unsigned char tmpdat;
tmp=(dat>>4)&0x0f;
tmpdat=(dat&0x0f)^tmp; //低四位或高4位
tmp=(tmpdat>>2)&0x03; //取低二位
tmpdat=(tmpdat&0x03)^tmp;
tmp=(tmpdat>>1)&0x01;
tmpdat=(tmpdat&0x01)^tmp;
return(tmpdat);
}
//----------------------------------------------------------------------------------------------------
//延時函數(shù)參數(shù)大延時長
//void DelayNS (uint32 dly)
//----------------------------------------------------------------------------------------------------
void DelayNS (uint32 dly)
{
uint32 i;
for ( ; dly>0; dly--)
for (i=0; i<50000; i++);
}
//----------------------------------------------------------------------------------------------------
//初始化串口0
//void UART0_Init (void)
//----------------------------------------------------------------------------------------------------
void UART0_Init (void)
{
uint16 Fdiv;
PINSEL0 =(PINSEL0&(~0x0f))|0x05; //設(shè)置UART0連接,其他為普通IO 口
U0LCR = 0x83; // DLAB=1,允許設(shè)置波特率
Fdiv = (Fpclk / 16) / UART_BPS; // 設(shè)置波特率
U0DLM = Fdiv / 256;
U0DLL = Fdiv % 256;
U0LCR = 0x03;
}
//----------------------------------------------------------------------------------------------------
//初始化串口1
// void UART1_Init (void)
//----------------------------------------------------------------------------------------------------
void UART1_Init (uint32 baud)
{
uint16 Fdiv;
PINSEL0 =(PINSEL0&(~0x0f))|0x05; //設(shè)置UART0連接,其他為普通IO 口
U0LCR = 0x83; // DLAB=1,允許設(shè)置波特率
Fdiv = (Fpclk / 16) / baud; // 設(shè)置波特率
U0DLM = Fdiv / 256;
U0DLL = Fdiv % 256;
U0LCR = 0x03;
}
//----------------------------------------------------------------------------------------------------
//串口0發(fā)送一字節(jié)`
//void UART0_SendByte (uint8 dat)
//----------------------------------------------------------------------------------------------------
char Uart_Getch(void)
{
uint8 rcv_dat;
while ((U1LSR & 0x01) == 0);
rcv_dat = U1RBR;
return (rcv_dat);
}
//----------------------------------------------------------------------------------------------------
//串口0發(fā)送一字節(jié)`
//void UART0_SendByte (uint8 dat)
//----------------------------------------------------------------------------------------------------
void Uart_SendByte (uint8 dat)
{
U1THR = dat;
while ((U1LSR & 0x40) == 0); // 等待數(shù)據(jù)發(fā)送完畢
}
//----------------------------------------------------------------------------------------------------
//串口0發(fā)送字符串`
//void Uart0_SendString(char *pt)
//----------------------------------------------------------------------------------------------------
void Uart_SendString(char *pt)
{
while(*pt)
Uart_SendByte(*pt++);
}
//----------------------------------------------------------------------------------------------------
//串口打印
//void Uart_Printf(char *fmt,...)
//----------------------------------------------------------------------------------------------------
void Uart_Printf(char *fmt,...)
{
va_list ap;
char string[256];
va_start(ap,fmt);
vsprintf(string,fmt,ap);
Uart_SendString(string);
va_end(ap);
}
//----------------------------------------------------------------------------------------------------
//串口0接接收一字符串`
//void Uart_GetString(char *string)
//----------------------------------------------------------------------------------------------------
void Uart_GetString(char *string)
{
char *string2=string;
char c;
while((c=Uart_Getch())!='\r')
{
if(c=='\b')
{
if( (int)string2 < (int)string )
{
Uart_Printf("\b \b");
string--;
}
}
else
{
*string++=c;
Uart_SendByte(c);
}
}
*string='\0';
Uart_SendByte('\n');
}
//-----------------------------------------------------------------------------------------------------
//端口初始化
//void Port_Init(void);
//------------------------------------------------------------------------------------------------------
void Port_Init(void)
{
// P00 RXD P01TXD P03 EINT1 P04 OUT P05 OUT P06 OUT P07 OUT P08 RXD P09TXD P010 IN P011 SCL P014 SDA P015 EINT2
//
// P0. 15 12 8 4 0
//|PINSEL0 | 10 11 00 00 | 11 00 01 01 | 00 00 00 00 | 11 00 01 01 | //控制功能=0xb0c500c5
//|IO0DIR | 0 1 1 1 1 0 0 0 1 1 1 1 0 0 0 0 | //低16位=0x78f0
// P016 EINT0 P018 CAP1.3 P019 CAP1.2 P020 EINT3 P021 OUT P022 OUT P028 OUT P029 IN
//
// P0. 31 28 24 20 16
//|PINSEL1 | 00 00 00 00 | 00 00 00 00 | 00 00 00 11 | 11 00 00 01 | //控制功能=0x000003c1
//|IO0DIR | 1 1 1 0 1 1 1 1 1 1 1 0 0 0 0 0 | //高16位=0xefe0
PINSEL1=0x000003c1; //IO狀態(tài)控制1
PINSEL0=0xb0c500c5; //IO狀態(tài)控制0
IO0DIR =0xefe078f0; //IO方向控制器
IO0SET =0x00000000; //IO置位寄存器
IO0CLR =0x00000000; //IO清除寄存器
//P117 OUT P119 OUT P121 IN P122 OUT P124OUT P125 OUT P127 OUT P129 IN P130 IN
// P. 31 24 16 8 0 //X位為0 P1.31- P1.26用作GPIO口
//|PINSEL2 | 0000 0000 | 0000 0000 | 0000 0000 | 0000 0YX0 | //X位為1 P1.31- P1.26用作JTAG調(diào)試口
// P. 31 24 16 8 0 //Y位為0 P1.25- P1.16用作GPIO口
//|PINSEL2 | 0000 0000 | 0000 0000 | 0000 0000 | 0000 0YX0 | //Y位為1 P1.25- P1.16用作跟蹤調(diào)試口
// IO1DIR 1001 1111 1101 1111 1111 1111 1111 1111 //IO1DIR=0x09fdfffff;
PINSEL2=PINSEL2&0xfffffff9;//除X,Y位外其它位不允許寫1 //用作GPIO口
IO1DIR =0x09fdfffff; //IO方向控制器
IO1SET =0x00000000; //IO置位寄存器
IO1CLR =0x00000000; //IO清除寄存器
}
//----------------------------------------------------------------------------------------------------
//使能HD1 寫NS
//void Hd1_H(void)
//----------------------------------------------------------------------------------------------------
void Hd1_H(void)
{
//IO0SET 0000 0000 0000 0000 0000 0000 000x 0000
IO0SET=IO0SET|0x00000010; //寫入1
//IO1SET 0000 00X0 0000 0000 0000 0000 0000 0000
IO1CLR=IO1CLR|0x02000000; //寫入0
}
//----------------------------------------------------------------------------------------------------
//使能HD1 寫SN
//void Hd1_L(void)
//----------------------------------------------------------------------------------------------------
void Hd1_L(void)
{
//IO0SET 0000 0000 0000 0000 0000 0000 000x 0000
IO0CLR=IO0CLR|0x00000010; //寫入0
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -