1.实验目的
1)通过实验掌握CC2530芯片GPIO的配置方法 2)学会在RFID射频模块的使用方法 3)通过串口输出显示卡号信息 2.实验设备
硬件:PC机一台,ZB2530,RFID射频模块一个 软件:2000/XP/win7系统,IAR 8.10集成开发环境、串口助手 3.实验相关实物图
- #include "variable.h"
- #include"delay.h"
- #include "UART.h"
- #include "IC_w_r.h"
- void InitIO()
- {
- CLKCONCMD &= ~0x40; //设置系统时钟源为32MHZ晶振
- while(CLKCONSTA & 0x40); //等待晶振稳定为32M
- CLKCONCMD &= ~0x47; //设置系统主时钟频率为32MHZ
- UartInitial();
- ( 1 ) // p2.0作为输出口
- P2INP |= 1<<0; //
- ( 2 ) // p2.0作为通用I/O口
- ( 3 ) // p0.7作为输出口
- P0INP |= 1<<7; //
- ( 4 ) // p0.7作为通用I/O口
- P0DIR |= 1<<6; //
- P0INP |= 1<<6;
- P0SEL &= ~(1<<6); //
- P0DIR |= 1<<5; //
- P0INP |= 1<<5;
- P0SEL &= ~(1<<5); //
- P0DIR &= ~(1<<4); //
- P0INP &= ~(1<<4);
- P0SEL &= ~(1<<4); //
- IC_SCK = 1;
- IC_SDA = 1;
- }
- void IC_test()
- {
- uchar ucTagType[4];
- uchar find=0xaa;
- uchar ret;
- while(1)
- {
- //16进制转ASC码
- char i;
- char Card_Id[8]; //存放32位卡号
- uchar asc_16[16]={'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'};
- ret = PcdRequest(0x52,ucTagType);//寻卡
- if(ret != 0x26)
- ret = PcdRequest(0x52,ucTagType);
- if(ret != 0x26)
- find = 0xaa;
- if((ret == 0x26)&&(find == 0xaa))
- {
- if(PcdAnticoll(ucTagType) == 0x26);//防冲撞
- {
- UartSend_String("The Card ID is: ",16);
- //16进制转ASC码
- for(i=0;i<4;i++)
- {
- Card_Id[i*2]=asc_16[ucTagType[i]/16];
- Card_Id[i*2+1]=asc_16[ucTagType[i]%16];
- }
- UartSend_String(Card_Id,8);
- UartSend_String("\n",1);
- find = 0x00;
- }
- }
- }
- }
- void main()
- {
- InitIO();
- PcdReset();
- M500PcdConfigISOType('A');//设置工作方式
- while(1)
- {
- IC_test(); //检测IC卡
- }
- }
复制代码
|