Listato basic con problema adc
ciao a tutti ho un problema con questo listato ,praticamente serve per far accendere e spengere le luci con una stessa combinazione a 4 bit proveniente da un rx ,funziona ma quando ho aggiunto un interruttore crepuscolare nel programma utilizzando l'adc, la codifica dei 4 bit d'ingresso funziona ma l'adc no.
ho provato anche a fare un listato a parte uguale a quello che ho aggiunto e funziona, ma tutti e due insieme no.
programma di prova funzionante
ho provato anche a fare un listato a parte uguale a quello che ho aggiunto e funziona, ma tutti e due insieme no.
- Codice: Seleziona tutto
program luci1
' Declarations section
const sala as byte[2]=(0,1)
dim k as byte
const bagno as byte[2]=(0,1)
dim ba as byte
const cucina as byte[2]=(0,1)
dim cu as byte
const cam1 as byte[2]=(0,1)
dim ca1 as byte
const cam2 as byte[2]=(0,1)
dim ca2 as byte
dim tempo as byte
dim volt as word
main:
adcon1=$80
trisa=%111111
trisc=%11111111
trisb=0
k=0
ba=0
cu=0
ca1=0
ca2=0
while true
volt=adc_read(0)
delay_ms(10)
'giardino crepuscolare'
if (volt>=0) and (volt<409) then
portb.5=1
end if
if (volt>=409) and (volt<921) then
portb.5=0
end if
'sala'
if (portc=112) and (k<1) then
k=k+1
while portc=112
wend
end if
if (portc=112) and (k>0) then
k=k-1
while portc=112
wend
end if
'bagno'
if (portc=176) and (ba<1) then
ba=ba+1
while portc=176
wend
end if
if (portc=176) and (ba>0) then
ba=ba-1
while portc=176
wend
end if
'cucina'
if (portc=48) and (cu<1) then
cu=cu+1
while portc=48
wend
end if
if (portc=48) and (cu>0) then
cu=cu-1
while portc=48
wend
end if
'cam1'
if (portc=208) and (ca1<1) then
ca1=ca1+1
while portc=208
wend
end if
if (portc=208) and (ca1>0) then
ca1=ca1-1
while portc=208
wend
end if
'cam2'
if (portc=80) and (ca2<1) then
ca2=ca2+1
while portc=80
wend
end if
if (portc=80) and (ca2>0) then
ca2=ca2-1
while portc=80
wend
end if
portb.0=sala[k]
portb.1=bagno[ba]
portb.2=cucina[cu]
portb.3=cam1[ca1]
portb.4=cam2[ca2]
for tempo =0 to 2
delay_ms(1000)
next tempo
wend
end.
programma di prova funzionante
- Codice: Seleziona tutto
program crepa
dim volt as word
main:
adcon1=$80
trisa=%111111
trisb=0
while true
volt=adc_read(0)
delay_ms(10)
'giardino crepuscolare'
if (volt>=0) and (volt<409) then
portb.5=1
end if
if (volt>=409) and (volt<921) then
portb.5=0
end if
wend
end.
