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

QQ登錄

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

搜索
查看: 2395|回復(fù): 0
收起左側(cè)

PMC234+AT24C01程序源碼

[復(fù)制鏈接]
ID:247996 發(fā)表于 2017-11-10 10:45 | 顯示全部樓層 |閱讀模式
PMC234 + AT24C01 程序源碼,直接可用
所有資料51hei提供下載:
pmc234_24c01.rar (17.78 KB, 下載次數(shù): 12)


單片機(jī)源程序如下:

  1. #include        "extern.h"
  2. /***********************************************************************************************/
  3. void at24cxx_Delay_5us( void );
  4. void at24cxx_Delay_10us( void );
  5. void at24cxx_Delay_10ms( void );
  6. void AT24CXX_IO_Init( void );
  7. void AT24CXX_CLK_LOW( void );
  8. void AT24CXX_CLK_HIGH( void );
  9. void AT24CXX_IO_LOW( void );
  10. void AT24CXX_IO_HIGH( void );
  11. void at24cxx_IO_input( void );
  12. void at24cxx_IO_ouput( void );
  13. void at24cxx_Start( void );
  14. void at24cxx_Stop( void );
  15. void at24cxx_SEND_ACK( void );
  16. void at24cxx_SEND_NACK( void );
  17. void at24cxx_RECV_ACK( void );
  18. void at24cxx_Recv_Char( void );
  19. void at24cxx_Send_Char( void );
  20. void read_Random_Byte( void );
  21. void write_Random_Byte( void );
  22. void read_eeprom_configuration( void );
  23. void write_eeprom_configuration( void );
  24. /***********************************************************************************************/
  25. void        FPPA0 (void)
  26. {
  27.         .ADJUST_IC        SYSCLK=IHRC/2, IHRC=16MHz, VDD=5V, Bandgap=On;

  28.         //        Insert Initial Code
  29.         AT24CXX_IO_Init();
  30.         while (1)
  31.         {
  32. //                ...
  33. //                wdreset;
  34.                 read_eeprom_configuration();
  35.                 write_eeprom_configuration();
  36.         }
  37. }

  38. void        FPPA1 (void)
  39. {
  40.         goto        $;
  41. }


  42. void        Interrupt (void)
  43. {
  44.         pushaf;

  45.         if (Intrq.T16)
  46.         {        //        T16 Trig
  47.                 //        User can add code
  48.                 Intrq.T16        =        0;
  49.                 //...
  50.         }

  51.         popaf;
  52. }

  53. /******************************************************/
  54. /***********************************************************************************************
  55. * \brief      This function is just used to generate some example data for write operations
  56. *             on the card.
  57. *
  58. **********************************************************************************************/
  59. void at24cxx_Delay_5us( void )
  60. {
  61.         .delay 100;
  62. }
  63. void at24cxx_Delay_10us( void )
  64. {
  65.         .delay 200;
  66. }
  67. void at24cxx_Delay_10ms( void )
  68. {
  69.         .delay 200;
  70.         .delay 200;
  71.         .delay 200;
  72.         .delay 200;
  73.         .delay 200;
  74. }
  75. /***********************************************************************************************/
  76. void AT24CXX_IO_Init( void )
  77. {
  78.         //SCL
  79.         PA.0 = 1;
  80.         PAC.0 = 1;
  81.         //SDA
  82.         PA.5 = 1;       
  83.         PAC.5 = 0;       
  84. }
  85. /***********************************************************************************************/
  86. void AT24CXX_CLK_LOW( void )
  87. {
  88.         PA.0 = 0;       
  89. }
  90. void AT24CXX_CLK_HIGH( void )
  91. {
  92.         PA.0 = 1;       
  93. }
  94. /***********************************************************************************************/
  95. void AT24CXX_IO_LOW( void )
  96. {
  97.         PA.5 = 0;       
  98. }
  99. void AT24CXX_IO_HIGH( void )
  100. {
  101.         PA.5 = 1;       
  102. }
  103. /***********************************************************************************************
  104. * \brief      This function is just used to generate some example data for write operations
  105. *             on the card.
  106. *
  107. **********************************************************************************************/
  108. void at24cxx_IO_input( void )
  109. {
  110.         PAC.5 = 0;       
  111. }
  112. void at24cxx_IO_ouput( void )
  113. {
  114.         PAC.5 = 1;
  115. }
  116. /***********************************************************************************************
  117. * \brief      This function is just used to generate some example data for write operations
  118. *             on the card.
  119. *
  120. **********************************************************************************************/
  121. /***********************************************************************************************
  122. * \brief      This function is just used to generate some example data for write operations
  123. *             on the card.
  124. *
  125. **********************************************************************************************/
  126. /***********************************************************************************************
  127. * \brief      This function is just used to generate some example data for write operations
  128. *             on the card.
  129. *
  130. **********************************************************************************************/
  131. void at24cxx_Start( void )
  132. {
  133.           at24cxx_Delay_10us();
  134.           at24cxx_IO_input();
  135.           AT24CXX_IO_HIGH();
  136.           at24cxx_Delay_10us();
  137.           AT24CXX_CLK_HIGH();         
  138.           at24cxx_Delay_10us();          
  139.           AT24CXX_IO_LOW();
  140.           at24cxx_Delay_10us();
  141.           AT24CXX_CLK_LOW();
  142.           at24cxx_Delay_10us();
  143. }

  144. /***********************************************************************************************
  145. * \brief      This function is just used to generate some example data for write operations
  146. *             on the card.
  147. *
  148. **********************************************************************************************/
  149. void at24cxx_Stop( void )
  150. {
  151.           at24cxx_IO_ouput();
  152.           AT24CXX_IO_LOW();
  153.           at24cxx_Delay_10us();
  154.           AT24CXX_CLK_HIGH();
  155.           at24cxx_Delay_10us();
  156.           AT24CXX_IO_HIGH();
  157.           at24cxx_Delay_10us();
  158. }

  159. /***********************************************************************************************
  160. * \brief      This function is just used to generate some example data for write operations
  161. *             on the card.
  162. *
  163. **********************************************************************************************/
  164. void at24cxx_SEND_ACK( void )
  165. {       
  166.         AT24CXX_CLK_LOW();
  167.         at24cxx_Delay_5us();
  168.         at24cxx_IO_ouput();
  169.         AT24CXX_IO_LOW();
  170.         at24cxx_Delay_10us();
  171.         AT24CXX_CLK_HIGH();
  172.         at24cxx_Delay_10us();
  173.         AT24CXX_CLK_LOW();  
  174.         at24cxx_Delay_10us();
  175. }
  176. /***********************************************************************************************
  177. * \brief      This function is just used to generate some example data for write operations
  178. *             on the card.
  179. *
  180. **********************************************************************************************/
  181. void at24cxx_SEND_NACK( void )
  182. {
  183.         AT24CXX_CLK_LOW();
  184.         at24cxx_Delay_5us();
  185.         at24cxx_IO_ouput();
  186.         AT24CXX_IO_HIGH();
  187.         at24cxx_Delay_10us();
  188.         AT24CXX_CLK_HIGH();
  189.         at24cxx_Delay_10us();
  190.         AT24CXX_CLK_LOW();
  191.         at24cxx_Delay_10us();
  192. }
  193. /***********************************************************************************************
  194. * \brief      This function is just used to generate some example data for write operations
  195. *             on the card.
  196. *
  197. **********************************************************************************************/
  198. void at24cxx_RECV_ACK( void )
  199. {       
  200.         AT24CXX_CLK_LOW();
  201.         at24cxx_Delay_5us();
  202.         at24cxx_IO_input();
  203.         at24cxx_Delay_10us();
  204.         AT24CXX_CLK_HIGH();
  205.         at24cxx_Delay_5us();       
  206.         iic_retry_times = 200;               
  207.         iic_ack_flag = 0;       
  208.         do
  209.         {                                                 
  210.                   if( !IIC_SDA_PIN )
  211.                   {
  212.                           iic_ack_flag = 1; //sucessful sending
  213.                           break;
  214.                   }
  215.                 at24cxx_Delay_5us();
  216.                 iic_retry_times--;
  217.         }while( iic_retry_times > 0 );  
  218.         AT24CXX_CLK_LOW();       
  219. }
  220. /***********************************************************************************************
  221. * \brief      This function is just used to generate some example data for write operations
  222. *             on the card.
  223. *
  224. **********************************************************************************************/
  225. void at24cxx_Recv_Char( void )
  226. {       
  227.         iic_count = 0x08;
  228.        
  229.         at24cxx_IO_input();
  230.         at24cxx_Delay_5us();
  231.         do
  232.         {
  233.                 iic_recvByte <<= 1;
  234.                 AT24CXX_CLK_LOW();
  235.                 at24cxx_Delay_10us();
  236.                 AT24CXX_CLK_HIGH();
  237.                 at24cxx_Delay_5us();
  238.                 if( IIC_SDA_PIN )
  239.                 {
  240.                         iic_recvByte |= 0x01;
  241.                 }               
  242.                 else
  243.                 {
  244.                         iic_recvByte &= 0xFE;
  245.                 }
  246.                 at24cxx_Delay_5us();
  247.                 AT24CXX_CLK_LOW();
  248.                 iic_count--;
  249.         }while( iic_count > 0 );       
  250.         at24cxx_Delay_10us();       
  251. }
  252. /***********************************************************************************************
  253. * \brief      This function is just used to generate some example data for write operations
  254. *             on the card.
  255. *
  256. **********************************************************************************************/
  257. void at24cxx_Send_Char( void )
  258. {         
  259.           iic_count = 0x08;
  260.           at24cxx_IO_ouput();       
  261.           at24cxx_Delay_5us();
  262.           do
  263.           {
  264.                           AT24CXX_CLK_LOW();
  265.                         at24cxx_Delay_5us();
  266.                           if( iic_sendByte.7 )
  267.                           {
  268.                                   AT24CXX_IO_HIGH();
  269.                           }
  270.                         else
  271.                         {
  272.                                 AT24CXX_IO_LOW();
  273.                         }
  274.                         iic_sendByte <<= 1;
  275.                         at24cxx_Delay_5us();
  276.                         AT24CXX_CLK_HIGH();
  277.                         at24cxx_Delay_10us();
  278.                         iic_count--;                       
  279.           }while( iic_count > 0 );       
  280.           AT24CXX_CLK_LOW();                   
  281. }
  282. /***********************************************************************************************
  283. * \brief      This function is just used to generate some example data for write operations
  284. *             on the card.
  285. *
  286. **********************************************************************************************/
  287. void read_Random_Byte( void )
  288. {       
  289.         iic_rd_successful_flag = 0;
  290.         at24cxx_Start();       
  291.         iic_sendByte = IIC_COMMAND_WRITE;  
  292.         at24cxx_Send_Char();
  293.         at24cxx_RECV_ACK();
  294.         if( !iic_ack_flag )
  295.         {
  296.                 iic_rd_successful_flag = 1;
  297.                 return;
  298.         }
  299.         iic_sendByte = iic_Address;  
  300.         at24cxx_Send_Char();       
  301.         at24cxx_RECV_ACK();
  302.         if( !iic_ack_flag )
  303.         {
  304.                 iic_rd_successful_flag = 1;
  305.                 return;
  306.         }
  307.         //
  308.         at24cxx_Start();
  309.         iic_sendByte = IIC_COMMAND_READ;  
  310.         at24cxx_Send_Char();       
  311.         at24cxx_RECV_ACK();
  312.         if( !iic_ack_flag )
  313.         {
  314.                 iic_rd_successful_flag = 1;
  315.                 return;
  316.         }
  317.         //
  318.         at24cxx_Recv_Char();
  319.         at24cxx_SEND_NACK();       
  320.         iic_Data = iic_recvByte;
  321.         at24cxx_Stop();       
  322. }
  323. /***********************************************************************************************
  324. * \brief      This function is just used to generate some example data for write operations
  325. *             on the card.
  326. *
  327. **********************************************************************************************/
  328. void write_Random_Byte( void )
  329. {       
  330.         iic_rd_successful_flag = 0;
  331.         at24cxx_Start();
  332.         iic_sendByte = IIC_COMMAND_WRITE;  
  333.         at24cxx_Send_Char( );
  334.         at24cxx_RECV_ACK();
  335.         if( !iic_ack_flag )
  336.         {
  337.                 iic_rd_successful_flag = 1;
  338.                 return;
  339.         }
  340.         iic_sendByte = iic_Address;         
  341.         at24cxx_Send_Char( );
  342.         at24cxx_RECV_ACK();
  343.         if( !iic_ack_flag )
  344.         {
  345.                 iic_rd_successful_flag = 1;
  346. ……………………

  347. …………限于本文篇幅 余下代碼請(qǐng)從51黑下載附件…………
復(fù)制代碼




回復(fù)

使用道具 舉報(bào)

本版積分規(guī)則

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

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

快速回復(fù) 返回頂部 返回列表