Guest User

Untitled

a guest
Jun 17th, 2016
45
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 3.20 KB | None | 0 0
  1.     if ( my_i2c_states == start )
  2.     {
  3.         //Send the start bit. Need to send SDA and SCL
  4.         OEA |= 0xC0;
  5.         PA7 = 0 ;
  6.         my_i2c_states = address;
  7.         tx_i2c_buffer_load  = 0x01;
  8.     }
  9.  
  10.     else if ( my_i2c_states == address )
  11.     {
  12.         //Check the count of address bits and send remaining bits. After eight bits go to read mode for ACK
  13.         OEA |= 0xC0;
  14.         PA6 = 0;
  15.         tx_i2c_bits ++;
  16.         if(tx_i2c_bits > 7)
  17.         {
  18.             my_i2c_states = address_ack;
  19.             tx_i2c_bits = 0x00;
  20.             __asm
  21.             mov _data_rw_bit, c
  22.             __endasm;
  23.  
  24.         }
  25.         __asm
  26.         mov a, _tx_i2c_buffer;
  27.         rlc a;
  28.         mov _PA7, c;
  29.         mov _tx_i2c_buffer,a;
  30.         __endasm;
  31.         PA6 = 1;
  32.  
  33.     }
  34.     else if ( my_i2c_states == address_ack )
  35.     {
  36.         //Read the ACK bit; Go back to address if NAK-ed. Else to data
  37.         PA6 = 0;
  38.         OEA |= 0x40;
  39.         __asm
  40.         mov c, _PA7
  41.         jc 6200$;
  42.             mov a , _data_rw_bit;
  43.             rrc a;
  44.                     jc 6201$;
  45.                     mov _my_i2c_states,#0x07;
  46.                     ajmp 6202$;
  47.                 6201$:
  48.                     mov _my_i2c_states,#0x05;
  49.                     ajmp 6202$;
  50.         6200$:
  51.             mov _my_i2c_states, #0x02;
  52.         6202$:
  53.         setb _PA6;
  54.         __endasm;
  55.  
  56.     }
  57.     else if ( my_i2c_states == data_write)
  58.     {
  59.  
  60.          //Check the count of address bits and send remaining bits. After eight bits go to read mode for ACK
  61.         OEA |= 0xC0;
  62.         PA6 = 0;
  63.         tx_i2c_bits ++;
  64.         if(tx_i2c_bits > 7)
  65.         {
  66.             my_i2c_states = data_write_ack;
  67.             tx_i2c_bits = 0x00;
  68.  
  69.         }
  70.         __asm
  71.         mov a, _tx_data_buffer;
  72.         rlc a;
  73.         mov _PA7, c;
  74.         mov _tx_data_buffer,a;
  75.         __endasm;
  76.         PA6 = 1;
  77.  
  78.  
  79.     }
  80.     else if ( my_i2c_states == data_read)
  81.     {
  82.         //Check the count of data bits and receive remaining bits. After eight bits go for data read ACK
  83.         OEA |= 0x40;
  84.         tx_i2c_bits ++;
  85.         if(tx_i2c_bits > 7)
  86.         {
  87.             my_i2c_states = data_read_ack;
  88.             tx_i2c_bits = 0x00;
  89.         }
  90.         else
  91.         {
  92.             __asm
  93.             mov a, _rx_i2c_buffer;
  94.             mov c,_PA5;
  95.             rrc a;
  96.             mov _rx_i2c_buffer,a;
  97.             __endasm;
  98.         }
  99.     }
  100.     else if ( my_i2c_states == data_write_ack )
  101.     {
  102.         //Read the ACK bit; Go back to previous data if NAK-ed. Else to next data if present. Else go to stop
  103.         OEA |= 0x40;
  104.         PA6 = 0;
  105.         __asm
  106.         mov c, _PA7
  107.         jc 6203$;
  108.         mov _my_i2c_states, #0x05;
  109.         6203$:
  110.         mov _my_i2c_states,#0x09;
  111.         setb _PA6;
  112.         __endasm;
  113.  
  114.  
  115.     }
  116.     else if ( my_i2c_states == data_read_ack )
  117.     {
  118.         //Send the ACK bit. No multiple reads considered.
  119.         OEA |= 0xC0;
  120.         __asm
  121.          clr _PA7;
  122.         __endasm;
  123.         my_i2c_states = stop;
  124.     }
  125.     else if ( my_i2c_states == stop )
  126.     {
  127.         //Send the stop bit
  128.         OEA |= 0xC0;
  129.         PA6 = 1 ;
  130.         PA7 = 1 ;
  131.         my_i2c_states = idle;
  132.     }
Add Comment
Please, Sign In to add comment