找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 910|回复: 2
打印 上一主题 下一主题
收起左侧

请问一下这个单片机程序的初始密码是多少,从哪个地方可以找出初始密码。

[复制链接]
跳转到指定楼层
楼主
ID:701114 发表于 2020-3-6 17:33 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
  1. #include<reg52.h>
  2. #define uint  unsigned int
  3. #define uchar unsigned char


  4. extern uchar keyscan();             //扫描按键                                 
  5. extern void write_c(uchar command); //lcd写命令                          
  6. extern void write_d(uchar date);    //lcd写数据                                 
  7. extern void Lcd_init();                    //lcd初始化
  8. extern void setposition(uchar x,uchar y)        ;
  9. extern void writebyte(uchar x,uchar y,uchar dat);                              
  10. extern void writenbyte(uchar x,uchar y,uchar *p);
  11. extern void WriteSet(uchar add, uchar dat);  //数据写入24c08的具体地址         
  12. extern unsigned char ReadSet(uchar set_addr); //从24c08的具体地址读出数据                                               
  13. sbit beep=P2^0;                                                                         //蜂鸣器         
  14. sbit  led=P3^0;                                                                       
  15. bit  takmo,right,set,input,flag;
  16. uchar i,j,use,temp,m,money,b,c;


  17. uchar code wel1[]={" welcome to the"};
  18. uchar code wel2[]={"ATM system"};
  19. uchar code new[]={"input new keys:"};
  20. uchar code yu_e[]={"   yu e is: "};


  21. uchar code note1[]={"Input your key"};
  22. uchar code note2[]={"key:"};
  23. uchar code note3[]={"set:"};
  24. uchar code note4[]={"your key is   "};
  25. uchar code note5[]={"  what can I   "};
  26. uchar code note6[]={"   do for you   "};
  27. uchar code note7[]={"  check the key "};
  28. uchar code note8[]={"and try it again"};
  29. uchar code note9[]={"thanks  use"};
  30. uchar code note10[]={" goodbye"};
  31. uchar code note11[]={"how much do you"};
  32. uchar code note12[]={"need:"};
  33. uchar code note13[]={"   not enough"};
  34. uchar code note14[]={"    processing "};
  35. uchar code note15[]={"  please wait...  "};
  36. uchar code note16[]={" your money is"};
  37. uchar code note17[]={"remember new key"};
  38. uchar code right0[]={" right!"};
  39. uchar code error0[]={" wrong!"};
  40. uchar code setname[]={"    set ok!"};
  41. uchar code setname1[]={"  set error!"};


  42. /******************************************************************
  43. 延时函数
  44. **********************************************************************/      
  45.                                                                                                                                                                                          
  46. void delay(uint x)
  47. {
  48.         uint y;
  49.         for(;x!=0;x--)
  50.                 for(y=110;y!=0;y--);
  51. }
  52. void delay0(uchar x)                             
  53. {  uchar i;
  54.    while(x--)
  55.    {for (i = 0; i<13; i++);}
  56. }
  57. /******************************************************************
  58. 声音函数
  59. **********************************************************************/
  60. void beepon()                                
  61. {  uchar i;
  62.   for (i=0;i<180;i++)
  63.   {delay0(5);
  64.    beep=!beep;                     
  65.   }
  66.    beep=1;                     
  67.    delay(20);                  
  68. }
  69. /*******************************************************************
  70. 灯闪,代表操作成功
  71. ********************************************************************/
  72. void  light()
  73. { uchar n;
  74.    for(n=0;n<=2;n++)
  75.    {
  76.    led=0;
  77.    delay(1000);
  78.    led=1;
  79.    delay(1000);
  80.    }
  81. }
  82. /******************************************************************
  83. 显示余额函数
  84. **********************************************************************/
  85. showmoney()
  86. {        if(money>use)
  87.    {
  88.     money-=use;
  89.         use=0;
  90.     write_c(0x01);
  91.     writenbyte(0,0,note14);
  92.         writenbyte(1,0,note15);
  93.         delay(5000);
  94.     write_c(0x01);
  95.     writenbyte(0,0,yu_e);
  96.     setposition(1,0);
  97.         write_d(money+0x30);
  98.     write_d(0+0x30);
  99.         write_d(0+0x30);
  100.         WriteSet(6,money);
  101.         light();


  102.         }
  103.         else
  104.         {
  105.           write_c(0x01);
  106.           write_c(0x0c);
  107.       writenbyte(0,0,note16);
  108.           writenbyte(1,0,note13);
  109.         }
  110. }
  111. /*********************************************************************
  112. 比较函数:用来确定密码正误
  113. *********************************************************************/
  114. bit check(uchar p[],uchar q[])
  115. {  uchar n,k=0;      
  116.    for(n=0;n<6;n++)
  117.    {  if(p[n]==q[n])
  118.        k++;}
  119.    if(k==6)
  120.    return 1;
  121.    else return 0;
  122. }
  123. /*******************************************************************
  124. 初始化函数
  125. ******************************************************************/
  126.   void  init()
  127. {         
  128.            takmo=0;right=0;set=0;input=1;flag=0;        
  129.                Lcd_init();
  130.                setposition(0,0);
  131.             for(i=0;wel1!='\0';i++)          //开机界面
  132.              {
  133.                  write_d(wel1);
  134.                  beepon();
  135.                  }         
  136.            setposition(1,3);
  137.             for(i=0;wel2!='\0';i++)
  138.              {write_d(wel2);
  139.                   beepon();
  140.                  }
  141.         delay(2000);                                                  
  142.                 write_c(0x01);                                 


  143.            writenbyte(0,1,note1);  //提示输入密码
  144.            writenbyte(1,0,note2);  //显示key
  145.            write_c(0x0f);               //光标闪烁
  146.            setposition(1,4);           //第二行第五个位置开始键入密码
  147.        i=0;     
  148. }


  149. /*********************************************************************  
  150. 主函数:确定不同按键组合功能
  151. ***********************************************************************/
  152. void main()
  153. {        
  154.     uchar key_buff[6];                 //输入缓冲
  155.     uchar new_key[6] ;                 //密码设置缓冲区
  156.     uchar original_key[6];                   //密码读出缓冲区
  157.         WriteSet(6,9);                    
  158.         init();
  159.     while(1)
  160.         {             for(b=0;b<6;b++)      //24c08里面取出正确的密码                                                  
  161.                {
  162.                  original_key=ReadSet(b);
  163.                  delay(5);
  164.                }
  165.         temp=keyscan();         //扫描键盘                                                   
  166.            if(temp>=0&&temp<=9)
  167.                   {   beepon();
  168.                  if(input)
  169.                   {
  170.                    key_buff[i++]=temp;
  171.                    write_d('*');
  172.                   }
  173.                  else if(set)
  174.                   {
  175.                    new_key[i++]=temp;
  176.                    write_d('*');
  177.                   }
  178.                  else if(takmo)
  179.                   {
  180.                                    i++;
  181.                    write_d(temp+0x30);
  182.                    use=10*use+temp;
  183.                   }
  184.                                  else{;}   
  185.               }
  186.            else if(temp==10)                   //取卡                  
  187.                  {
  188.                              beepon();
  189.                  write_c(0x01);
  190.                                  write_c(0x0c);
  191.                  writenbyte(0,3,note9);
  192.                  writenbyte(1,3,note10);
  193.                  delay(3000);
  194.                  init();
  195.              }
  196.       
  197.         else if(temp==11)                                //取钱
  198.             {      
  199.                  if(right)
  200.                {
  201.                               beepon();
  202.                           takmo=1;
  203.                   write_c(0x01);
  204.                                   write_c(0x0f);
  205.                   writenbyte(0,0,note11);
  206.                   writenbyte(1,0,note12);
  207.                }
  208.                            else{beepon();}
  209.             }
  210.         else if(temp==12)                           //设置新密码
  211.           {                              
  212.                if(right)
  213.                    {beepon();  
  214.               set=1;
  215.                   write_c(0x01);
  216.                           write_c(0x0f);
  217.               writenbyte(0,0,new);
  218.               setposition(1,0);
  219.               }
  220.                            else{beepon();}
  221.           }


  222.            else if(temp==13)
  223.            {
  224.                 if(right)
  225.                {
  226.                              beepon();
  227.                  write_c(0x01);
  228.                                  money=ReadSet(6);        
  229.                  showmoney();           //显示余额
  230.                 }
  231.                                 else{beepon();}
  232.            }  
  233.        else if(temp==14)                                 //确认
  234.            {  
  235.                         beepon();           
  236.                 if(input)
  237.                 {   
  238.                                        if(i!=6)
  239.                                     {   i=0;
  240.                         write_c(0x01);
  241.                                                 write_c(0x0c);
  242.                         writenbyte(0,2,note4);
  243.                         writenbyte(1,4,error0);
  244.                         delay(3000);
  245.                         write_c(0x01);
  246.                         writenbyte(0,0,note7);
  247.                         writenbyte(1,0,note8);
  248.                                             delay(3000);
  249.                                             init();
  250.                                                 ;
  251.                                          }
  252.                                         else
  253.                                         { flag=check(key_buff,original_key);
  254.                                           if(flag==1)
  255.                       {  
  256.                         i=0;
  257.                         right=1;
  258.                         input=0;
  259.                         write_c(0x01);
  260.                                                 write_c(0x0c);
  261.                         writenbyte(0,3,note4);
  262.                         writenbyte(1,4,right0);
  263.                         delay(3000);
  264.                         write_c(0x01);
  265.                         writenbyte(0,1,note5);
  266.                         writenbyte(1,0,note6);
  267.                        }                                       
  268.                      else
  269.                       {      
  270.                         i=0;
  271.                         write_c(0x01);
  272.                                                 write_c(0x0c);
  273.                         writenbyte(0,2,note4);
  274.                         writenbyte(1,4,error0);
  275.                         delay(3000);
  276.                         write_c(0x01);
  277.                         writenbyte(0,0,note7);
  278.                         writenbyte(1,0,note8);
  279.                                             delay(3000);
  280.                                             init();
  281.                                                 ;
  282.                       }
  283.                                          }
  284.                                }               
  285.                   
  286.                  else if(set)
  287.                      {  if(i==6)
  288.                                            {
  289.                          set=0;
  290.                          write_c(0x01);
  291.                                                  write_c(0x0c);
  292.                          writenbyte(0,0,setname);
  293.                                                  writenbyte(1,0,note17);
  294.                                   for(c=0;c<6;c++)
  295.                          {
  296.                            WriteSet(c,new_key[c]);
  297.                            delay(100);  
  298.                           }
  299.                             c=0;
  300.                                                 }
  301.                                                 else
  302.                                                 {
  303.                                                    set=0;
  304.                                                    i=0;
  305.                                                    write_c(0x01);
  306.                                                    write_c(0x0c);
  307.                            writenbyte(0,0,setname1);
  308.                                                  }
  309.                      }
  310.                 else if(takmo)
  311.                      {  
  312.                                             money=ReadSet(6);
  313.                         takmo=0;
  314.                         showmoney();      
  315.                      }
  316.                 else
  317.                   {beepon();}
  318.              }                           
  319.            else  if(temp==15)                                   //清除
  320.               {
  321.                                beepon();   
  322.                    if(input&&i>=1)
  323.                     {
  324.                                             writebyte(1,4+(--i),' ');
  325.                                                 setposition(1,4+i);
  326.                                         }
  327.                    else if(set&&i>=1)
  328.                     {
  329.                                             writebyte(1,0+(--i),' ');
  330.                                                 setposition(1,0+i);
  331.                                         }
  332.                    else if(takmo&&i>=1)
  333.                     {
  334.                                             writebyte(1,5+(--i),' ');
  335.                                             setposition(1,5+i);
  336.                                         }
  337.                    else
  338.                     {;}           
  339.               }
  340.           else {;}         
  341.     }
  342. }


  343.    #include<reg52.h>
  344. #define uint unsigned int
  345. #define uchar unsigned char
  346. void delayms(uint z)
  347. {
  348.         uint x,y;
  349.         for(x=z;x>0;x--)
  350.                 for(y=110;y>0;y--);
  351. }








  352. /*********************************************************************  
  353. * 函 数 名: keyscan
  354. * 功能描述: 键盘扫描返回值
  355. ***********************************************************************/


  356. uchar keyscan()
  357. {     uchar num=16,temp;
  358.                         P1=0xfe;
  359.                         temp=P1;
  360.                         temp=temp&0xf0;
  361.                         while(temp!=0xf0)
  362.                                 {
  363.                                         delayms(5);
  364.                                         temp=P1;
  365.                                         temp=temp&0xf0;
  366.                                         while(temp!=0xf0)
  367.                                         {
  368.                                                 temp=P1;
  369.                                         switch(temp)
  370.                                                 {
  371.                                                         case 0xee:num=0;
  372.                                                                 break;
  373.                                                         case 0xde:num=1;
  374.                                                                 break;
  375.                                                         case 0xbe:num=2;
  376.                                                                 break;
  377.                                                         case 0x7e:num=3;
  378.                                                                 break;
  379.                                                 }
  380.                                         while(temp!=0xf0)
  381.                                                 {
  382.                                                         temp=P1;
  383.                                                         temp=temp&0xf0;
  384.                                                 }
  385.                                         }
  386.                                 }






  387.                         P1=0xfd;
  388.                         temp=P1;
  389.                         temp=temp&0xf0;
  390.                         while(temp!=0xf0)
  391.                                 {
  392.                                         delayms(5);
  393.                                         temp=P1;
  394.                                         temp=temp&0xf0;
  395.                                         while(temp!=0xf0)
  396.                                         {
  397.                                                 temp=P1;
  398.                                         switch(temp)
  399.                                                 {
  400.                                                         case 0xed:num=4;
  401.                                                                 break;
  402.                                                         case 0xdd:num=5;
  403.                                                                 break;
  404.                                                         case 0xbd:num=6;
  405.                                                                 break;
  406.                                                         case 0x7d:num=7;
  407.                                                                 break;
  408.                                                 }
  409.                                         while(temp!=0xf0)
  410.                                                 {
  411.                                                         temp=P1;
  412.                                                         temp=temp&0xf0;
  413.                                                 }
  414.                                         }
  415.                                 }
















  416.                         P1=0xfb;
  417.                         temp=P1;
  418.                         temp=temp&0xf0;
  419.                         while(temp!=0xf0)
  420.                                 {
  421.                                         delayms(5);
  422.                                         temp=P1;
  423.                                         temp=temp&0xf0;
  424.                                         while(temp!=0xf0)
  425.                                         {
  426.                                                 temp=P1;
  427.                                         switch(temp)
  428.                                                 {
  429.                                                         case 0xeb:num=8;
  430.                                                                 break;
  431.                                                         case 0xdb:num=9;
  432.                                                                 break;
  433.                                                         case 0xbb:num=10;
  434.                                                                 break;
  435.                                                         case 0x7b:num=11;
  436.                                                                 break;
  437.                                                 }
  438.                                         while(temp!=0xf0)
  439.                                                 {
  440.                                                         temp=P1;
  441.                                                         temp=temp&0xf0;
  442.                                                 }
  443.                                         }
  444.                                 }




  445.                         P1=0xf7;
  446.                         temp=P1;
  447.                         temp=temp&0xf0;
  448.                         while(temp!=0xf0)
  449.                                 {
  450.                                         delayms(5);
  451.                                         temp=P1;
  452.                                         temp=temp&0xf0;
  453.                                         while(temp!=0xf0)
  454.                                         {
  455.                                                 temp=P1;
  456.                                         switch(temp)
  457.                                                 {
  458.                                                         case 0xe7:num=12;
  459.                                                                 break;
  460.                                                         case 0xd7:num=13;
  461.                                                                 break;
  462.                                                         case 0xb7:num=14;
  463.                                                                 break;
  464.                                                         case 0x77:num=15;
  465.                                                                 break;
  466.                                                 }
  467.                                         while(temp!=0xf0)
  468.                                                 {
  469.                                                         temp=P1;
  470.                                                         temp=temp&0xf0;
  471.                                                 }
  472.                                         }
  473.                                 }
  474. return num;


  475. }
  476. #include<reg52.h>
  477. #define uchar  unsigned char
  478. #define uint   unsigned int


  479. sbit RS=P2^5;
  480. sbit RW=P2^6;
  481. sbit EN=P2^7;


  482. void delaymms()
  483. {
  484.    unsigned char i,j;      
  485.          for(i=0;i<10;i++)
  486.           for(j=0;j<33;j++)
  487.            ;                 
  488. }
  489. void delays(uint n)
  490. {
  491.    uint i;
  492.         for(i=0;i<n;i++)
  493.            delaymms();
  494. }
  495. void write_c( uchar x )
  496. {
  497.    RS=0;
  498.    RW=0;
  499.    EN=0;
  500.    P0=x;
  501.    delays(5);
  502.    EN=1;
  503.    delays(5);
  504.    EN=0;
  505. }
  506. void write_d( uchar x )
  507. {
  508.    RS=1;
  509.    RW=0;
  510.    EN=0;
  511.    P0=x;
  512.    delays(5);
  513.    EN=1;
  514.    delays(5);
  515.    EN=0;   
  516. }

  517.   void setposition(uchar x,uchar y)
  518.   {
  519.      if(x==0)
  520.             write_c( 0x80+y );
  521.          else
  522.             write_c( 0xc0+y );
  523.   }
  524.   void writebyte(uchar x,uchar y,uchar dat)
  525.   {
  526.      setposition( x,y);
  527.              write_d( dat );
  528.    }
  529. void writenbyte(uchar x,uchar y,uchar *p)
  530.    {
  531.       setposition( x,y);
  532.           while(*p)
  533.           {
  534.              write_d( *p++ );
  535.            }
  536.     }
  537. void Lcd_init(void)
  538. {
  539.         write_c( 0x01 );
  540.         write_c( 0x38 );
  541.         write_c( 0x0c );
  542.         write_c( 0x06 );
  543.   }
  544.   #include <reg52.h>        //  包含51单片机寄存器定义的头文件
  545. #include <intrins.h>      //包含_nop_()函数定义的头文件
  546. #define        OP_READ        0xa1                // 器件地址以及读取操作,0xa1即为1010 0001B
  547. #define        OP_WRITE 0xa0                // 器件地址以及写入操作,0xa1即为1010 0000B
  548. sbit SCL=P3^5;         //将串行时钟总线SCL位定义在为P3.4引脚
  549. sbit SDA=P3^6;          //将串行数据总线SDA位定义在为P3.5引脚     
  550. /*****************************************************
  551. 函数功能:延时1ms
  552. ***************************************************/
  553. void delay1ms()
  554. {
  555.    unsigned char i,j;      
  556.          for(i=0;i<10;i++)
  557.           for(j=0;j<33;j++)
  558.            ;                 
  559. }


  560. /*****************************************************
  561. 函数功能:延时若干毫秒
  562. 入口参数:n
  563. ***************************************************/
  564. void delaynms(unsigned char n)
  565. {
  566.    unsigned char i;
  567.         for(i=0;i<n;i++)
  568.            delay1ms();
  569. }
  570. /***************************************************
  571. 函数功能:开始数据传送
  572. ***************************************************/
  573. void start()
  574. // 开始位
  575. {
  576.         SDA = 1;    //SDA初始化为高电平“1”
  577.    SCL = 1;    //开始数据传送时,要求SCL为高电平“1”
  578.         _nop_();     //等待一个机器周期
  579.         _nop_();     //等待一个机器周期
  580.         _nop_();     //等待一个机器周期
  581.         _nop_();     //等待一个机器周期
  582.         _nop_();     //等待一个机器周期
  583.         SDA = 0;    //SDA的下降沿被认为是开始信号
  584.         _nop_();     //等待一个机器周期
  585.         _nop_();     //等待一个机器周期
  586.         _nop_();     //等待一个机器周期
  587.         _nop_();     //等待一个机器周期
  588.         _nop_();     //等待一个机器周期
  589.         SCL = 0;    //SCL为低电平时,SDA上数据才允许变化(即允许以后的数据传递)  
  590. }
  591. /***************************************************
  592. 函数功能:结束数据传送
  593. ***************************************************/
  594. void stop()// 停止位
  595. {
  596.         SDA = 0;     //SDA初始化为低电平“0”        _n
  597.         SCL = 1;     //结束数据传送时,要求SCL为高电平“1”
  598.         _nop_();     //等待一个机器周期
  599.         _nop_();     //等待一个机器周期
  600.         _nop_();     //等待一个机器周期
  601.         _nop_();     //等待一个机器周期
  602.         _nop_();     //等待一个机器周期
  603.         SDA = 1;    //SDA的上升沿被认为是结束信号
  604.         _nop_();     //等待一个机器周期
  605.         _nop_();     //等待一个机器周期
  606.         _nop_();     //等待一个机器周期
  607.         _nop_();     //等待一个机器周期
  608.         _nop_();     //等待一个机器周期
  609.         SDA=0;
  610.         SCL=0;
  611. }
  612. /***************************************************
  613. 函数功能:检测应答位
  614. ***************************************************/


  615. bit Ask()                  //检测应答
  616. {
  617.       bit ack_bit;        //储存应答位
  618.         SDA = 1;         // 发送设备(主机)应在时钟脉冲的高电平期间(SCL=1)释放SDA线,
  619.                         //以让SDA线转由接收设备(AT24Cxx)控制
  620.         _nop_();        //等待一个机器周期
  621.         _nop_();        //等待一个机器周期
  622.         SCL = 1;       //根据上述规定,SCL应为高电平
  623.         _nop_();       //等待一个机器周期
  624.         _nop_();       //等待一个机器周期
  625.         _nop_();       //等待一个机器周期
  626.         _nop_();       //等待一个机器周期
  627.         _nop_();       //等待一个机器周期  
  628.         ack_bit = SDA; //接受设备(AT24Cxx)向SDA送低电平,表示已经接收到一个字节
  629.                        //若送高电平,表示没有接收到,传送异常 结束发送
  630.         SCL = 0;       //SCL为低电平时,SDA上数据才允许变化(即允许以后的数据传递)
  631.         return  ack_bit;                        // 返回AT24Cxx应答位






  632. }
  633. /***************************************************
  634. 函数功能:从AT24Cxx读取数据
  635. 出口参数:x
  636. ***************************************************/
  637. unsigned char ReadData()
  638. // 从AT24Cxx移入数据到MCU
  639. {
  640.         unsigned char i;
  641.         unsigned char x;   //储存从AT24Cxx中读出的数据
  642.         for(i = 0; i < 8; i++)
  643.         {
  644.                 SCL = 1;                //SCL置为高电平
  645.                 x<<=1;                  //将x中的各二进位向左移一位
  646.                 x|=(unsigned char)SDA;  //将SDA上的数据通过按位“或“运算存入x中
  647.                 SCL = 0;                        //在SCL的下降沿读出数据
  648.         }
  649.         return(x);                //将读取的数据返回
  650. }
  651. /***************************************************
  652. 函数功能:向AT24Cxx的当前地址写入数据
  653. 入口参数:y (储存待写入的数据)
  654. ***************************************************/
  655. //在调用此数据写入函数前需首先调用开始函数start(),所以SCL=0
  656. void WriteCurrent(unsigned char y)
  657. {
  658.         unsigned char i;
  659.         for(i = 0; i < 8; i++)                // 循环移入8个位
  660.         {
  661.             SDA = (bit)(y&0x80);   //通过按位“与”运算将最高位数据送到S
  662.                                                   //因为传送时高位在前,低位在后
  663.                 _nop_();            //等待一个机器周期   
  664.            SCL = 1;            //在SCL的上升沿将数据写入AT24Cxx      
  665.            _nop_();            //等待一个机器周期
  666.           _nop_();             //等待一个机器周期      
  667.                
  668.                   SCL = 0;            //将SCL重新置为低电平,以在SCL线形成传送数据所需的8个脉冲
  669.                 y <<= 1;           //将y中的各二进位向左移一位
  670.                
  671.         }
  672. }
  673. /***************************************************
  674. 函数功能:向AT24Cxx中的指定地址写入数据
  675. 入口参数:add (储存指定的地址);dat(储存待写入的数据)
  676. ***************************************************/
  677. void WriteSet(unsigned char add, unsigned char dat)
  678. // 在指定地址addr处写入数据WriteCurrent
  679. {
  680.         start();               //开始数据传递
  681.         WriteCurrent(OP_WRITE);  //选择要操作的AT24Cxx芯片,并告知要对   其写入数据
  682.          Ask();
  683.         WriteCurrent(add);       //写入指定地址
  684.         Ask();
  685.         WriteCurrent(dat);       //向当前地址(上面指定的地址)写入数据
  686.         Ask();
  687.         stop();                //停止数据传递
  688.         delaynms(5);               //1个字节的写入周期为1ms, 最好延时1ms以上
  689. }
  690. /***************************************************
  691. 函数功能:从AT24Cxx中的当前地址读取数据
  692. 出口参数:x (储存读出的数据)
  693. ***************************************************/
  694. unsigned char ReadCurrent()
  695. {
  696.         unsigned char x;
  697.         start();               //开始数据传递
  698.         WriteCurrent(OP_READ);   //选择要操作的AT24Cxx芯片,并告知要读其数据
  699.         Ask();
  700.         x=ReadData();         //将读取的数据存入x
  701.         stop();                //停止数据传递
  702.         return x;              //返回读取的数据
  703. }
  704. /***************************************************
  705. 函数功能:从AT24Cxx中的指定地址读取数据
  706. 入口参数:set_addr
  707. 出口参数:x
  708. ***************************************************/
  709. unsigned char ReadSet(unsigned char set_addr)
  710. // 在指定地址读取
  711. {
  712.         start();                      //开始数据传递
  713.         WriteCurrent(OP_WRITE);       //选择要操作的AT24Cxx芯片,并告知要对其写入数据
  714.         Ask();
  715.         WriteCurrent(set_addr);       //写入指定地址
  716.         Ask();
  717.         return(ReadCurrent());        //从指定地址读出数据并返回
  718. }
复制代码

分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏1 分享淘帖 顶 踩
回复

使用道具 举报

沙发
ID:648281 发表于 2020-3-6 22:15 | 只看该作者
你好!初始密码保存在 24C08 存储器里面
回复

使用道具 举报

板凳
ID:235200 发表于 2020-3-7 01:55 | 只看该作者
这已经告诉了你密码
for(b=0;b<6;b++)      //24c08里面取出正确的密码                                                  
   {
       original_key=ReadSet(b);
        delay(5);
     }
读出放在uchar original_key[6]; 这个数组中(程序中未用数组估计不对),新存储器读出结果是FFFFFFFFFFFF
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

手机版|小黑屋|51黑电子论坛 |51黑电子论坛6群 QQ 管理员QQ:125739409;技术交流QQ群281945664

Powered by 单片机教程网

快速回复 返回顶部 返回列表