新聞中心

EEPW首頁(yè) > 嵌入式系統(tǒng) > 設(shè)計(jì)應(yīng)用 > NRF9E51讀IC卡卡號(hào),并把讀取到的數(shù)據(jù)傳送出去

NRF9E51讀IC卡卡號(hào),并把讀取到的數(shù)據(jù)傳送出去

作者: 時(shí)間:2016-11-30 來(lái)源:網(wǎng)絡(luò) 收藏
/*void rst_wdog()
{ if((REGX_CTRL&0x10)!=0x10)
{ REGX_MSB=0x75;
REGX_LSB=0x30;
// REGX_CTRL=0x08;
}
}*/
unsigned char SpiReadWrite(unsigned char b)
{
EXIF &= ~0x20; // Clear SPI interrupt
SPI_DATA = b; // Move byte to send to SPI data register
while((EXIF & 0x20) == 0x00) // Wait until SPI hs finished transmitting
;
return SPI_DATA;
}
void TransmitPacket()
{
unsigned char i;
CE = 1;
Delay100us(0);
// All packets start with the receiver address:
for(i=0;i
SpiReadWrite(tconf.buf[ADDR_INDEX+i]);
SpiReadWrite(array[0]);
SpiReadWrite(array[1]);
SpiReadWrite(array[2]);
CE = 0;
Delay100us(3); // Wait ~300us
}
///led000000000000000000000000000000000000
/*定時(shí)器0和定時(shí)器1的定時(shí)間是10ms*/
void InitTimer(void)
{
TR0 = 0;
TMOD &= ~0x33;
TMOD |= 0x11; // mode 1
CKCON |= 0x98; // T0M = 1 (/4 timer clock)
t0lrel = 0xC0; // 1KHz tick...
t0hrel = 0x63; // ... = 65536-16e6/(4*1e3) = F060h
TF0 = 0; // Clear any pending Timer0 interrupts
ET0 = 1; // Enable Timer0 interrupt
TR1=0;
t1lrel=0xC0;
t1hrel=0x63;
TF1 = 0; // Clear any pending Timer0 interrupts
ET1 = 1;
T2CON=0x00;
RCAP2H=0xFE;
RCAP2L=0x70;
ET2=1;
}
void Timer0ISR (void) interrupt 1
{
TF0 = 0; // Clear Timer0 interrupt
TH0 = t0hrel; // Reload Timer0 high byte
TL0 = t0lrel; // Reload Timer0 low byte
count0++;
if (count0==300)
{
LED=0; // Led off
TR0 = 0; // Stop timer
}
}
void Timer1ISR(void) interrupt 3
{
TF1 = 0; // Clear Timer1 interrupt
TH1 = t1hrel; // Reload Timer1 high byte
TL1 = t1lrel; // Reload Timer1 low byte
count++;
if (count == 120)
{
count=0;
over_flag=1;
TR1=0;
}
}
void Timer2ISR (void) interrupt 5 using 2
{
TF2 = 0;
count1++;
if (count1==1)
{
data0=1;
data1=1;
}
else if(count1==11)
{ count1=0;
over1_flag=1;
TR2=0;
}
}
void Receiver(void)
{
unsigned char b;
CS = 1;
Delay100us(0);
for(b=0;b {
SpiReadWrite(rconf.buf[b]);
}
CS = 0;
for(;;)
{
CE = 1;
while(DR1 == 0)
{ //rst_wdog();
nop();
}
a[0]=SpiReadWrite(0);
a[1]=SpiReadWrite(1);
a[2]= SpiReadWrite(2);
CE = 0;
LED=1;
count0=0;
TR0 = 1;
if(fsen==0)
{
fs();
}
//rst_wdog();
}
}
void Transmitter(void)
{
unsigned char b;
CS = 1;
Delay100us(0);
for(b=0;b {
SpiReadWrite(tconf.buf[b]);
}
CS = 0;
for(;;)
{ //rst_wdog();
TransmitPacket(); // Transmit data
over_flag=0;
TR1=1;
LED=1;
while(!over_flag)
{ nop();
}
}
}
void Init(void)
{ uchar i;
uchar j;
P0_DIR=0x00;
P0=0xfb;
P1=0xff;
SPICLK=1;
SPI_CTRL=0x02; //連接到RADIO上
PWR_UP = 1; // Turn on Radio on 24E1
Delay100us(30); // Wait > 3ms
InitTimer();
EA = 1;
for(j=0;j<2;j++)
{ LED=1;
for(i=0;i<10;i++)
{ Delay100us(250);
Delay100us(250);
}
LED=0;
for(i=0;i<10;i++)
{ Delay100us(250);
Delay100us(250);
}
}
}
void main(void)
{
Init();
/*f((REGX_CTRL&0x10)!=0x10)
{
REGX_MSB=0x75;
REGX_LSB=0x30;
REGX_CTRL=0x08;
} */
//Receiver();
Transmitter();
}
上一頁(yè) 1 2 下一頁(yè)

關(guān)鍵詞: NRF9E51IC卡卡

評(píng)論


技術(shù)專區(qū)

關(guān)閉