Cos'è ElectroYou | Login Iscriviti

ElectroYou - la comunità dei professionisti del mondo elettrico

Listato basic con problema adc

Raccolta di codici sorgenti

Moderatore: Foto UtentePaolino

0
voti

[1] Listato basic con problema adc

Messaggioda Foto Utentemattia281193 » 20 nov 2011, 21:32

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.
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.
Avatar utente
Foto Utentemattia281193
26 4
Frequentatore
Frequentatore
 
Messaggi: 132
Iscritto il: 1 ott 2011, 13:38

0
voti

[2] Re: Listato basic con problema adc

Messaggioda Foto UtentePaolino » 20 nov 2011, 21:48

Con quale micro stai lavorando?

Ciao.

Paolo.
"Houston, Tranquillity Base here. The Eagle has landed." - Neil A.Armstrong

-------------------------------------------------------------

PIC Experience - http://www.picexperience.it
Avatar utente
Foto UtentePaolino
32,6k 8 12 13
G.Master EY
G.Master EY
 
Messaggi: 4226
Iscritto il: 20 gen 2006, 11:42
Località: Vigevano (PV)

0
voti

[3] Re: Listato basic con problema adc

Messaggioda Foto Utentemattia281193 » 20 nov 2011, 21:49

PIC 16f876 a 8mhz
Avatar utente
Foto Utentemattia281193
26 4
Frequentatore
Frequentatore
 
Messaggi: 132
Iscritto il: 1 ott 2011, 13:38

0
voti

[4] Re: Listato basic con problema adc

Messaggioda Foto UtentePaolino » 21 nov 2011, 9:01

PIC16F876-04 oppure PIC16F876-20?
Attenzione che se usi il PIC16F876-04 non puoi fare overclock e farlo funzionare a 8 MHz.

Edit:
Alcuni punti restano a me un po' oscuri. Per esempio:
- come ricevi il dato dal dispositivo RX? Via seriale? Usando un interrupt o in polling?
- il ritardo posto dopo la conversione A/D, a che pro lo hai messo?
- stai usando MikroBASIC o altro?

Ciao.

Paolo.
"Houston, Tranquillity Base here. The Eagle has landed." - Neil A.Armstrong

-------------------------------------------------------------

PIC Experience - http://www.picexperience.it
Avatar utente
Foto UtentePaolino
32,6k 8 12 13
G.Master EY
G.Master EY
 
Messaggi: 4226
Iscritto il: 20 gen 2006, 11:42
Località: Vigevano (PV)

0
voti

[5] Re: Listato basic con problema adc

Messaggioda Foto Utentemattia281193 » 21 nov 2011, 16:13

non fa niente ho cambiato l'hw comunque grazie e dal rx arrivano 4 bit ottenuti da 4 transistor a collettore aperto con apposita R di pull up
comunque il PIC è 04 ma a 8mhz ha sempre funzionato :(
Avatar utente
Foto Utentemattia281193
26 4
Frequentatore
Frequentatore
 
Messaggi: 132
Iscritto il: 1 ott 2011, 13:38

0
voti

[6] Re: Listato basic con problema adc

Messaggioda Foto UtentePaolino » 21 nov 2011, 16:21

Mmh, cambia quarzo, passa a 4MHz!

E cosa mi dici delle altre domande che ti ho posto?

Ciao.

Paolo.
"Houston, Tranquillity Base here. The Eagle has landed." - Neil A.Armstrong

-------------------------------------------------------------

PIC Experience - http://www.picexperience.it
Avatar utente
Foto UtentePaolino
32,6k 8 12 13
G.Master EY
G.Master EY
 
Messaggi: 4226
Iscritto il: 20 gen 2006, 11:42
Località: Vigevano (PV)

0
voti

[7] Re: Listato basic con problema adc

Messaggioda Foto Utentemattia281193 » 21 nov 2011, 16:25

arrivano in maniera parallela tipo pin10=1 pin9=0 pin8=0 pin7=1 O_/
Avatar utente
Foto Utentemattia281193
26 4
Frequentatore
Frequentatore
 
Messaggi: 132
Iscritto il: 1 ott 2011, 13:38

0
voti

[8] Re: Listato basic con problema adc

Messaggioda Foto UtentePaolino » 21 nov 2011, 16:41

Dai, ce la puoi fare: leggi il post [4] e vedrai che ci sono altre domande.

Ciao.

Paolo.
"Houston, Tranquillity Base here. The Eagle has landed." - Neil A.Armstrong

-------------------------------------------------------------

PIC Experience - http://www.picexperience.it
Avatar utente
Foto UtentePaolino
32,6k 8 12 13
G.Master EY
G.Master EY
 
Messaggi: 4226
Iscritto il: 20 gen 2006, 11:42
Località: Vigevano (PV)

0
voti

[9] Re: Listato basic con problema adc

Messaggioda Foto Utentemattia281193 » 21 nov 2011, 16:58

micro basic :lol:
Avatar utente
Foto Utentemattia281193
26 4
Frequentatore
Frequentatore
 
Messaggi: 132
Iscritto il: 1 ott 2011, 13:38

0
voti

[10] Re: Listato basic con problema adc

Messaggioda Foto UtentePaolino » 21 nov 2011, 17:08

Ma guarda che puoi rispondere a tutte le domande in un unico post ;-)

Cosa mi dici del ritardo? (cfr sempre il mio post [4])

Ciao.

Paolo.
"Houston, Tranquillity Base here. The Eagle has landed." - Neil A.Armstrong

-------------------------------------------------------------

PIC Experience - http://www.picexperience.it
Avatar utente
Foto UtentePaolino
32,6k 8 12 13
G.Master EY
G.Master EY
 
Messaggi: 4226
Iscritto il: 20 gen 2006, 11:42
Località: Vigevano (PV)

Prossimo

Torna a Firmware e programmazione

Chi c’è in linea

Visitano il forum: Nessuno e 9 ospiti