Advertisement
milanmetal

[RSDMK] Zadatak 1

Mar 17th, 2018
177
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.35 KB | None | 0 0
  1. #include <REGX52.H> //biblioteka sa definicijama registara
  2. typedef unsigned char byte;
  3. byte xdata LED_PREK _at_ 0x8000; //crvene LED diode / prekidaci
  4. byte xdata PLAVE_LED _at_ 0x8003; //zute LED diode
  5. //byte xdata ZELENE_LED _at_ 0x8001; //zelene LED diode
  6.  
  7. byte LEDS; //pomocna promenljiva koja pamti
  8. //stanje zutih LED dioda
  9. byte prethodna_vr = 0x00;
  10.  
  11. byte PREK_SL;
  12. byte MSB;
  13. void main()
  14. {
  15.     unsigned long i; //brojacka promenljiva
  16.     LEDS = 0x0F; //pocetno stanje zutih LED dioda
  17.  
  18.         while(1)
  19.         {
  20.             PREK_SL = ~LED_PREK; //izgleda sasavo, ali radi :)
  21.            
  22.             switch(PREK_SL) {
  23.                 case 0x00:
  24.                     if(PREK_SL != prethodna_vr) {  
  25.                         LEDS = 0x01;
  26.                         prethodna_vr = 0x00;
  27.                     }
  28.                 break;
  29.                 case 0x01:
  30.                     if(PREK_SL != prethodna_vr) {  
  31.                         LEDS = 0x03;
  32.                         prethodna_vr = 0x01;
  33.                     }
  34.                 break;
  35.                 case 0x02:
  36.                     if(PREK_SL != prethodna_vr) {  
  37.                         LEDS = 0x07;
  38.                         prethodna_vr = 0x02;
  39.                     }
  40.                 break;
  41.                 case 0x03:
  42.                     if(PREK_SL != prethodna_vr) {  
  43.                         LEDS = 0x0F;
  44.                         prethodna_vr = 0x03;
  45.                     }
  46.                 break;
  47.             }          
  48.  
  49.             for (i = 0; i < 200000; i++); //pauza
  50.             PLAVE_LED = ~LEDS; //promena stanja
  51.            
  52.             if(~LED_PREK & 0x04) {
  53.                 MSB = LEDS & 0x80;
  54.                 LEDS = LEDS << 1;
  55.                 if(MSB) LEDS |= 1;
  56.             }  else {
  57.                 MSB = LEDS & 0x01;
  58.                 LEDS = LEDS >> 1;
  59.                 if(MSB) LEDS |= 0x80;
  60.             }
  61.         }
  62.  
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement