sombruxo

adc_activa

Apr 22nd, 2026
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
ASM (NASM) 1.49 KB | Source Code | 0 0
  1.  
  2. ldi r16, 0b11111111
  3. out ddrb, r16
  4. RCALL config_ADC ;Configurar el conversor ADC
  5. conv:
  6.     LDS r17, ADCSRA
  7.     ORI r17, (1<< ADSC)
  8.     STS ADCSRA, r17         ;Disparo la conversion AC to Digital
  9.     bit:
  10.         LDS r20, ADCSRA    
  11.         SBRC r20, ADSC      ;Espero que termine la conversion.
  12.         rjmp bit       
  13.     LDS r21, ADCH           ;Leo el valor de la conversion.
  14.     cpi r21, 127
  15.     if:
  16.         brlo else
  17.     then:
  18.         ldi r16, 0x00
  19.         out portb, r16
  20.         rjmp fin_if
  21.     else:
  22.         ldi r16, 0xff
  23.         out portb, r16
  24.     fin_if:
  25. rjmp conv
  26.  
  27.  
  28. config_ADC:
  29.     push r16
  30.     LDI R16, (1<<ADEN)
  31.     ;ADC Enable
  32.     ORI R16, (0<<ADATE)
  33.     ;ADC Auto Trigger Enable
  34.     ORI R16, (1<<ADPS2) | (1<<ADPS1) | (1<<ADPS0)
  35.     ;ADPSx=3: ADC Prescaler Select Bits (ADPS2:0=111 -> 128)
  36.     STS ADCSRA, R16
  37.     ;_> ADOSRA: The ADC Control and Status register A
  38.     LDI R16, (0<<ADTS2) | (0<<ADTS1) | (1<<ADTS0)
  39.     ;ADTSx-1: trigger source Analog Comparator
  40.     STS ADCSRB, R16
  41.     ;-> ADCSRB: The ADC Control and Status register B
  42.     LDI R16, (2<<MUX0)
  43.     ;MUXx-1: input channel 1: MUX5:0-00001
  44.     ORI R16, (0<<REFS1) | (1<<REFS0)
  45.     ;AREF-1: internal 5V reference (REF$1:0-01)
  46.     ORI R16, (1<<ADLAR)
  47.     ;ADC 8 bits resolution
  48.     STS ADMUX, R16
  49.     ; -> ADMUX: The ADC multiplexer Selection Register
  50.     LDI R16, (1<<ADC1D)
  51.     ;ADC disable digital input circuitry for channel 1 (saves energy)
  52.     STS DIDR0, R16
  53.     ; -> DIDRO: Digital Input Disable Register
  54.     LDI R16, (0<<PRADC)
  55.     ;ADC disable the power reduction saving for the ADC circuitry (not necesary)
  56.     STS PRR, R16
  57.     ;-> PRR: Power Reduction Register
  58.     pop r16
  59. RET
Advertisement
Add Comment
Please, Sign In to add comment