SHARE
TWEET

Untitled

a guest May 22nd, 2019 76 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <REGX52.H>
  2. #define TT 80000
  3. sbit STR = 0x84; //P0_4
  4. sbit ACK = 0x85;    //P0_5
  5. sbit STRS = 0x82;   //P0_2
  6. sbit ACKS = 0x83;   //P0_3
  7.  
  8. bit b1 =1, b2=1;
  9.  
  10. int dt = TT/1000, tt = TT/100;
  11. unsigned char LiczB2 = 0x00;
  12.  
  13. void wait(int i){
  14.     unsigned int k,l,m;
  15.    
  16.     for(l = 0;l<i;l++){
  17.         k=500;
  18.         m=1000;
  19.         k=m*k;
  20.     }
  21. }
  22.  
  23. void init(){
  24.     LiczB2=0;
  25.     STR = 1;
  26.     ACK = 0;
  27.  
  28.    
  29.     IT0 = 1;    //-int0 edge active
  30.     EX0 = 1;    //enable int0
  31.     EA = 1;     //enable all interruopts
  32. }
  33.  
  34. void LiczInt0(void) interrupt 0{
  35.     EX0 = 0;
  36.     LiczB2++;
  37.     if(LiczB2 == 255){
  38.     LiczB2 = 0;
  39.     }
  40.     EX0 = 1;
  41.     b2 = 0;
  42. }
  43.  
  44. void main(){
  45.     init();
  46.     wait(tt);
  47.     while(P0_0 == 0){
  48.  
  49.         wait(tt);
  50.         while(b2){
  51.             wait(dt);
  52.         }
  53.         P1 = LiczB2;
  54.         P2 = LiczB2;
  55.         b2=1;
  56.         STR = 0;
  57.         while(ACK != 1){
  58.            
  59.         }
  60.         STR = 1;
  61.     }
  62.     while(P0_0 == 1){
  63.         wait(tt);
  64.        
  65.         while(STRS==1){
  66.  
  67.         }
  68.         P1 = P2;
  69.         ACKS = 1;
  70.         wait(dt);
  71.         ACKS = 0;
  72.     }
  73. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top