Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ;JoyVRX = ADC3
- ;JoyVRY = ADC2
- ;JoySW = PB0
- ;FreqOut = PB1
- ;LEDA=grn
- ;LEDB=blu
- ;LEDC=red
- ; ThreshB = VRX>3.4V
- ; ThreshC = VRX<1.6V
- .INCLUDE <m328pdef.inc>
- .org 0x0000 ; memory (PC) location of reset handler
- rjmp Reset
- .EQU LED_C = 3
- .EQU LED_A = 4
- .EQU LED_B = 5
- .EQU Led_Port = PORTB
- ;JoySW = PB0
- .EQU Switch_Pin = 0
- .EQU Switch_Port = PinB
- Reset:
- ;Disable interrupts and configure stack pointer for 328P
- cli
- ldi r16,low(RAMEND) ; RAMEND address 0x08ff
- out SPL,r16 ; Stack Pointer Low SPL at i/o address 0x3d
- ldi r16,high(RAMEND) ; Stack Pointer High SPH at i/o address 0x3e
- out SPH,r16
- INIT:
- ; Init the 3 output RGB LED's
- in r16,DDRB
- sbr r16,0b00111000
- out DDRB,r16
- ; Init the input switch, configure with internal pull up resistor
- in r16,DDRB
- cbr r16,0b1000000
- out DDRB,r16
- in r16,PORTB
- sbr r16,0b00000001
- out PORTB,r16
- ;Initing ADC Pin: making all pins inputs
- in r16,DDRC
- sbr r16.0b00000000
- ;ADC Control/Status reg
- ;Enabling ADC: 0x80 = 0b1000 and division factor of 128: 0x07 = 0b0111
- ldi r16,0x87
- sts ADCSRA,r16
- ;ADC Muliplexer select reg
- ;Setting ref voltage to AVCC and left adjusting result; 0x60 = 0b0110
- ;Selecting VRX ADC pin ADC3: 0x03 = 0b0011
- ldi r16,0x63
- sts ADMUX,r16
- MAIN_LOOP:
- ; Switch pressed = Red Led on
- sbis Switch_Port, Switch_Pin
- sbi Led_Port, LED_A
- ; Switch not pressed = Red Led off
- sbic Switch_Port, Switch_Pin
- cbi Led_Port, LED_A
- RJMP MAIN_LOOP ; keep doing this indefinitely
- ; Start an ADC Conversion
- ; Set ADSC bit
- lds r16,ADCSRA
- sbr r16,(1<<ADSC)
- sts ADCSRA,r16
- ADC_Polling_Loop:
- ;check is ADIF bit is set
- lds r16, ADCSRA
- sbrs r16,ADIF
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement