0
我試圖從電位器讀取一個使用ADC的值,然後用它來設置我的延遲時間長度,這將在不同的時間間隔點亮不同的燈光(取決於輸入來自ADC)。我可能會犯一個簡單的錯誤。這是迄今爲止代碼:`ADC輸入不工作的代碼
`初始化:
LDI R16, HIGH(RAMEND) ;Initializing the r16 register
OUT SPH, R16
LDI R16, LOW(RAMEND)
OUT SPL, R16
LDI R16, 0xFF
OUT DDRB, R16 ;Initializes port B as output
LDI R16, 0x00
OUT DDRC, R16 ;Initializes port C as an input
LDI R16, 0b00000000; Initialize ADC port and reference voltage
STS ADMUX, R16
startADC:
LDI R16, 0b11000111
STS ADCSRA, R16 ;Begins converstion
KeepPolling:
LDI R16, ADCSRA
SBRS R16, 4 ;Checks if bit is set
RJMP KeepPolling ;If bit is not set, conversion continues
LDS R18, ADCL ;Loads ADCL value onto R16
LDS R16, ADCH ;Readvalue so resistor doesnt lock down
RCALL Green
Green:
MOV R16, R18 ;Load value of ADC to R24
SBI PORTB, 0b00000001 ;Output High to portb
RCALL loop
CBI PORTB, 0b00000001
RCALL Yellow ;Go to yellow if R24 is 0
Yellow:
MOV R16, R18 ;Load value of ADC to R24
LSR R16 ;Divide R24 by 2
SBI PORTB, 0b00000010 ;Output high to port B
CALL loop
CBI PORTB, 0b00000010
RCALL Red
Red:
MOV R16, R18
SBI PORTB, 0b00000011
RCALL loop
CBI PORTB, 0b00000011
RCALL startADC
loop:
MOV R20, R16
outer_loop:
LDI R24, 0
Add_Dec:
ADIW R24, 1
BRNE Add_Dec
DEC R20
BRNE outer_loop
RET
任何幫助將不勝感激。
我怎麼可能改變代碼,以便沒有用完堆棧空間?你能否詳細說明你評論的最後一部分,不太清楚我的理解是什麼意思?謝謝 – HerculesDev