Advertisement
Pagoniusz

Untitled

Apr 21st, 2015
212
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.32 KB | None | 0 0
  1. #define F_CPU 6000000L
  2. #define czas 400
  3. #include <avr/io.h>
  4. #include <avr/delay.h>
  5.  
  6. #include <lcd.h>
  7. #include <one_wire.h>
  8. void init()
  9. {
  10.    MCUCR=_BV(SRE)|_BV(SRW10);
  11.    XMCRA=_BV(SRW00)|_BV(SRW01)|_BV(SRW11);
  12.    _delay_ms(15);
  13.    COMM_LCD=0x30;
  14.    _delay_ms(5);
  15.    COMM_LCD=0x30;
  16.    _delay_us(200);
  17.    COMM_LCD=0x30;
  18.    _delay_ms(2);
  19.    //2
  20.    pisz_com(0b00111000);
  21.    //3
  22.    pisz_com(0b00001100);
  23.    //4
  24.    pisz_com(0b00000001);
  25.    //5
  26.    pisz_com(0b00000110);
  27.    //
  28. }
  29.  
  30. char znaki[16]={'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'};
  31.  
  32. int zi=0;
  33. int cz=0;
  34.  
  35. void zielona(int zapal)
  36. {
  37.    if(zapal)
  38.       _iB_zapal(2);
  39.    else
  40.       _iB_zgas(2);
  41.    zi=zapal;
  42. }
  43. void czerwona(int zapal)
  44. {
  45.    if(zapal)
  46.       _iB_zapal(1);
  47.    else
  48.       _iB_zgas(1);
  49.    cz=zapal;
  50. }
  51.  
  52. void piszBajt(char bajt)
  53. {
  54.    char mlodsza;
  55.    char starsza;
  56.    mlodsza=bajt%16;
  57.    starsza=bajt/16;
  58.    _delay_ms(2);
  59.    pisz_ws(znaki[starsza]);
  60.    _delay_ms(2);
  61.    pisz_ws(znaki[mlodsza]);
  62.    
  63. }
  64.  
  65. char tab[8], tab_1[8];
  66. //char pattern[]={0xde,0x00, 0x00, 0x00, 0xfd,0x28,0xa3,0x08};
  67. int main(void)
  68. {
  69.    int w;
  70.    char odp;
  71.    init();
  72.    int bylo=0;
  73.    _iB_init();
  74.    
  75.    int i;
  76.    
  77.    int first = 1;
  78.    
  79.    while(1)
  80.    {
  81.       w=iB_reset();
  82.       if(w==0)
  83.       {
  84.          _iB_33h(tab);
  85.          bylo=1;
  86.          for(int i=0;i<8;i++)
  87.          {
  88.             if(first == 1)
  89.             {
  90.                tab_1[i] = tab[i];
  91.                bylo = 0;
  92.             }
  93.             else if(tab[i]!=tab_1[i])
  94.             {
  95.                bylo=0;
  96.                break;
  97.             }
  98.          }
  99.          
  100.          if(first == 1)
  101.          {
  102.             pisz_com(0x80);
  103.             for(i=0;i<8;i++)
  104.             {
  105.                piszBajt(tab[i]);
  106.             }
  107.             first = 0;
  108.          }
  109.          else
  110.          {
  111.             pisz_com(0xC0);
  112.             for(i=0;i<8;i++)
  113.             {
  114.                piszBajt(tab[i]);
  115.             }
  116.          }
  117.          
  118.          if(bylo)
  119.          {
  120.             czerwona(0);
  121.             zielona(1);
  122.          }
  123.          else
  124.          {
  125.             zielona(0);
  126.             czerwona(1);
  127.          }
  128.          odp=odp;
  129.          
  130.          _delay_ms(1000);
  131.       }
  132.      
  133.       //czerwona(0);
  134.       //zielona(0);
  135.       _delay_ms(1000);
  136.    }
  137. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement