求51单片机写读卡器的源码
答案:1 悬赏:80 手机版
解决时间 2021-03-24 21:55
- 提问者网友:呐年旧曙光
- 2021-03-24 07:23
求51单片机写读卡器的源码
最佳答案
- 五星知识达人网友:患得患失的劫
- 2021-03-24 08:37
这类程序很多的,给你一个作为参考吧:
#include〈reg51.h〉
#include
#define ucharunsigned char
#define uint unsignedint
sbit scl=P1^7;
sbit sda=P1^6;
sbit ICOUT=P3^2;
sbit ICIN=P3^3;
sbit COMM=P3^4;
sbit BELL=P3^5;
sbit PWR=P1^4;
sbit BAUD=P1^2;
sbit a0=ACC^0;
sbit a1=ACC^1;
sbit a2=ACC^2;
sbit a3=ACC^3;
sbit a4=ACC^4;
sbit a5=ACC^5;
sbit a6=ACC^6;
sbit a7=ACC^7;
uchar buf[16];
uchar flag;
sbitIC-WR=flag^0;
sbit ONCOMM=flag^1;
sbit RST=flag^2;
void start-ic(void)
{
sda=1;
scl=1;
delay(2);
sda=0;
delay(6);
scl=0;
delay(6);
}
voidstop-ic(void)
{
sda=0;
scl=1;
delay(6);
sda=1;
delay(6);
scl=0;
sda=0;
}
voidack-ic(void)
{
sda=0;
delay(3);
scl=1;
delay(3);
scl=0;
sda=1;
}
unsignedchar rd24(void)
{
sda=1;
scl=1;a7=sda;scl=0;
scl=1;a6=sda;scl=0;
scl=1;a5=sda;scl=0;
scl=1;a4=sda;scl=0;
scl=1;a3=sda;scl=0;
scl=1;a2=sda;scl=0;
scl=1;a1=sda;scl=0;
scl=1;a0=sda;scl=0;
sda=1;scl=1;sci=0;
return(ACC);
}
Voidwd24(unsigned char dd)
{
ACC=dd;
sda=a7;scl=1;scl=0;
sda=a6;scl=1;scl=0;
sda=a5;scl=1;scl=0;
sda=a4;scl=1;scl=0;
sda=a3;scl=1;scl=0;
sda=a2;scl=1;scl=0;
sda=a1;scl=1;scl=0;
sda=a0;scl=1;scl=0;
sda=1;scl=1;
while(sda= =1);
SCL=0;
}
{
unchar x;
start-oc();
wd24(0a0);
wd24(address);
start-ic();
wd24(0a1);
x=rd24();
stop-ic();
return(x);
}
Ucharread-bytes(uchar address,uchar n)
{
uchar a,y;
for(y=0;y {
A=read-buter(address+y);
Buf[y]=a;
}
}
voidwrire-byte(uchar address,uchar dd)
{
Start-ic();
Wd24(0a0);
Wd24(address);
Wd24(dd);
Stop-ic();
}
Void comm(ucharx,uchar y)
{
uchar i,a;
uint j;
while(1)
{l1: while(RI==0);
RI=0;
a=SBUF;
if(a!=y)goto l1;
for(i=0;i { SBUF=trdata[i];
While(T1= =0);
TI=0;
}
For(j=0;j<12500;j++);
}
}
voidinit(void)
{
RST=0;
PWR=1;
IC-WR=0;
ONCOMM=0;
EX0=1;
TMOD=0x20;
SCON=0x50;
TH1=0xf3;TL1=0xf3;
If(BAUD= =0)
{
PCON=0x80;
}
else
{
PCON=0x00;
}
TR1=1;
EA=1;
}
voidtransfer(void)
{
uchar I;
uint j;
for(i=0;i<16;i++)
{ SBUF=buf[i];
WHILE(TI= =0);
TI=0;
for(j=0;j<1000;j++);
}
}
voidreceive(void)
{
uchar i,a;
for(i=0;i<16;i++)
{ while(RI==0);
RI=0;
a=SBUF;
buf[i]=a;
}
}
Voidreceive(void)
{
uchar x,y;
for(y=0;y {
Writ-byte(address+y,buf[y]);
delay(10);
}
}
voidint-0(void)interrupt 0 using 1
{
while(! ICOUT);
delay(10);
if(! ICOUT)
{
If(IC-WR|ONCOMM)
{
PWR=1;
BELL=0;
delay(10);
BELL=1;
RST=1;
}
}
}
voiddelay(uchar n)
{
uchar i,j,k;
for(k=0;k for(i=0;i〈100;i++〉
for(j=0;j<255;j++);
}
Void main(void)
{
uchar a;
fuwei: init();
while(! ICIN);
delay(10);
while(! ICIN);
IC-wr=1;
PWR=0;
read-bytes(0,16);
PWR=1;
ONCOMM=1;
While(RI= =0);
RI=0;
a=SBUF;
switch(a)
{
case 0xaa: SBUF=0xaa;
while(! TI);
TI=0;
transfer();
break;
case 0xbb: SBUF=0xbb;
while(! TI);
TI=0;
receive();
PWR=0;
write-ic(0,16);
PWR=1;
Break;
Default: SBUF=0xcc;
While(! TI);
TI=0;
}
ONCOMM=0;
while(! RST);
goto fuwei;
}
#include〈reg51.h〉
#include
#define ucharunsigned char
#define uint unsignedint
sbit scl=P1^7;
sbit sda=P1^6;
sbit ICOUT=P3^2;
sbit ICIN=P3^3;
sbit COMM=P3^4;
sbit BELL=P3^5;
sbit PWR=P1^4;
sbit BAUD=P1^2;
sbit a0=ACC^0;
sbit a1=ACC^1;
sbit a2=ACC^2;
sbit a3=ACC^3;
sbit a4=ACC^4;
sbit a5=ACC^5;
sbit a6=ACC^6;
sbit a7=ACC^7;
uchar buf[16];
uchar flag;
sbitIC-WR=flag^0;
sbit ONCOMM=flag^1;
sbit RST=flag^2;
void start-ic(void)
{
sda=1;
scl=1;
delay(2);
sda=0;
delay(6);
scl=0;
delay(6);
}
voidstop-ic(void)
{
sda=0;
scl=1;
delay(6);
sda=1;
delay(6);
scl=0;
sda=0;
}
voidack-ic(void)
{
sda=0;
delay(3);
scl=1;
delay(3);
scl=0;
sda=1;
}
unsignedchar rd24(void)
{
sda=1;
scl=1;a7=sda;scl=0;
scl=1;a6=sda;scl=0;
scl=1;a5=sda;scl=0;
scl=1;a4=sda;scl=0;
scl=1;a3=sda;scl=0;
scl=1;a2=sda;scl=0;
scl=1;a1=sda;scl=0;
scl=1;a0=sda;scl=0;
sda=1;scl=1;sci=0;
return(ACC);
}
Voidwd24(unsigned char dd)
{
ACC=dd;
sda=a7;scl=1;scl=0;
sda=a6;scl=1;scl=0;
sda=a5;scl=1;scl=0;
sda=a4;scl=1;scl=0;
sda=a3;scl=1;scl=0;
sda=a2;scl=1;scl=0;
sda=a1;scl=1;scl=0;
sda=a0;scl=1;scl=0;
sda=1;scl=1;
while(sda= =1);
SCL=0;
}
{
unchar x;
start-oc();
wd24(0a0);
wd24(address);
start-ic();
wd24(0a1);
x=rd24();
stop-ic();
return(x);
}
Ucharread-bytes(uchar address,uchar n)
{
uchar a,y;
for(y=0;y
A=read-buter(address+y);
Buf[y]=a;
}
}
voidwrire-byte(uchar address,uchar dd)
{
Start-ic();
Wd24(0a0);
Wd24(address);
Wd24(dd);
Stop-ic();
}
Void comm(ucharx,uchar y)
{
uchar i,a;
uint j;
while(1)
{l1: while(RI==0);
RI=0;
a=SBUF;
if(a!=y)goto l1;
for(i=0;i
While(T1= =0);
TI=0;
}
For(j=0;j<12500;j++);
}
}
voidinit(void)
{
RST=0;
PWR=1;
IC-WR=0;
ONCOMM=0;
EX0=1;
TMOD=0x20;
SCON=0x50;
TH1=0xf3;TL1=0xf3;
If(BAUD= =0)
{
PCON=0x80;
}
else
{
PCON=0x00;
}
TR1=1;
EA=1;
}
voidtransfer(void)
{
uchar I;
uint j;
for(i=0;i<16;i++)
{ SBUF=buf[i];
WHILE(TI= =0);
TI=0;
for(j=0;j<1000;j++);
}
}
voidreceive(void)
{
uchar i,a;
for(i=0;i<16;i++)
{ while(RI==0);
RI=0;
a=SBUF;
buf[i]=a;
}
}
Voidreceive(void)
{
uchar x,y;
for(y=0;y
Writ-byte(address+y,buf[y]);
delay(10);
}
}
voidint-0(void)interrupt 0 using 1
{
while(! ICOUT);
delay(10);
if(! ICOUT)
{
If(IC-WR|ONCOMM)
{
PWR=1;
BELL=0;
delay(10);
BELL=1;
RST=1;
}
}
}
voiddelay(uchar n)
{
uchar i,j,k;
for(k=0;k
for(j=0;j<255;j++);
}
Void main(void)
{
uchar a;
fuwei: init();
while(! ICIN);
delay(10);
while(! ICIN);
IC-wr=1;
PWR=0;
read-bytes(0,16);
PWR=1;
ONCOMM=1;
While(RI= =0);
RI=0;
a=SBUF;
switch(a)
{
case 0xaa: SBUF=0xaa;
while(! TI);
TI=0;
transfer();
break;
case 0xbb: SBUF=0xbb;
while(! TI);
TI=0;
receive();
PWR=0;
write-ic(0,16);
PWR=1;
Break;
Default: SBUF=0xcc;
While(! TI);
TI=0;
}
ONCOMM=0;
while(! RST);
goto fuwei;
}
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