K
king_213
Unregistered / Unconfirmed
GUEST, unregistred user!
如何将下面的函数转换为delphi函数 就这点分了 不好意思
#include "stdio.h"
#include "reg51.h"
#define DO P10
#define INT P32
#define BUSY P11
#define DI P12
#define CLK P13
#define CS P33
#define SGIN 0x02
#define DR0 0x04
#define DR1 0x00
#define CSEL 0x40
#define CDIS 0x00
void delay(void);
void RUN(void);
void ReadMsg(void);
void WriteReg(unsigned char,unsigned char);
unsigned char Msg[20],buffer[20],remained;
unsigned long int ID = 1513050;
main()
{
unsigned int dly;
unsigned char ch,cn;
SCON = 0x50;
TMOD |= 0x20;
TH1 = 0xfd;
TR1 = 1;
TI = 1;
puts("POSAG decode Program V1.0."
WriteReg(0x1a,CDIS + CSEL + DR1 + DR0 + SGIN);
for(dly=0;dly<500;dly++);
remained = (unsigned char) (ID % 8);
ID = ID / 8;
ch = (unsigned char)(ID&0xff);
WriteReg(0x00,ch);
for(dly=0;dly<500;dly++);
ch = (unsigned char) ((ID>>8) & 0xff);
WriteReg(0x01,ch);
for(dly=0;dly<500;dly++);
ch = (unsigned char) ((ID>>16) & 0xff);
WriteReg(0x02,ch);
for(dly=0;dly<500;dly++);
ch = (unsigned char)(remained<<3);
WriteReg(0x18,ch);
for(dly=0;dly<500;dly++);
RUN();
while(1) {
while(P32);
for(cn=0;cn<20;cn++) Msg[cn] = 0;
putch('#');
ReadMsg();
}
}
void delay(void) {
unsigned int cn;
for(cn=0;cn<5;cn++);
}
void WriteReg(unsigned char i,unsigned char j) {
unsigned char cn,ch;
while(!BUSY);
CS = 0;
ch = 0x20 + i;
for(cn=0;cn<8;cn++) {
if(ch&0x01) DI = 1; else DI = 0;
CLK = 0; delay(); CLK = 1; delay();
ch = ch >> 1;
}
ch = j;
for(cn=0;cn<8;cn++) {
if(ch&0x01) DI = 1; else DI = 0;
CLK = 0; delay(); CLK = 1; delay();
ch = ch >> 1;
}
CS = 1;
}
void RUN(void) {
unsigned char cn;
while(!BUSY);
CS = 0;
for(cn=0;cn<8;cn++) {
DI = 1;
CLK = 0; delay(); CLK = 1; delay();
}
CS = 1;
}
void ReadMsg(void) {
unsigned char cn,ch,s0,s1,sn,d;
while(!BUSY);
CS = 0;
ch = 0x80; s1 = 0; // Read s0
for(cn=0;cn<8;cn++) {
if(ch&0x01) DI = 1; else DI = 0;
CLK = 0; delay(); CLK = 1; delay();
s1 = s1 >> 1;if(DO) s1 |= 0x80; ch = ch >> 1;
}
while(!BUSY);
ch = 0x00; s0 = 0; // Dummy
for(cn=0;cn<8;cn++) {
if(ch&0x01) DI = 1; else DI = 0;
CLK = 0; delay(); CLK = 1; delay();
s0 = s0 >> 1; if(DO) s0 |= 0x80; ch = ch >> 1;
}
if(s0 & 0x06) goto end;
while(!BUSY);
ch = 0xb0; // Read DREG
for(cn=0;cn<8;cn++) {
if(ch&0x01) DI = 1; else DI = 0;
CLK = 0; delay(); CLK = 1; delay();
ch = ch >> 1;
}
sn = 0;
while(1) {
while(!BUSY);
ch = 0x80; d = 0; // Read s0
for(cn=0;cn<8;cn++) {
if(ch&0x01) DI = 1; else DI = 0;
CLK = 0; delay(); CLK = 1; delay();
d = d >> 1; if(DO) d |= 0x80;
ch = ch >> 1;
}
Msg[sn] = d & 0x0f;
while(!BUSY);
ch = 0xb0; s0 = 0; // Read DREG
for(cn=0;cn<8;cn++) {
if(ch&0x01) DI = 1; else DI = 0;
CLK = 0; delay(); CLK = 1; delay();
s0 = s0 >> 1; if(DO) s0 |= 0x80;
ch = ch >> 1;
}
sn++; if(s0 & 0x04) break;
}
end:
CS = 1;
for(cn=0;cn<sn;cn++) { if(Msg[cn]<10) putchar('0'+Msg[cn]); }
puts("/r"
}
#include "stdio.h"
#include "reg51.h"
#define DO P10
#define INT P32
#define BUSY P11
#define DI P12
#define CLK P13
#define CS P33
#define SGIN 0x02
#define DR0 0x04
#define DR1 0x00
#define CSEL 0x40
#define CDIS 0x00
void delay(void);
void RUN(void);
void ReadMsg(void);
void WriteReg(unsigned char,unsigned char);
unsigned char Msg[20],buffer[20],remained;
unsigned long int ID = 1513050;
main()
{
unsigned int dly;
unsigned char ch,cn;
SCON = 0x50;
TMOD |= 0x20;
TH1 = 0xfd;
TR1 = 1;
TI = 1;
puts("POSAG decode Program V1.0."
WriteReg(0x1a,CDIS + CSEL + DR1 + DR0 + SGIN);
for(dly=0;dly<500;dly++);
remained = (unsigned char) (ID % 8);
ID = ID / 8;
ch = (unsigned char)(ID&0xff);
WriteReg(0x00,ch);
for(dly=0;dly<500;dly++);
ch = (unsigned char) ((ID>>8) & 0xff);
WriteReg(0x01,ch);
for(dly=0;dly<500;dly++);
ch = (unsigned char) ((ID>>16) & 0xff);
WriteReg(0x02,ch);
for(dly=0;dly<500;dly++);
ch = (unsigned char)(remained<<3);
WriteReg(0x18,ch);
for(dly=0;dly<500;dly++);
RUN();
while(1) {
while(P32);
for(cn=0;cn<20;cn++) Msg[cn] = 0;
putch('#');
ReadMsg();
}
}
void delay(void) {
unsigned int cn;
for(cn=0;cn<5;cn++);
}
void WriteReg(unsigned char i,unsigned char j) {
unsigned char cn,ch;
while(!BUSY);
CS = 0;
ch = 0x20 + i;
for(cn=0;cn<8;cn++) {
if(ch&0x01) DI = 1; else DI = 0;
CLK = 0; delay(); CLK = 1; delay();
ch = ch >> 1;
}
ch = j;
for(cn=0;cn<8;cn++) {
if(ch&0x01) DI = 1; else DI = 0;
CLK = 0; delay(); CLK = 1; delay();
ch = ch >> 1;
}
CS = 1;
}
void RUN(void) {
unsigned char cn;
while(!BUSY);
CS = 0;
for(cn=0;cn<8;cn++) {
DI = 1;
CLK = 0; delay(); CLK = 1; delay();
}
CS = 1;
}
void ReadMsg(void) {
unsigned char cn,ch,s0,s1,sn,d;
while(!BUSY);
CS = 0;
ch = 0x80; s1 = 0; // Read s0
for(cn=0;cn<8;cn++) {
if(ch&0x01) DI = 1; else DI = 0;
CLK = 0; delay(); CLK = 1; delay();
s1 = s1 >> 1;if(DO) s1 |= 0x80; ch = ch >> 1;
}
while(!BUSY);
ch = 0x00; s0 = 0; // Dummy
for(cn=0;cn<8;cn++) {
if(ch&0x01) DI = 1; else DI = 0;
CLK = 0; delay(); CLK = 1; delay();
s0 = s0 >> 1; if(DO) s0 |= 0x80; ch = ch >> 1;
}
if(s0 & 0x06) goto end;
while(!BUSY);
ch = 0xb0; // Read DREG
for(cn=0;cn<8;cn++) {
if(ch&0x01) DI = 1; else DI = 0;
CLK = 0; delay(); CLK = 1; delay();
ch = ch >> 1;
}
sn = 0;
while(1) {
while(!BUSY);
ch = 0x80; d = 0; // Read s0
for(cn=0;cn<8;cn++) {
if(ch&0x01) DI = 1; else DI = 0;
CLK = 0; delay(); CLK = 1; delay();
d = d >> 1; if(DO) d |= 0x80;
ch = ch >> 1;
}
Msg[sn] = d & 0x0f;
while(!BUSY);
ch = 0xb0; s0 = 0; // Read DREG
for(cn=0;cn<8;cn++) {
if(ch&0x01) DI = 1; else DI = 0;
CLK = 0; delay(); CLK = 1; delay();
s0 = s0 >> 1; if(DO) s0 |= 0x80;
ch = ch >> 1;
}
sn++; if(s0 & 0x04) break;
}
end:
CS = 1;
for(cn=0;cn<sn;cn++) { if(Msg[cn]<10) putchar('0'+Msg[cn]); }
puts("/r"
}