daily pastebin goal
16%
SHARE
TWEET

Untitled

a guest Dec 9th, 2018 64 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2. light dimmer na nekom pinu pomocu timera, tako da se intenzitet svijetla mijenja promjenom omjera popunjenosti (DC-om),
  3. treba priložiti proračun svega
  4. */
  5.  
  6. .def tmp = r16
  7. .def step = r17
  8. .def ocval = r18
  9. .equ delayCnt = 10
  10. .cseg
  11.     rjmp reset
  12.  
  13. reset:
  14.     ldi tmp, high(RAMEND)
  15.     out SPH, tmp
  16.     ldi tmp, low(RAMEND)
  17.     out SPL, tmp
  18.  
  19.     ldi tmp, 0x03
  20.     out PORTB, tmp
  21.  
  22.     ldi tmp, 0
  23.     out DDRB, tmp
  24.  
  25.     ldi tmp, (1 << PD5)
  26.     out DDRD, tmp
  27.  
  28.     ldi tmp, (1 << COM1A0) | (COM1A1) | (1 << WGM10)
  29.     out TCCR1A, tmp
  30.  
  31.     ldi tmp, (1 << WGM12) | (CS11)
  32.     out TCCR1B, tmp
  33.    
  34.     ldi tmp, high(128)
  35.     out OCR1AH, tmp
  36.     ldi tmp, low(128)
  37.     out OCR1AL, tmp
  38.  
  39.     ldi ocval, 0x00
  40.     ldi step, 0x0A
  41.  
  42. main:
  43.     sbis PINB, 0
  44.         rcall smanji
  45.     sbis PINB, 1
  46.         rcall povecaj
  47.  
  48.     rcall delay
  49. rjmp main
  50.  
  51. smanji:
  52.     ldi tmp, 248
  53.     in ocval, OCR1AL
  54.  
  55.     cpse tmp, ocval
  56.         add ocval, step
  57.  
  58.     out OCR1AL, ocval
  59. ret
  60.  
  61. povecaj:
  62.     ldi tmp, 8
  63.     in ocval, OCR1AL
  64.  
  65.     cpse tmp, ocval
  66.         sub ocval, step
  67.  
  68.     out OCR1AL, ocval
  69. ret
  70.  
  71. delay:
  72.     push r17
  73.     push r18
  74.     push r19
  75.  
  76.     clr r17
  77.     clr r18
  78.     ldi r19, delayCnt
  79.  
  80.     delay_loop:
  81.         dec r17
  82.         brne delay_loop
  83.             dec r18
  84.             brne delay_loop
  85.                 dec r19
  86.                 brne delay_loop
  87.  
  88.     pop r19
  89.     pop r18
  90.     pop r17
  91. ret
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top