Advertisement
Pagoniusz

Untitled

Apr 7th, 2015
218
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.35 KB | None | 0 0
  1. Buzka latajaca po obwodzie wyswietlacza.
  2.  
  3. Pamietajcie o dołączeniu pliku libswm.a do projektu
  4.  
  5. /*
  6.  * AVRGCC1.c
  7.  *
  8.  * Created: 2013-04-03 13:22:50
  9.  *  Author: student
  10.  */
  11. #define F_CPU 6000000UL
  12. #include <lcd.h>
  13. #include <util/delay.h>
  14. int poz = 0;
  15. int direction = 0;
  16. char* sNapis = "Laboratorium SW";
  17. void init(void)
  18. {
  19.     MCUCR = _BV(SRE) | _BV(SRW10);
  20.     XMCRA = _BV(SRW00) | _BV(SRW01) | _BV(SRW11);
  21.      
  22.     _delay_ms(50);
  23.     COMM_LCD = 0x30;
  24.     _delay_ms(50);
  25.     COMM_LCD = 0x30;
  26.     _delay_ms(50);
  27.     COMM_LCD = 0x30;    
  28.     _delay_ms(20);
  29.      
  30.     pisz_com(0x38);
  31.     pisz_com(0x0C);
  32.     pisz_com(0x01);
  33.     pisz_com(0x06);
  34.      
  35.     DDRD = 0x00;
  36.     PORTD = 0xFF;
  37. }
  38.  
  39. void dodaj_znaki(void)
  40. {
  41.     // samochod jadacy w prawo
  42.     pisz_com(0b01000000);
  43.     pisz_ws(0b00000001);
  44.     pisz_ws(0b00000110);
  45.     pisz_ws(0b00000100);
  46.     pisz_ws(0b00001010);
  47.     pisz_ws(0b00001000);
  48.     pisz_ws(0b00000101);
  49.     pisz_ws(0b00000110);
  50.     pisz_ws(0b00000001);
  51.      
  52.     pisz_com(0b01001000);
  53.     pisz_ws(0b00011000);
  54.     pisz_ws(0b01100110);
  55.     pisz_ws(0b01000010);
  56.     pisz_ws(0b10000101);
  57.     pisz_ws(0b10000001);
  58.     pisz_ws(0b01011010);
  59.     pisz_ws(0b01100110);
  60.     pisz_ws(0b00011000);
  61.      
  62.      
  63.  
  64. }
  65.  
  66. void pisz_napis(char* napis)
  67. {
  68.     pisz_com(0b10000000);
  69.     int i;
  70.     for (i = 0; i < strlen(napis); i++)
  71.     {
  72.         pisz_ws(napis[i]);
  73.     }
  74. }
  75.  
  76. void jedz(void)
  77. {
  78.     int adres;
  79.     if (direction==0)
  80.     {
  81.         adres=0b10000000+poz;
  82.     }
  83.     else
  84.     {
  85.         adres = 0b11000000 + poz;
  86.     }
  87.      
  88.     pisz_com(adres);
  89.      
  90.      
  91.         pisz_ws(0x00);
  92.  
  93.         pisz_ws(0x01);
  94.      
  95. }
  96.  
  97. void sprawdz(void)
  98. {
  99.     uint8_t zaq = PIND;
  100.     if (poz==0&&direction==1)
  101.         {
  102.             direction = 0;
  103.              
  104.         }
  105.         else if (poz==14&&direction==0)
  106.         {
  107.             direction = 1;
  108.              
  109.         }
  110.         else{
  111.             if(direction==1 && poz > 0)
  112.     {
  113.         poz--;
  114.          
  115.          
  116.     }        
  117.     else if(poz < 15)
  118.     {
  119.         poz++;
  120.          
  121.          
  122.     }
  123.              
  124.         }
  125.      
  126. }
  127.  
  128. int main(void)
  129. {
  130.     init();
  131.     dodaj_znaki();
  132.          
  133.     while(1)
  134.     {
  135.         sprawdz();
  136.         pisz_com(0x01);
  137.         //pisz_napis(sNapis);    
  138.         jedz();
  139.         _delay_ms(200);
  140.     }
  141. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement