Advertisement
Guest User

Untitled

a guest
Jun 27th, 2019
208
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. $regfile = "m8def.dat"
  2. $crystal = 1000000
  3. $hwstack = 40
  4. $swstack = 16
  5. $framesize = 32
  6.  
  7. Config Lcdpin = Pin , Db4 = Portc.3 , Db5 = Portc.2 , Db6 = Portc.1 , Db7 = Portc.0 , E = Portb.0 , Rs = Portd.7
  8. Config Lcd = 16 * 2
  9. Config Portc.5 = Output
  10. Config Adc = Single , Prescaler = Auto , Reference = Avcc
  11. Config Timer0 = Timer , Prescale = 8
  12. Config Timer1 = Pwm , Pwm = 8 , Prescale = 1 , Compare A Pwm = Clear Up , Compare B Pwm = Clear Up
  13.  
  14.  
  15.  
  16.  
  17. Deflcdchar 0,32,14,17,17,17,31,4,32' replace [x] with number (0-7)
  18. Deflcdchar 1,32,14,17,17,17,31,4,32' replace [x] with number (0-7)
  19.  
  20. Display On
  21. On Timer0 Przerwanie_co_2ms
  22. Dim Licznik As Integer
  23. Dim Sekundy As Byte
  24. Dim Minuty As Byte
  25. Dim Godziny As Byte
  26. Dim Liczba As Integer
  27. Dim Jasnosc As Integer
  28. dim bip as bit
  29. config portd.3 = input
  30. config portd.2 = input
  31. config portd.1 = input
  32. config portd.0 = input
  33. config DEBOUNCE = 30
  34. Deflcdchar 0,32,32,14,21,23,17,14,32' replace [x] with number (0-7)
  35.  
  36. Dim godzinaAlarmu as Byte
  37. Dim minutaAlarmu as Byte
  38. godzinaAlarmu = 0
  39. minutaAlarmu = 0
  40.  
  41. Dim timeChange as Byte
  42. timeChange = 0
  43.  
  44. portd.3 = 0
  45. portd.2 = 0
  46. portd.1 = 0
  47. portd.0 = 0
  48.  
  49. Enable Interrupts
  50. Enable Timer0
  51. Enable Timer1
  52. Timer0 = 6
  53.  
  54. Licznik = 0
  55. Sekundy = 0
  56. Minuty = 0
  57. Godziny = 1
  58. Jasnosc = 0
  59. bip = 1
  60.  
  61.  portc.5 = 0
  62. Cursor Off Noblink
  63.  
  64. Jasnosc = 41
  65. Do
  66.  
  67. '///////////////////////////////////////////////////ustawienia
  68.  
  69.  
  70.  
  71. IF PinD.2 = 1 THEN
  72.       timeChange = timeChange+1
  73.               IF timeChange > 4 THEN
  74.                       timeChange = 0
  75.               END IF
  76.       waitms 500
  77. END IF
  78.  
  79.  
  80.  
  81.  
  82. IF timeChange = 1 THEN
  83.        IF PIND.1 = 1 THEN
  84.              Godziny = Godziny + 1
  85.               IF Godziny = 24 THEN
  86.                     Godziny = 0
  87.                ENDIF
  88.        waitms 200
  89.        END IF
  90.        IF PIND.0 = 1 THEN
  91.              Godziny = Godziny - 1
  92.              IF Godziny = 255 THEN
  93.                    Godziny = 23
  94.              END IF
  95.              waitms 200
  96.          END IF
  97. END IF
  98. IF timeChange = 2 THEN
  99.        IF PIND.1 = 1 THEN
  100.              Minuty =Minuty + 1
  101.               IF Minuty = 60 THEN
  102.                     Minuty = 0
  103.                ENDIF
  104.        waitms 200
  105.        END IF
  106.        IF PIND.0 = 1 THEN
  107.              Minuty =Minuty - 1
  108.              IF Minuty = 255 THEN
  109.                    Minuty = 59
  110.              END IF
  111.              waitms 200
  112.          END IF
  113. END IF
  114. IF timeChange = 3 THEN
  115.        IF PIND.1 = 1 THEN
  116.              godzinaAlarmu = godzinaAlarmu + 1
  117.               IF godzinaAlarmu = 24 THEN
  118.                     godzinaAlarmu= 0
  119.                ENDIF
  120.        waitms 200
  121.        END IF
  122.        IF PIND.0 = 1 THEN
  123.              godzinaAlarmu= godzinaAlarmu- 1
  124.              IF godzinaAlarmu = 255 THEN
  125.                    godzinaAlarmu= 23
  126.              END IF
  127.              waitms 200
  128.          END IF
  129. END IF
  130. IF timeChange = 4 THEN
  131.        IF PIND.1 = 1 THEN
  132.              minutaAlarmu=minutaAlarmu+ 1
  133.               IF Minuty = 60 THEN
  134.                     minutaAlarmu= 0
  135.                ENDIF
  136.        waitms 200
  137.        END IF
  138.        IF PIND.0 = 1 THEN
  139.              minutaAlarmu=minutaAlarmu- 1
  140.              IF minutaAlarmu = 255 THEN
  141.                    minutaAlarmu= 59
  142.              END IF
  143.              waitms 200
  144.          END IF
  145. END IF
  146.  
  147.  
  148.  '//////////////////////////////////////////////////bip
  149.  
  150.  
  151.  
  152.  
  153.  
  154.  
  155.  IF godzinaAlarmu = godziny AND minutaAlarmu = minuty and bip=1 THEN
  156.                    pwm1b=25
  157.                    waitms 100
  158.                    pwm1b=255
  159.                    waitms 100
  160.                    IF PIND.3 = 1 THEN
  161.                             bip=0
  162.                             pwm1b=255
  163.                    END IF
  164.    END IF
  165.  
  166.    if  godzinaAlarmu = godziny AND minutaAlarmu <> minuty and bip=0 then
  167.     bip=1
  168.  
  169.    end if
  170.  
  171.  
  172.  
  173.  
  174.  '/////////////////////////////////////// Jasnosc ekranu
  175.      Liczba = Getadc(4)
  176.      Liczba = Liczba
  177.  
  178.  
  179.      If Liczba > 800 Then
  180.          If Jasnosc < 42 Then
  181.             Jasnosc = Jasnosc + 4
  182.  
  183.          End IF
  184.          If Jasnosc > 42 Then
  185.             Jasnosc = Jasnosc - 4
  186.  
  187.          End If
  188.      End If
  189.  
  190.      If Liczba < 800 And Liczba > 700 Then
  191.          If Jasnosc < 84 Then
  192.             Jasnosc = Jasnosc + 4
  193.  
  194.          End If
  195.          If Jasnosc > 84 Then
  196.             Jasnosc = Jasnosc - 4
  197.  
  198.          End If
  199.      End If
  200.  
  201.      If Liczba < 700 And Liczba > 600 Then
  202.          If Jasnosc < 126 Then
  203.             Jasnosc = Jasnosc + 4
  204.  
  205.          End If
  206.          If Jasnosc > 126 Then
  207.             Jasnosc = Jasnosc - 4
  208.  
  209.          End If
  210.      End If
  211.  
  212.      If Liczba < 600 And Liczba > 500 Then
  213.          If Jasnosc < 168 Then
  214.             Jasnosc = Jasnosc + 4
  215.  
  216.          End If
  217.          If Jasnosc > 168 Then
  218.             Jasnosc = Jasnosc - 4
  219.  
  220.          End If
  221.      End If
  222.  
  223.      If Liczba < 500 And Liczba > 400 Then
  224.          If Jasnosc < 210 Then
  225.             Jasnosc = Jasnosc + 4
  226.  
  227.          End If
  228.          If Jasnosc > 210 Then
  229.             Jasnosc = Jasnosc - 4
  230.  
  231.          End If
  232.      End If
  233.  
  234.      If Liczba < 400 Then
  235.          If Jasnosc < 250 Then
  236.             Jasnosc = Jasnosc + 4
  237.  
  238.          End If
  239.      End If
  240.  
  241.      Pwm1a = Jasnosc
  242.       'Lcd Jasnosc
  243.  
  244.  
  245.  
  246.  
  247.  
  248.  
  249.  
  250.  
  251. '////////////////////////////////////////////////// Wyswietlanie czasu
  252.  
  253.  
  254.  
  255.  If Licznik > 490 Then
  256.  cls
  257.  
  258.       upperline
  259.  
  260.       lcd chr(0)
  261.       Lcd "    "
  262.       if godziny < 10 then
  263.       lcd "0"
  264.       Lcd Godziny
  265.       else
  266.       lcd godziny
  267.       end if
  268.       lcd "::"
  269.       if minuty <10 then
  270.       lcd "0"
  271.       lcd Minuty
  272.       else
  273.       lcd minuty
  274.       end if
  275.  
  276.       lowerline
  277.  
  278.  
  279.       lcd chr(1)
  280.       Lcd "    "
  281.       if godzinaAlarmu < 10 then
  282.       lcd "0"
  283.       Lcd Godzinaalarmu
  284.       else
  285.       lcd godzinaalarmu
  286.       end if
  287.       lcd "::"
  288.       if minutaAlarmu <10 then
  289.       lcd "0"
  290.       lcd Minutaalarmu
  291.       else
  292.       lcd minutaalarmu
  293.       end if
  294.  End If
  295.  Waitms 10
  296. Loop
  297. End
  298.  
  299.  
  300.  
  301. Przerwanie_co_2ms:
  302.  
  303.  
  304. '////////////////////////// to chyba jest liczenie czasu
  305.    timer0 = 6
  306.    Incr Licznik
  307.    If Licznik = 500 Then
  308.       Sekundy = Sekundy + 1
  309.       Licznik = 0
  310.    End If
  311.    If Sekundy = 60 Then
  312.     Sekundy = 0
  313.     Minuty = Minuty + 1
  314.  End If
  315.    If Minuty = 60 Then
  316.     Minuty = 0
  317.     Godziny = Godziny + 1
  318.  End If
  319.    if godziny=24 then
  320.    godziny=0
  321.    end if
  322.  
  323. Return
  324.  
  325. pip:
  326.  
  327. if bip=1 then
  328. pwm1b=200
  329. waitms 250
  330. end if
  331. Return
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement