打印

求助:各位大哥,请帮我看看这个奇怪的问题,谢谢!

[复制链接]
1561|2
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
星星电灯|  楼主 | 2008-2-20 09:41 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
#include <REG52.H>

#include <string.h>
#include <stdio.h>
#include <absacc.h>
#include <intrins.h>

#include <SLE4442.h>

sbit SPK        =    P3^4;        //蜂鸣器
sbit LED        =    P3^5;        //指示灯

void delay_ms(unsigned int ms)
{
    unsigned char i;
    while(ms--)
    {
        i=112;
        while(i--);
    }

}

void printchar(unsigned char ch)
{
    if(ch>=0&&ch<=9) ch=ch+'0';
    else if(ch>=10&&ch<=15) ch=ch+'A'-10;
    putchar(ch);
}

void printhex(unsigned char hex)//以十六进制格式输出1个字节
{
    unsigned char c;
    c=hex;
    c=c>>4;
    printchar(c);
    c=hex;
    c=c&0x0F;
    printchar(c);
}

void init(void)
{
    LED=0;
    SPK=0;

    TMOD=0x21;
    TH1=0xFD;
    SCON=0x50;
    PCON=0x00;
    TR1=1;
    TI=1;
    //EA=1;

    CARD_IN=1;
    printf("程序开始运行...\n");

    delay_ms(300);
    LED=1;
    SPK=1;
}


void ComInStr() interrupt 4 //串行口中断
{
    /*
   if(RI)
     {
          if (ReceiveCount > 4)   //从电脑接收 3 个字符
           {
                    ReceiveCount = 0;        
             }
         ReceiveBuf[ReceiveCount] = SBUF; //用来接收电脑发过来的字符
           ReceiveCount++;                  //串口接收的字符个数
         if (ReceiveCount > 4)
               {
                ReceiveFlag = 1; //接收标志置位 表示是否接收完了
              }
         RI=0;
     }//if(RI)
     */
}


main()
{
    unsigned char i;
    unsigned int p;
    unsigned char buff[16];
    unsigned char pwd[3];

    init();

    for(;;)
    {
        while(CARD_IN);            //等待插入IC卡
        delay_ms(5);            //防抖动
        if(CARD_IN) continue;

    //-----------------------------IC 卡已经插入------------------------------------
        LED=0;                    //打开绿灯
        SPK=0;
        printf("IC卡已插入\n");

        delay_ms(100);
        SPK=1;
        delay_ms(30);

        ResetCard();
        printf("IC卡数据:\n");
        p=0;
        while((!CARD_IN)&&(p<256))
        {
            //读16字节
            ReadMainMem(p,buff,16);  //读IC卡主存
            BreakOperate();
            Delay10us();
            printhex(p);
            printf(": ");
            for(i = 0;i <= 15; i++)
                printhex(buff);
                /*
                {
                    SBUF = '1';
              while(!TI);
              TI=0;    
            }
            */
            printf("\n");
            p+=16;
        }
        
        printf("保护寄存器: "); //读保护存储器
        ReadProtectMem(buff);
        for(i = 0;i < 5; i++)
            printhex(buff);
        printf("\n");

        //检查密码寄存器
        printf("密码寄存器: ");
        ReadPwd(buff);     //读密码存储器
        for(i = 0;i < 4; i++)
            printhex(buff);
         printf("\n");

        //if((buff[0] & 0x07) == 0x07)        //密码计数,防止3次校验错误密码导致锁卡
        //{
            //出厂默认密码
            //pwd[0]=0xFF;
            //pwd[1]=0xFF;
            //pwd[2]=0xFF;
        if((buff[0] & 0x07) == 0x07)
      {
        pwd[0]=0x12;
          pwd[1]=0x34;
          pwd[2]=0x56;

            if(Verify(pwd))        //校对密码
            {
                printf("校对密码正确\n");

                //写0x30开始的16个字节
                for(i=0x30;i<0x40;i++)            
                {
                    buff[0]=i;
                    WriteMainMem(i,buff);        //写一字节
                }
                printf("写数据成功\n");
                buff[0]=0x12;
                buff[1]=0x34;
                buff[2]=0x56;
                ChangePwd(buff);
                printf("密码已修改为:0x123456\n");
            }
            else
            {
                printf("校对密码出错\n");
            }
        }
        else
        {
                printf("密码计数器不是 111\n");
        }

        if(!CARD_IN)
            ResetCard();


        while(!CARD_IN);        //等待拨出IC卡
        //-----------------------------IC 卡已经插入------------------------------------
        
        
        //-----------------------------IC 卡退出----------------------------------------
        LED=1;                    //关闭绿灯
        printf("IC卡已退出\n");
        delay_ms(30);
        //-----------------------------IC 卡退出----------------------------------------
    }
}


则打印的信息:

IC卡已插入
IC卡数据
00: A2131091FFFF8115FFFFFFFFFFFFFFFF
10: FFFFFFFFFFD27600000400FFFFFFFFFF
20: FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
30: 303132333435363738393A3B3C3D3E3F
40: FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
50: FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
60: FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
70: FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
80: FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
90: FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
A0: FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
B0: FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
C0: FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
D0: FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
E0: FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
F0: FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
保护寄存器: FFFFFFFFFF
密码寄存器: 07000000
校对密码正确
写示成功
密码已修改为:0x123456



如果:
while((!CARD_IN)&&(p<256))
        {
            //读16字节
            ReadMainMem(p,buff,16);  //读IC卡主存
            BreakOperate();
            Delay10us();
            printhex(p);
            printf(": ");
            for(i = 0;i <= 15; i++)
                //printhex(buff);
                
                {
                    SBUF = '1';
              while(!TI);
              TI=0;    
            }
            
            printf("\n");
            p+=16;
        }
        
        

则打印的是:
IC卡已插入
IC数据
00:1111111111111111

为什么不能打印 256 个 1

为什么
p 都不下移了呢?

谢谢!

相关帖子

沙发
星星电灯|  楼主 | 2008-2-20 14:04 | 只看该作者

各位大哥,帮我看看啊,谢谢!

各位大哥,帮我看看啊,谢谢!

使用特权

评论回复
板凳
ayb_ice| | 2008-2-20 14:14 | 只看该作者

太长了。。。

使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

74

主题

121

帖子

1

粉丝