Advertisement
Guest User

backup2

a guest
Oct 16th, 2018
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.92 KB | None | 0 0
  1.  
  2. ;JoyVRX = ADC3
  3. ;JoyVRY = ADC2
  4. ;JoySW = PB0
  5. ;FreqOut = PB1
  6. ;LEDA=grn
  7. ;LEDB=blu
  8. ;LEDC=red
  9. ; ThreshB = VRX>3.4V
  10. ; ThreshC = VRX<1.6V
  11. .INCLUDE <m328pdef.inc>
  12.  
  13. .org 0x0000 ; memory (PC) location of reset handler
  14. rjmp Reset
  15.  
  16. .EQU LED_C = 3
  17. .EQU LED_A = 4
  18. .EQU LED_B = 5
  19. .EQU Led_Port = PORTB
  20.  
  21. ;JoySW = PB0
  22. .EQU Switch_Pin = 0
  23. .EQU Switch_Port = PinB
  24.  
  25. Reset:
  26. ;Disable interrupts and configure stack pointer for 328P
  27. cli
  28. ldi r16,low(RAMEND) ; RAMEND address 0x08ff
  29. out SPL,r16 ; Stack Pointer Low SPL at i/o address 0x3d
  30. ldi r16,high(RAMEND) ; Stack Pointer High SPH at i/o address 0x3e
  31. out SPH,r16
  32.  
  33. INIT:
  34. ; Init the 3 output RGB LED's
  35. in r16,DDRB
  36. sbr r16,0b00111000
  37. out DDRB,r16
  38.  
  39. ; Init the input switch, configure with internal pull up resistor
  40. in r16,DDRB
  41. cbr r16,0b1000000
  42. out DDRB,r16
  43.  
  44. in r16,PORTB
  45. sbr r16,0b00000001
  46. out PORTB,r16
  47.  
  48. ;Initing ADC Pin: making all pins inputs
  49. in r16,DDRC
  50. sbr r16.0b00000000
  51.  
  52. ;ADC Control/Status reg
  53. ;Enabling ADC: 0x80 = 0b1000 and division factor of 128: 0x07 = 0b0111
  54. ldi r16,0x87
  55. sts ADCSRA,r16
  56.  
  57. ;ADC Muliplexer select reg
  58. ;Setting ref voltage to AVCC and left adjusting result; 0x60 = 0b0110
  59. ;Selecting VRX ADC pin ADC3: 0x03 = 0b0011
  60. ldi r16,0x63
  61. sts ADMUX,r16
  62.  
  63.  
  64.  
  65.  
  66. MAIN_LOOP:
  67. ; Switch pressed = Red Led on
  68. sbis Switch_Port, Switch_Pin
  69. sbi Led_Port, LED_A
  70.  
  71. ; Switch not pressed = Red Led off
  72. sbic Switch_Port, Switch_Pin
  73. cbi Led_Port, LED_A
  74.  
  75. RJMP MAIN_LOOP ; keep doing this indefinitely
  76.  
  77. ; Start an ADC Conversion
  78. ; Set ADSC bit
  79. lds r16,ADCSRA
  80. sbr r16,(1<<ADSC)
  81. sts ADCSRA,r16
  82.  
  83. ADC_Polling_Loop:
  84. ;check is ADIF bit is set
  85. lds r16, ADCSRA
  86. sbrs r16,ADIF
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement