Hallo,
Betrifft Pic 16F676
Ich will über einen Spannungsteiler am Port RC0/AN4 die Spannung eines
AKKUS lesen und in einen Digitalen Wert zur späteren Verarbeitung aus
dem
ADRESL *ADRESH Register auslesen.
Ich habe das Programm nur mit dem Debugger getestet und da fest gestellt
das der A/D Wandler startet aber mit der commando zeile
while (ADCON0.GO_DONE==1); //prüfen ob noch aktiv
nicht stoppt. Was ist falsch ??
Im Anschluss noch das Programm.
Gruß Karl-Heinz
// Define
#define LED1 PORTC.RC5 //LED low liegt an Port RC5
// Globale Variablen
int analog_hexwert;
void main(void) {
TRISC = 0x07; //set C-Port 0-2 in 3-5 out
PORTC = 0x00; //set C-Port all bit to 0V
ADCON0 = 0x80; //set analog module right justified
ADCON1 = 0x20; //set clock select Fosc32
ANSEL = 0x70; //select ANS 4 to analog input
while(1)
{
ADCON0.ADON = 1;
ADCON0.CHS2 = 1;
ADCON0.GO_DONE = 1; //messen ein
while (ADCON0.GO_DONE==1); //prüfen ob noch aktiv
Delay_ms (550);
analog_hexwert = ADRESL + (ADRESH * 256);
}
if (analog_hexwert < 500)
{
LED1 =1;
}
}
Bitte melde dich an um einen Beitrag zu schreiben. Anmeldung ist kostenlos und dauert nur eine Minute.
Bestehender Account
Schon ein Account bei Google/GoogleMail? Keine Anmeldung erforderlich!
Mit Google-Account einloggen
Mit Google-Account einloggen
Noch kein Account? Hier anmelden.