久久久久久久999_99精品久久精品一区二区爱城_成人欧美一区二区三区在线播放_国产精品日本一区二区不卡视频_国产午夜视频_欧美精品在线观看免费

 找回密碼
 立即注冊(cè)

QQ登錄

只需一步,快速開(kāi)始

搜索
查看: 1148|回復(fù): 2
打印 上一主題 下一主題
收起左側(cè)

請(qǐng)問(wèn)一下這個(gè)單片機(jī)程序的初始密碼是多少,從哪個(gè)地方可以找出初始密碼。

[復(fù)制鏈接]
跳轉(zhuǎn)到指定樓層
樓主
ID:701114 發(fā)表于 2020-3-6 17:33 | 只看該作者 回帖獎(jiǎng)勵(lì) |正序?yàn)g覽 |閱讀模式
  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寫數(shù)據(jù)                                 
  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);  //數(shù)據(jù)寫入24c08的具體地址         
  12. extern unsigned char ReadSet(uchar set_addr); //從24c08的具體地址讀出數(shù)據(jù)                                               
  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. 延時(shí)函數(shù)
  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. 聲音函數(shù)
  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. 顯示余額函數(shù)
  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. 比較函數(shù):用來(lái)確定密碼正誤
  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. 初始化函數(shù)
  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++)          //開(kāi)機(jī)界面
  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);               //光標(biāo)閃爍
  146.            setposition(1,4);           //第二行第五個(gè)位置開(kāi)始鍵入密碼
  147.        i=0;     
  148. }


  149. /*********************************************************************  
  150. 主函數(shù):確定不同按鍵組合功能
  151. ***********************************************************************/
  152. void main()
  153. {        
  154.     uchar key_buff[6];                 //輸入緩沖
  155.     uchar new_key[6] ;                 //密碼設(shè)置緩沖區(qū)
  156.     uchar original_key[6];                   //密碼讀出緩沖區(qū)
  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)                           //設(shè)置新密碼
  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)                                 //確認(rèn)
  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. * 函 數(shù) 名: 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單片機(jī)寄存器定義的頭文件
  545. #include <intrins.h>      //包含_nop_()函數(shù)定義的頭文件
  546. #define        OP_READ        0xa1                // 器件地址以及讀取操作,0xa1即為1010 0001B
  547. #define        OP_WRITE 0xa0                // 器件地址以及寫入操作,0xa1即為1010 0000B
  548. sbit SCL=P3^5;         //將串行時(shí)鐘總線SCL位定義在為P3.4引腳
  549. sbit SDA=P3^6;          //將串行數(shù)據(jù)總線SDA位定義在為P3.5引腳     
  550. /*****************************************************
  551. 函數(shù)功能:延時(shí)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. 函數(shù)功能:延時(shí)若干毫秒
  562. 入口參數(shù):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. 函數(shù)功能:開(kāi)始數(shù)據(jù)傳送
  572. ***************************************************/
  573. void start()
  574. // 開(kāi)始位
  575. {
  576.         SDA = 1;    //SDA初始化為高電平“1”
  577.    SCL = 1;    //開(kāi)始數(shù)據(jù)傳送時(shí),要求SCL為高電平“1”
  578.         _nop_();     //等待一個(gè)機(jī)器周期
  579.         _nop_();     //等待一個(gè)機(jī)器周期
  580.         _nop_();     //等待一個(gè)機(jī)器周期
  581.         _nop_();     //等待一個(gè)機(jī)器周期
  582.         _nop_();     //等待一個(gè)機(jī)器周期
  583.         SDA = 0;    //SDA的下降沿被認(rèn)為是開(kāi)始信號(hào)
  584.         _nop_();     //等待一個(gè)機(jī)器周期
  585.         _nop_();     //等待一個(gè)機(jī)器周期
  586.         _nop_();     //等待一個(gè)機(jī)器周期
  587.         _nop_();     //等待一個(gè)機(jī)器周期
  588.         _nop_();     //等待一個(gè)機(jī)器周期
  589.         SCL = 0;    //SCL為低電平時(shí),SDA上數(shù)據(jù)才允許變化(即允許以后的數(shù)據(jù)傳遞)  
  590. }
  591. /***************************************************
  592. 函數(shù)功能:結(jié)束數(shù)據(jù)傳送
  593. ***************************************************/
  594. void stop()// 停止位
  595. {
  596.         SDA = 0;     //SDA初始化為低電平“0”        _n
  597.         SCL = 1;     //結(jié)束數(shù)據(jù)傳送時(shí),要求SCL為高電平“1”
  598.         _nop_();     //等待一個(gè)機(jī)器周期
  599.         _nop_();     //等待一個(gè)機(jī)器周期
  600.         _nop_();     //等待一個(gè)機(jī)器周期
  601.         _nop_();     //等待一個(gè)機(jī)器周期
  602.         _nop_();     //等待一個(gè)機(jī)器周期
  603.         SDA = 1;    //SDA的上升沿被認(rèn)為是結(jié)束信號(hào)
  604.         _nop_();     //等待一個(gè)機(jī)器周期
  605.         _nop_();     //等待一個(gè)機(jī)器周期
  606.         _nop_();     //等待一個(gè)機(jī)器周期
  607.         _nop_();     //等待一個(gè)機(jī)器周期
  608.         _nop_();     //等待一個(gè)機(jī)器周期
  609.         SDA=0;
  610.         SCL=0;
  611. }
  612. /***************************************************
  613. 函數(shù)功能:檢測(cè)應(yīng)答位
  614. ***************************************************/


  615. bit Ask()                  //檢測(cè)應(yīng)答
  616. {
  617.       bit ack_bit;        //儲(chǔ)存應(yīng)答位
  618.         SDA = 1;         // 發(fā)送設(shè)備(主機(jī))應(yīng)在時(shí)鐘脈沖的高電平期間(SCL=1)釋放SDA線,
  619.                         //以讓SDA線轉(zhuǎn)由接收設(shè)備(AT24Cxx)控制
  620.         _nop_();        //等待一個(gè)機(jī)器周期
  621.         _nop_();        //等待一個(gè)機(jī)器周期
  622.         SCL = 1;       //根據(jù)上述規(guī)定,SCL應(yīng)為高電平
  623.         _nop_();       //等待一個(gè)機(jī)器周期
  624.         _nop_();       //等待一個(gè)機(jī)器周期
  625.         _nop_();       //等待一個(gè)機(jī)器周期
  626.         _nop_();       //等待一個(gè)機(jī)器周期
  627.         _nop_();       //等待一個(gè)機(jī)器周期  
  628.         ack_bit = SDA; //接受設(shè)備(AT24Cxx)向SDA送低電平,表示已經(jīng)接收到一個(gè)字節(jié)
  629.                        //若送高電平,表示沒(méi)有接收到,傳送異常 結(jié)束發(fā)送
  630.         SCL = 0;       //SCL為低電平時(shí),SDA上數(shù)據(jù)才允許變化(即允許以后的數(shù)據(jù)傳遞)
  631.         return  ack_bit;                        // 返回AT24Cxx應(yīng)答位






  632. }
  633. /***************************************************
  634. 函數(shù)功能:從AT24Cxx讀取數(shù)據(jù)
  635. 出口參數(shù):x
  636. ***************************************************/
  637. unsigned char ReadData()
  638. // 從AT24Cxx移入數(shù)據(jù)到MCU
  639. {
  640.         unsigned char i;
  641.         unsigned char x;   //儲(chǔ)存從AT24Cxx中讀出的數(shù)據(jù)
  642.         for(i = 0; i < 8; i++)
  643.         {
  644.                 SCL = 1;                //SCL置為高電平
  645.                 x<<=1;                  //將x中的各二進(jìn)位向左移一位
  646.                 x|=(unsigned char)SDA;  //將SDA上的數(shù)據(jù)通過(guò)按位“或“運(yùn)算存入x中
  647.                 SCL = 0;                        //在SCL的下降沿讀出數(shù)據(jù)
  648.         }
  649.         return(x);                //將讀取的數(shù)據(jù)返回
  650. }
  651. /***************************************************
  652. 函數(shù)功能:向AT24Cxx的當(dāng)前地址寫入數(shù)據(jù)
  653. 入口參數(shù):y (儲(chǔ)存待寫入的數(shù)據(jù))
  654. ***************************************************/
  655. //在調(diào)用此數(shù)據(jù)寫入函數(shù)前需首先調(diào)用開(kāi)始函數(shù)start(),所以SCL=0
  656. void WriteCurrent(unsigned char y)
  657. {
  658.         unsigned char i;
  659.         for(i = 0; i < 8; i++)                // 循環(huán)移入8個(gè)位
  660.         {
  661.             SDA = (bit)(y&0x80);   //通過(guò)按位“與”運(yùn)算將最高位數(shù)據(jù)送到S
  662.                                                   //因?yàn)閭魉蜁r(shí)高位在前,低位在后
  663.                 _nop_();            //等待一個(gè)機(jī)器周期   
  664.            SCL = 1;            //在SCL的上升沿將數(shù)據(jù)寫入AT24Cxx      
  665.            _nop_();            //等待一個(gè)機(jī)器周期
  666.           _nop_();             //等待一個(gè)機(jī)器周期      
  667.                
  668.                   SCL = 0;            //將SCL重新置為低電平,以在SCL線形成傳送數(shù)據(jù)所需的8?jìng)(gè)脈沖
  669.                 y <<= 1;           //將y中的各二進(jìn)位向左移一位
  670.                
  671.         }
  672. }
  673. /***************************************************
  674. 函數(shù)功能:向AT24Cxx中的指定地址寫入數(shù)據(jù)
  675. 入口參數(shù):add (儲(chǔ)存指定的地址);dat(儲(chǔ)存待寫入的數(shù)據(jù))
  676. ***************************************************/
  677. void WriteSet(unsigned char add, unsigned char dat)
  678. // 在指定地址addr處寫入數(shù)據(jù)WriteCurrent
  679. {
  680.         start();               //開(kāi)始數(shù)據(jù)傳遞
  681.         WriteCurrent(OP_WRITE);  //選擇要操作的AT24Cxx芯片,并告知要對(duì)   其寫入數(shù)據(jù)
  682.          Ask();
  683.         WriteCurrent(add);       //寫入指定地址
  684.         Ask();
  685.         WriteCurrent(dat);       //向當(dāng)前地址(上面指定的地址)寫入數(shù)據(jù)
  686.         Ask();
  687.         stop();                //停止數(shù)據(jù)傳遞
  688.         delaynms(5);               //1個(gè)字節(jié)的寫入周期為1ms, 最好延時(shí)1ms以上
  689. }
  690. /***************************************************
  691. 函數(shù)功能:從AT24Cxx中的當(dāng)前地址讀取數(shù)據(jù)
  692. 出口參數(shù):x (儲(chǔ)存讀出的數(shù)據(jù))
  693. ***************************************************/
  694. unsigned char ReadCurrent()
  695. {
  696.         unsigned char x;
  697.         start();               //開(kāi)始數(shù)據(jù)傳遞
  698.         WriteCurrent(OP_READ);   //選擇要操作的AT24Cxx芯片,并告知要讀其數(shù)據(jù)
  699.         Ask();
  700.         x=ReadData();         //將讀取的數(shù)據(jù)存入x
  701.         stop();                //停止數(shù)據(jù)傳遞
  702.         return x;              //返回讀取的數(shù)據(jù)
  703. }
  704. /***************************************************
  705. 函數(shù)功能:從AT24Cxx中的指定地址讀取數(shù)據(jù)
  706. 入口參數(shù):set_addr
  707. 出口參數(shù):x
  708. ***************************************************/
  709. unsigned char ReadSet(unsigned char set_addr)
  710. // 在指定地址讀取
  711. {
  712.         start();                      //開(kāi)始數(shù)據(jù)傳遞
  713.         WriteCurrent(OP_WRITE);       //選擇要操作的AT24Cxx芯片,并告知要對(duì)其寫入數(shù)據(jù)
  714.         Ask();
  715.         WriteCurrent(set_addr);       //寫入指定地址
  716.         Ask();
  717.         return(ReadCurrent());        //從指定地址讀出數(shù)據(jù)并返回
  718. }
