Advertisement
ventress

Mikronapędy 04

Apr 25th, 2016
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.53 KB | None | 0 0
  1. #include <reg515.sfr>
  2. #include <lcd.h>
  3.  
  4. int tablicaP1[6] = {222, 219, 249, 237, 231, 246};
  5. int hallotron[6] = {3, 1, 5, 4, 6, 2};
  6. int czestotliwosc = 100;
  7. int limp;
  8. int licznik = 0;
  9. int kierunek = 0;
  10.  
  11.  
  12. main() {
  13.  
  14.     int i = 0;
  15.     unsigned char znak;
  16.     unsigned int liczba = 0;
  17.     int enterPressed = 0;
  18.  
  19.     EAL = 1;
  20.     ET2 = 1;
  21.     T2I0 = 1;
  22.     T2R1 = 1;
  23.    
  24.     lcd_init();
  25.     out_instr(0x01);
  26.     while(1)
  27.     {
  28.         znak = get_kb();
  29.         if(znak != '\0')
  30.         {
  31.             if(znak >='0' && znak <='9')
  32.             {
  33.                 liczba = liczba*10 +(znak-48);
  34.                 out_char(znak);
  35.             }
  36.             if(znak == 'p')
  37.             {
  38.                kierunek = 0;
  39.             }
  40.             if(znak == 'l')
  41.             {
  42.                kierunek = 1;
  43.             }
  44.             if(znak == 'e')
  45.             {
  46.                 enterPressed = 1;
  47.                 out_instr(0x01);
  48.                 out_instr(0xC0);
  49.                 out_char(liczba);
  50.  
  51.                 czestotliwosc = liczba;
  52.                 if (czestotliwosc < 100 && czestotliwosc > 500)
  53.                 {
  54.                     czestotliwosc = 100;
  55.                 }
  56.                 limp = 0xFFFF - 1000000 / czestotliwosc;
  57.                 CRCH = limp >>8;
  58.                 CRCL = limp;
  59.                 liczba = 0;
  60.                 out_instr(0x10);
  61.             }
  62.             if(enterPressed == 1)
  63.             {
  64.             out_instr(0x80);
  65.             enterPressed = 0;
  66.             }
  67.         }
  68.         for(i=0;i<15000;i++);
  69.     }      
  70. }
  71.  
  72. _interrupt 5 void int_T2(void)
  73. {
  74.     while((P4&7) == hallotron[licznik])
  75.     {
  76.         TF2 = 0;
  77.         if (kierunek == 0)
  78.         {
  79.             licznik++;
  80.             if(licznik > 5)
  81.                 licznik = 0;
  82.             P1 = tablicaP1[licznik];
  83.         }
  84.         if (kierunek == 1)
  85.         {
  86.             licznik--;
  87.             if(licznik < 0)
  88.                 licznik = 5;
  89.             P1 = tablicaP1[licznik];
  90.            
  91.         }
  92.     }
  93. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement