stankovic96

Keil-Shift LED

Mar 19th, 2018
402
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.50 KB | None | 0 0
  1. #include <REGX52.H>
  2. typedef unsigned char byte;
  3.  
  4. byte xdata LED_PREK _at_ 0x8000;
  5. byte xdata PLAVE_LED _at_ 0x8003;
  6. byte LEDS;
  7. byte prek;
  8. byte smer;
  9.  
  10. void poc_stanje(byte x )
  11. {
  12.     switch (x&0x03)
  13.     {
  14.         case 0:
  15.             LEDS=~0x01;
  16.             break;
  17.         case 1:
  18.             LEDS=~0x03;
  19.             break;
  20.         case 2:
  21.             LEDS=~0x07;
  22.             break;
  23.         case 3:
  24.             LEDS=~0x0f;
  25.             break;
  26.     }
  27. }
  28. void main()
  29. {
  30.     unsigned long i;
  31.     prek=LED_PREK;
  32.     poc_stanje(prek);
  33.  
  34.    while(1)
  35.    {
  36.         prek=LED_PREK; 
  37.         smer=(0x04&prek)>>2;
  38.         if(smer==0x01)
  39.             LEDS=(LEDS>>1)|((LEDS&0x01)<<7);
  40.         else
  41.             LEDS=(LEDS<<1)|((LEDS&0x80)>>7);       
  42.         for(i=0; i<100000 ;i++);
  43.         PLAVE_LED=LEDS;
  44.    }
  45. }
  46. //******************************************* DRUGI NACIN
  47. #include<REGX52.H>
  48. typedef unsigned char byte;
  49. byte xdata led_prek _at_ 0x8000;
  50. byte xdata plave_led _at_ 0x8003;
  51. byte leds;
  52. byte prek;
  53. byte smer;
  54. unsigned int brojac=0;
  55.  
  56. void poc_stanje(byte x)
  57. {
  58.     switch(x&0x03)
  59.     {
  60.         case 0:
  61.             leds=~0x01;
  62.             break;
  63.         case 1:
  64.             leds=~0x03;
  65.             break;
  66.         case 2:
  67.             leds=~0x07;
  68.             break;
  69.         case 3:
  70.             leds=~0x0f;
  71.             break;
  72.     }
  73. }
  74. void timer2_ISR() interrupt 5
  75. {   EA=0;
  76.     if(++brojac>10000)
  77.     {
  78.         prek=led_prek;
  79.         smer=(0x04&prek)>>2;
  80.         if(smer==0x01)
  81.             leds=(leds>>1)|((leds&0x01)<<7);
  82.         else
  83.             leds=(leds<<1)|((leds&0x80)>>7);
  84.         plave_led=leds;
  85.         brojac=0;
  86.     }
  87.     TF2=EXF2=0;
  88.     EA=1;
  89. }
  90. void main()
  91. {
  92.     RCAP2H=0xfa;
  93.     RCAP2L=0x00;
  94.     T2CON=0x00;
  95.     ET2=1;
  96.     TR2=1;
  97.    
  98.     EA=1;
  99.     prek=led_prek;
  100.     poc_stanje(prek);
  101.  
  102.     while(1);
  103. }
Advertisement
Add Comment
Please, Sign In to add comment