復(fù)制代碼

分享到:  QQ好友和群QQ好友和群 QQ空間QQ空間 騰訊微博騰訊微博 騰訊朋友騰訊朋友
收藏收藏1 分享淘帖 頂 踩
回復(fù)

使用道具 舉報(bào)

板凳
ID:235200 發(fā)表于 2020-3-7 01:55 | 只看該作者
這已經(jīng)告訴了你密碼
for(b=0;b<6;b++)      //24c08里面取出正確的密碼                                                  
   {
       original_key=ReadSet(b);
        delay(5);
     }
讀出放在uchar original_key[6]; 這個(gè)數(shù)組中(程序中未用數(shù)組估計(jì)不對(duì)),新存儲(chǔ)器讀出結(jié)果是FFFFFFFFFFFF
回復(fù)

使用道具 舉報(bào)

沙發(fā)
ID:648281 發(fā)表于 2020-3-6 22:15 | 只看該作者
你好!初始密碼保存在 24C08 存儲(chǔ)器里面
回復(fù)

使用道具 舉報(bào)

本版積分規(guī)則

小黑屋|51黑電子論壇 |51黑電子論壇6群 QQ 管理員QQ:125739409;技術(shù)交流QQ群281945664

Powered by 單片機(jī)教程網(wǎng)

