Code/Resource
Windows Develop
Linux-Unix program
Internet-Socket-Network
Web Server
Browser Client
Ftp Server
Ftp Client
Browser Plugins
Proxy Server
Email Server
Email Client
WEB Mail
Firewall-Security
Telnet Server
Telnet Client
ICQ-IM-Chat
Search Engine
Sniffer Package capture
Remote Control
xml-soap-webservice
P2P
WEB(ASP,PHP,...)
TCP/IP Stack
SNMP
Grid Computing
SilverLight
DNS
Cluster Service
Network Security
Communication-Mobile
Game Program
Editor
Multimedia program
Graph program
Compiler program
Compress-Decompress algrithms
Crypt_Decrypt algrithms
Mathimatics-Numerical algorithms
MultiLanguage
Disk/Storage
Java Develop
assembly language
Applications
Other systems
Database system
Embeded-SCM Develop
FlashMX/Flex
source in ebook
Delphi VCL
OS Develop
MiddleWare
MPI
MacOS develop
LabView
ELanguage
Software/Tools
E-Books
Artical/Document
demo.c
Package: 我自己写的RFID读写程序(U2270).zip [view]
Upload User: zqdhsx28
Upload Date: 2010-03-30
Package Size: 154k
Code Size: 5k
Category:
RFID
Development Platform:
C/C++
- #include <reg52.h>
- //#include <string.h>
- //#include <stdio.h>
- //u2270b 读卡子程序,利用T0解码
- #define uchar unsigned char
- #define EMBIT P1^1
- uchar OLDEM=0;
- SCON |= 0xc0; //开启帧错误位。UART设置为9位。
- TCON |= 0x00;
- PCON &= 0x7f;
- TMOD |= 0x11; //定义T0工作模式定时器0作为双8位定时计数 器。
- //TL0为8位定时/计数器通过标准定时器0控制位控制。
- //TH0仅作为8位定时器,由定时器1控制位控制,此模式下定时/计数器1关闭。
- bit bitchange(void)//检查数据
- {
- uchar outtime;
- bit bitc;
- bitc=1;
- outtime=200;
- bitchlp1:
- if (((EMBIT==OLDEM) && (outtime!=0))==1)//数据正确且当outtime不为0时循环
- {
- outtime--;
- rst_wdog();
- goto bitchlp1;
- }
- if (outtime==0)//时间到时,返回bitc标志。
- {
- bitc=0;
- }
- OLDEM=EMBIT;
- return bitc;
- }
- bit findlongpluse(void)
- {
- bit retbit;
- retbit=1;
- OLDEM=EMBIT;
- TH0=0;
- TL0=0;
- TR0=0;
- if (bitchange()==0)
- {
- goto errfindlong;
- }
- TR0=1;
- findllp1:
- if (bitchange()==0)
- {
- goto errfindlong;
- }
- TR0=0;
- if (TH0>2)
- {
- goto errfindlong;
- }
- if (TH0==2)
- {
- goto findllp2;
- }
- if ((TH0==1) && (TL0>98))
- {
- goto findllp2;
- }
- if ((TH0==0) && (TL0<100))
- {
- goto errfindlong;
- }
- TH0=0;
- TL0=0;
- TR0=1;
- goto findllp1;
- errfindlong:retbit=0;
- findllp2: return retbit;
- }
- bit readbit(void)
- {
- bit retbit;
- retbit=1;
- TH0=0;
- TL0=0;
- TR0=1;
- if (bitchange()==0)
- {
- goto errreadbit;
- }
- TR0=0;
- if (TH0>2)
- {
- goto errreadbit;
- }
- if ((TH0==0) && (TL0<100))
- {
- goto errreadbit;
- }
- if (TH0==2)
- {
- goto okreadbit;
- }
- if ((TH0==1) && (TL0>35))
- {
- goto okreadbit;
- }
- TH0=0;
- TL0=0;
- TR0=1;
- if (bitchange()==0)
- {
- goto errreadbit;
- }
- TR0=0;
- if (TH0>1)
- {
- goto errreadbit;
- }
- if ((TH0==0) && (TL0<100))
- {
- goto errreadbit;
- }
- if ((TH0==1) && (TL0>35))
- {
- goto errreadbit;
- }
- goto okreadbit;
- errreadbit:retbit=0;
- okreadbit:return retbit;
- }
- bit findbegin(void)
- {
- bit retbit;
- uchar tempdata;
- uint fk;
- fk=1000;
- retbit=1;
- tempdata=0;
- if (findlongpluse()==0)
- {
- goto errfindbegin;
- }
- findbelp1:
- if (readbit()==0)
- {
- goto errfindbegin;
- }
- if (OLDEM==0)
- {
- if (tempdata==0xff)
- {
- goto okfindbegin;
- }
- tempdata=tempdata<<1;
- tempdata=tempdata | 1;
- }
- else
- {
- tempdata=tempdata<<1;
- }
- fk--;
- if (fk==0)
- {
- goto errfindbegin;
- }
- goto findbelp1;
- errfindbegin: retbit=0;
- okfindbegin:return retbit;
- }
- bit rdemdata(void)
- {
- bit retbit;
- uchar i;
- uchar j;
- uchar parity;
- uchar emcheck;
- emcheck=0;
- retbit=1;
- if (findbegin()==0)
- {
- goto errrdem;
- }
- for (j=0;j<=4;j++)
- {
- parity=0;
- for (i=1;i<=4;i++)
- {
- if (readbit()==0)
- {
- goto errrdem;
- }
- emdata[j]=emdata[j]<<1;
- if (OLDEM==0)
- {
- emdata[j]=emdata[j] | 1;
- parity++;
- }
- }
- if (readbit()==0)
- {
- goto errrdem;
- }
- if (OLDEM==0)
- {
- parity++;
- }
- if ((parity & 1)==1)
- {
- goto errrdem;
- }
- parity=0;
- for (i=1;i<=4;i++)
- {
- if (readbit()==0)
- {
- goto errrdem;
- }
- emdata[j]=emdata[j]<<1;
- if (OLDEM==0)
- {
- emdata[j]=emdata[j] | 1;
- parity++;
- }
- }
- if (readbit()==0)
- {
- goto errrdem;
- }
- if (OLDEM==0)
- {
- parity++;
- }
- if ((parity&1)==1)
- {
- goto errrdem;
- }
- }
- for (i=1;i<=5;i++)
- {
- if (readbit()==0)
- {
- goto errrdem;
- }
- emcheck=emcheck<<1;
- if (OLDEM==0)
- {
- emcheck=emcheck | 1;
- }
- }
- if ((emcheck&1)==1)
- {
- goto errrdem;
- }
- emcheck=emcheck<<3;
- for (j=0;j<=3;j++)
- {
- parity=0;
- for (i=0;i<=4;i++)
- {
- if (((emdata[i]<<j) & 0x80)==0x80)
- {
- parity++;
- }
- if (((emdata[i]<<j) & 0x8)==0x8)
- {
- parity++;
- }
- }
- if (((emcheck<<j) & 0x80)==0x80)
- {
- parity++;
- }
- if ((parity%2)==1)
- {
- goto errrdem;
- }
- }
- goto okrdemdata;
- errrdem:retbit=0;
- okrdemdata:return retbit;
- }