AS3933-firmware

整理文档很辛苦,赏杯茶钱您下走!

免费阅读已结束,点击下载阅读编辑剩下 ...

阅读已结束,您可以下载文档离线阅读编辑

资源描述

文件:C:\DocumentsandSettings\Administrator\桌面\AS3933.c2015-7-29,17:332:39#includemain.h//==============================================================================voidInitial_AS3933(void){unsignedcharfg,value;AS3933_Direct_Command(PRESET_DEFAULT);AS3933_Direct_Command(CLEAR_WAKE);AS3933_Write_Single_Reg(REG0,0x4E);//Default0x0E,使能X,Y,Z轴//bit6=MasksdataonDATpinbeforewake-up:0=datanotmasked;1=datamaskedif(DAMPER_RESISTOR==0x00)AS3933_Write_Single_Reg(REG1,0x2B);//Default0x23elseAS3933_Write_Single_Reg(REG1,0x3B);//Default0x23//bit5=1:AGCOperatinginbothdirection(up-down)//bit4=1:Antennadamperenable//bit3=1:Manchesterdecoderenable//bit2=1:Doublewake-uppatterncorrelation//bit1=0:disableCorrelator//bit0=1:CrystalOscillatorenableAS3933_Write_Single_Reg(REG2,0x00);//Default0x00,bit3-2=11:ShowPinCL_DATAS3933_Write_Single_Reg(REG3,0x20);//Default0x20if(DAMPER_RESISTOR==0){value=0x10;fg=GAIN_REDUCTION&0x0F;value|=fg;}else{value=(DAMPER_RESISTOR-1)&0x03;//减1后才能与寄存器对应,&3是做容错处理value=4;fg=GAIN_REDUCTION&0x0F;value|=fg;}AS3933_Write_Single_Reg(REG4,value);//Default0x10//bit5-4:Antennadampingresistor.00=1k;01=3k;10=9k;11=27k.电阻值越小,通讯效果反面越差//bit3-0:Gainreduction//Wake-upPattern必须与发射端一样才能唤醒AS3933_Write_Single_Reg(REG5,0x59);//Default0x69,2ndByteofwake-uppatternAS3933_Write_Single_Reg(REG6,0xAA);//Default0x96,1stByteofwake-uppatternAS3933_Write_Single_Reg(REG7,0xEB);//Default0x0B,Timeout=200ms,BitDurationinClockGeneratorPeriods=4//bit7-5:自动清空唤醒标签的延时时间//000=display;001=50ms;010=100ms;......;111=350ms第1页文件:C:\DocumentsandSettings\Administrator\桌面\AS3933.c2015-7-29,17:332:39AS3933_Write_Single_Reg(REG8,0x00);//Default0x00,OperatingFrequencyRange=95-150kHzAS3933_Write_Single_Reg(REG9,0x00);//Default0x00//REG10-REG15:ReadOnlyAS3933_Write_Single_Reg(REG16,0x00);//Default0x00//打开bit2-0后,电流大很多.可用示波器在DAT脚中测出共振频率的大小;若关掉,则测不到//如果直接在LF1P,LF2P,LF3P脚中测,则实际频率会变小.受探测脚的影响//注意:测试共振频率时,需要打开R14:Antennadamperenable,并将R45-4设为27kR.根据开发板的操作来的AS3933_Write_Single_Reg(REG17,0x00);//Default0x00AS3933_Write_Single_Reg(REG18,0x00);//Default0x00AS3933_Write_Single_Reg(REG19,0x00);//Default0x00AS3933_Direct_Command(CLEAR_WAKE);AS3933_Direct_Command(CLEAR_FALSE);}//==============================================================================voidAS3933_Direct_Command(unsignedcharcmd){unsignedchari;SET_AS_CS_H;cmd|=0xC0;//直接命令的bit7-6=11for(i=0;i8;i++){SET_AS_SCL_H;if(cmd&0x80)SET_AS_SDI_H;elseSET_AS_SDI_L;cmd=1;SET_AS_SCL_L;//SCL下降延采样}SET_AS_SDI_L;delay_us(AS_DELAY_TIME);SET_AS_CS_L;}//==============================================================================voidAS3933_Write_Single_Reg(unsignedcharaddr,unsignedchardat){unsignedchari;unsignedintvalue;SET_AS_CS_H;第2页文件:C:\DocumentsandSettings\Administrator\桌面\AS3933.c2015-7-29,17:332:39value=((unsignedint)(addr&0x3F)8)+dat;//写命令的bit7-6=00for(i=0;i16;i++){SET_AS_SCL_H;if(value&0x8000)SET_AS_SDI_H;elseSET_AS_SDI_L;value=1;SET_AS_SCL_L;//SCL下降延采样}SET_AS_SDI_L;delay_us(AS_DELAY_TIME);SET_AS_CS_L;}//==============================================================================//连续写多个寄存器,寄存器地址会自动增1//参数1:要写入的首个寄存器地址//参数2:要写入的寄存器值地址//参数3:要连续写入的寄存器数量//==============================================================================voidAS3933_Write_N_Reg(unsignedcharaddr,unsignedchar*ptr,unsignedcharnum){unsignedchari,j;SET_AS_CS_H;//写寄存器地址addr&=0x3F;//写命令的bit7-6=00for(i=0;i8;i++){SET_AS_SCL_H;if(addr&0x80)SET_AS_SDI_H;elseSET_AS_SDI_L;addr=1;SET_AS_SCL_L;//SCL下降延采样}//连续写寄存器值for(i=0;inum;i++){for(j=0;j8;j++){SET_AS_SCL_H;if(ptr[i]&0x80)SET_AS_SDI_H;elseSET_AS_SDI_L;第3页文件:C:\DocumentsandSettings\Administrator\桌面\AS3933.c2015-7-29,17:332:39ptr[i]=1;SET_AS_SCL_L;//SCL下降延采样}}SET_AS_SDI_L;delay_us(AS_DELAY_TIME);SET_AS_CS_L;}//==============================================================================unsignedcharAS3933_Read_Single_Reg(unsignedcharaddr){unsignedchari,value;SET_AS_CS_H;addr&=0x3F;addr|=0x40;//读命令的bit7-6=01//发送寄存器地址for(i=0;i8;i++){SET_AS_SCL_H;if(addr&0x80)SET_AS_SDI_H;elseSET_AS_SDI_L;addr=1;SET_AS_SCL_L;//SCL下降延采样}//接收寄存器值value=0;for(i=0;i8;i++){SET_AS_SCL_H;value=1;//放中间,正好可以延时一小会SET_AS_SCL_L;//SCL下降延读取if(AS_SDO_IS_H)value|=1;}SET_AS_SDI_L;delay_us(AS_DELAY_TIME);SET_AS_CS_L;returnvalue;}//==============================================================================//连续读取多个寄存器值,寄存器地址会自动增1第4页文件:C:\DocumentsandSettings\Administrator\桌面\AS3933.c2015-7-29,17:332:39//参数1:要读取的首个寄存器地址//参数2:存放读取的寄存器值地址//参数3:要连续读取的寄存器数量//==============================================================================voidAS3933_Read_N_Reg(unsignedcharaddr,unsignedchar*ptr,unsignedcharnum){unsignedchari,j;SET_AS_CS_H;addr&=0x3F;addr|=0x40;//读命令的bit7-6=01//发送寄存器地址for(i=0;i8;i++){SET_AS_SCL_H;if(addr&0x80)SET_AS_SDI_H;elseSET_AS_SDI_L;addr=1;SET_AS_SCL_L;//SCL下降延采样}//接收寄存器值for(i=0;inum;i++){ptr[i]=0;for(j=0;j8;j++){SET_AS_SCL_H;ptr[i]=1;SET_AS_SCL_L;//SCL下降延读取if(AS_SDO_IS_H)ptr[i]|=1;}}SET_AS_SDI_L;delay_us(AS_DELAY_TIME);SET_AS_CS_L;}第5页

1 / 5
下载文档,编辑使用

©2015-2020 m.777doc.com 三七文档.

备案号:鲁ICP备2024069028号-1 客服联系 QQ:2149211541

×
保存成功