快速回復(fù) 返回頂部 返回列表
主站蜘蛛池模板: av大片 | 国产精品国产成人国产三级 | 国产成人福利在线观看 | 国产精品99久久久久久宅男 | 国产清纯白嫩初高生视频在线观看 | 成人a网| 成人高潮片免费视频欧美 | 亚洲国产一区二区三区在线观看 | 国产精品午夜电影 | 亚洲欧美视频一区 | 欧美日韩一区精品 | 国产一区视频在线 | 91免费观看在线 | 亚洲天堂一区 | www.久久99| 久久精品免费 | 荷兰欧美一级毛片 | 国产精品久久国产精品 | 国产伦精品一区二区三区精品视频 | 日韩精品久久久久 | 岛国av免费在线观看 | 在线视频a | 久久国产精品-国产精品 | 午夜男人天堂 | 黄色小视频入口 | 欧美成年人视频在线观看 | 亚洲精品久| 精国产品一区二区三区四季综 | 日本一区二区三区在线观看 | 亚洲欧美在线免费观看 | 精品麻豆剧传媒av国产九九九 | 日本成人中文字幕 | 国产成人精品免费视频 | 国产乱码精品一品二品 | 日韩有码在线观看 | 超碰97人人人人人蜜桃 | 婷婷在线免费 | 日韩精品无码一区二区三区 | 久久久激情 | 久久久综合色 | 国产91精品久久久久久久网曝门 |