AS3992阅读器主程序里为什么要用莫尔斯编码?完全不懂啊,哪位大神指教一下啊。
时间:10-02
整理:3721RD
点击:
/*
*****************************************************************************
* Copyright @ 2009 by austriamicrosystems AG *
* All rights are reserved. *
* *
* IMPORTANT - PLEASE READ CAREFULLY BEFORE COPYING, INSTALLING OR USING *
* THE SOFTWARE. *
* *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS *
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT *
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS *
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT *
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, *
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT *
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, *
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY *
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT *
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE *
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
*****************************************************************************
*/
/** @file
*
*
* @author Ulrich Herrmann
*/
#include "c8051F340.h"
#include "uart.h"
#include "as399x_public.h"
#include "as399x.h"
#include "gen2.h"
#include "global.h"
#include "iso6b.h"
#include "timer.h"
#include "usb_commands.h"
#include "as399x_config.h"
#include "F340_FlashPrimitives.h"
#include "F3xx_USB0_Register.h"
#include "F3xx_Blink_Control.h"
#include "F3xx_USB0_InterruptServiceRoutine.h"
#include "F3xx_USB0_Descriptor.h"
extern Freq Frequencies;
extern XDATA Tag tags_[MAXTAG];
#define ENTRY_POINT_ADDR 0
static bool continueAlways( ) {return 1; }
static void calcBestSlotSize( void )
{
u8 round;
u8 powSlot;
u8 numTags;
for ( powSlot = 0; powSlot < 15 ; powSlot ++) //try every q
{
u8 maxTags=0;
u16 tagsFound=0;
for ( round = 0; round < 255 ; round ++)
{
numTags = gen2SearchForTags(tags_,16,0,0,powSlot,0, continueAlways);
tagsFound+= numTags;
if ( numTags > maxTags) maxTags = numTags;
}
CON_print("found with powSlot=%hhx %x tags, max %hhx\n",
powSlot, tagsFound,maxTags);
}
}
static const u8 codes[0x10] =
{
/* upper 3 bits length, lower 5 bits shorts/longs */
0xbf, /* 0 ----- */
0xaf, /* 1 .--- */
0xa7, /* 2 ..--- */
0xa3, /* 3 ...-- */
0xa1, /* 4 ....- */
0xa0, /* 5 ..... */
0xb0, /* 6 -.... */
0xb8, /* 7 --... */
0xbc, /* 8 ---.. */
0xbe, /* 9 ----. */
0x41, /* a .- */
0x88, /* b -... */
0x8a, /* c -.-. */
0x64, /* d -.. */
0x20, /* e . */
0x82, /* f ..-. */
};
static void morse_nibble( u8 nibble )
{
u8 i, cod, code_len;
if (nibble > 0xf) nibble = 0x89; /* -..- = "x" */
cod = codes[nibble];
code_len = cod >> 5;
for ( i = code_len; i>0; i-- )
{
LED1(0);
if ( cod & (1<<(i-1)) )
{
CON_print("-");
mdelay(450);
}
else
{
CON_print(".");
mdelay(150);
}
LED1(1);
mdelay(150);
}
CON_print(" %hhx\n", nibble);
mdelay(450);
}
/** main function
+ It dosn't take any parameter and it doesn't return a value
*/
void main(void)
{
u8 count = 0;
u16 failure;
unsigned short counter = 200;
u8 a;
PCA0MD &= ~0x40; /* WDTE = 0 (clear watchdog timer */
/* System_Init already sets clocks, do this before initing uart */
System_Init ();
EA = 1; /* enable all interrupts */
initUART();
initCommands(); /* USB report commands */
CON_print("Hello World\n");
/* Fill frequencies interval used in usb_commands.c with values */
/* European channels since we are developping in Europe, values can be changed using GUI */
Frequencies.freq[0]= 866900;Frequencies.rssiThreshold[0]=-40;
Frequencies.freq[1]= 865700;Frequencies.rssiThreshold[1]=-40;
Frequencies.freq[2]= 866300;Frequencies.rssiThreshold[2]=-40;
Frequencies.freq[3]= 867500;Frequencies.rssiThreshold[3]=-40;
Frequencies.activefreq=4;
failure = as399xInitialize(912000); /* Initializes also the parallel interface. */
if (failure)
{
mdelay(1000);
morse_nibble(failure);
mdelay(1000);
}
CON_print("as399xInitialize() returned %x\n",failure);
//iso6bInitialize();
//calcBestSlotSize();
#ifdef ENTRY_POINT_ADDR
/* systems seems to be up and running. set the magic byte to tell the bootloader引导模式
to boot the image also next time */
if (ENTRY_POINT_ADDR > 0)
{
FLASH_ByteWrite(ENTRY_POINT_ADDR-1, 0xaa);
}
#endif
#if ! UARTSUPPORT //in as399x_config.h #define UARTSUPPORT 1
Usb_Init ();
#endif
while (1)
{
if (counter)
{
counter--;
}
else
{
counter = (24000<<(failure?4:0));
if (a) {
a=0;
LED1(0);
}
else {
a=1;
LED1(1);
}
}
#if UARTSUPPORT
uartCommands(); /* main trigger for operation commands received by UART. */
#else
commands(); /* main trigger for operation commands received by USB. */
#endif
}
}
*****************************************************************************
* Copyright @ 2009 by austriamicrosystems AG *
* All rights are reserved. *
* *
* IMPORTANT - PLEASE READ CAREFULLY BEFORE COPYING, INSTALLING OR USING *
* THE SOFTWARE. *
* *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS *
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT *
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS *
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT *
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, *
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT *
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, *
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY *
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT *
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE *
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
*****************************************************************************
*/
/** @file
*
*
* @author Ulrich Herrmann
*/
#include "c8051F340.h"
#include "uart.h"
#include "as399x_public.h"
#include "as399x.h"
#include "gen2.h"
#include "global.h"
#include "iso6b.h"
#include "timer.h"
#include "usb_commands.h"
#include "as399x_config.h"
#include "F340_FlashPrimitives.h"
#include "F3xx_USB0_Register.h"
#include "F3xx_Blink_Control.h"
#include "F3xx_USB0_InterruptServiceRoutine.h"
#include "F3xx_USB0_Descriptor.h"
extern Freq Frequencies;
extern XDATA Tag tags_[MAXTAG];
#define ENTRY_POINT_ADDR 0
static bool continueAlways( ) {return 1; }
static void calcBestSlotSize( void )
{
u8 round;
u8 powSlot;
u8 numTags;
for ( powSlot = 0; powSlot < 15 ; powSlot ++) //try every q
{
u8 maxTags=0;
u16 tagsFound=0;
for ( round = 0; round < 255 ; round ++)
{
numTags = gen2SearchForTags(tags_,16,0,0,powSlot,0, continueAlways);
tagsFound+= numTags;
if ( numTags > maxTags) maxTags = numTags;
}
CON_print("found with powSlot=%hhx %x tags, max %hhx\n",
powSlot, tagsFound,maxTags);
}
}
static const u8 codes[0x10] =
{
/* upper 3 bits length, lower 5 bits shorts/longs */
0xbf, /* 0 ----- */
0xaf, /* 1 .--- */
0xa7, /* 2 ..--- */
0xa3, /* 3 ...-- */
0xa1, /* 4 ....- */
0xa0, /* 5 ..... */
0xb0, /* 6 -.... */
0xb8, /* 7 --... */
0xbc, /* 8 ---.. */
0xbe, /* 9 ----. */
0x41, /* a .- */
0x88, /* b -... */
0x8a, /* c -.-. */
0x64, /* d -.. */
0x20, /* e . */
0x82, /* f ..-. */
};
static void morse_nibble( u8 nibble )
{
u8 i, cod, code_len;
if (nibble > 0xf) nibble = 0x89; /* -..- = "x" */
cod = codes[nibble];
code_len = cod >> 5;
for ( i = code_len; i>0; i-- )
{
LED1(0);
if ( cod & (1<<(i-1)) )
{
CON_print("-");
mdelay(450);
}
else
{
CON_print(".");
mdelay(150);
}
LED1(1);
mdelay(150);
}
CON_print(" %hhx\n", nibble);
mdelay(450);
}
/** main function
+ It dosn't take any parameter and it doesn't return a value
*/
void main(void)
{
u8 count = 0;
u16 failure;
unsigned short counter = 200;
u8 a;
PCA0MD &= ~0x40; /* WDTE = 0 (clear watchdog timer */
/* System_Init already sets clocks, do this before initing uart */
System_Init ();
EA = 1; /* enable all interrupts */
initUART();
initCommands(); /* USB report commands */
CON_print("Hello World\n");
/* Fill frequencies interval used in usb_commands.c with values */
/* European channels since we are developping in Europe, values can be changed using GUI */
Frequencies.freq[0]= 866900;Frequencies.rssiThreshold[0]=-40;
Frequencies.freq[1]= 865700;Frequencies.rssiThreshold[1]=-40;
Frequencies.freq[2]= 866300;Frequencies.rssiThreshold[2]=-40;
Frequencies.freq[3]= 867500;Frequencies.rssiThreshold[3]=-40;
Frequencies.activefreq=4;
failure = as399xInitialize(912000); /* Initializes also the parallel interface. */
if (failure)
{
mdelay(1000);
morse_nibble(failure);
mdelay(1000);
}
CON_print("as399xInitialize() returned %x\n",failure);
//iso6bInitialize();
//calcBestSlotSize();
#ifdef ENTRY_POINT_ADDR
/* systems seems to be up and running. set the magic byte to tell the bootloader引导模式
to boot the image also next time */
if (ENTRY_POINT_ADDR > 0)
{
FLASH_ByteWrite(ENTRY_POINT_ADDR-1, 0xaa);
}
#endif
#if ! UARTSUPPORT //in as399x_config.h #define UARTSUPPORT 1
Usb_Init ();
#endif
while (1)
{
if (counter)
{
counter--;
}
else
{
counter = (24000<<(failure?4:0));
if (a) {
a=0;
LED1(0);
}
else {
a=1;
LED1(1);
}
}
#if UARTSUPPORT
uartCommands(); /* main trigger for operation commands received by UART. */
#else
commands(); /* main trigger for operation commands received by USB. */
#endif
}
}
好长的程序,看得懂的走起来~~
这只是主函数。不知道为什么要用莫尔斯编码啊