Code:
// nibobee: LCD 20x4 (LMC-SSC4A20) an Port C 28.12.2009 mic
#include <nibobee/iodefs.h>
#include <nibobee/base.h>
#include <nibobee/analog.h>
#include <nibobee/motpwm.h>
#include <nibobee/line.h>
#include <nibobee/delay.h>
#include <nibobee/led.h>
#include <stdlib.h>
#include "lcd_lib.h"
void Msleep(uint16_t pause_ms) // für LCD-LIB
{
delay(pause_ms);
}
void do_blink(uint8_t mask)
{
uint8_t i;
for (i=0; i<5; ++i)
{
led_set(LED_L_RD, mask&0x01);
led_set(LED_R_RD, mask&0x01);
led_set(LED_L_YE, mask&0x02);
led_set(LED_R_YE, mask&0x02);
delay(200);
led_set(LED_L_RD, 0);
led_set(LED_R_RD, 0);
led_set(LED_L_YE, 0);
led_set(LED_R_YE, 0);
delay(200);
}
}
void liniensensoren_kalibrieren(void)
{
lcd_cls(); // lcd Inhalt löschen
lcd_locate(2,0);
lcd_writeString("Kalibrieren");
lcd_locate(2,3);
lcd_writeString("Abbruch Sav sw ws");
line_readPersistent();
while(lcd_getkeys()<7)
{
if (lcd_getkeys()==1)
{
while (lcd_getkeys()==1) delay(1);
line_calibrateWhite();
do_blink(2);
}
if (lcd_getkeys()==2)
{
while (lcd_getkeys()==2) delay(1);
line_calibrateBlack();
do_blink(1);
}
set_output_groupbitval(IO_LEDS, L_YE, line_get(LINE_L)>160);
set_output_groupbitval(IO_LEDS, L_RD, line_get(LINE_L)>240);
set_output_groupbitval(IO_LEDS, R_YE, line_get(LINE_R)>160);
set_output_groupbitval(IO_LEDS, R_RD, line_get(LINE_R)>240);
if (lcd_getkeys()==4)
{
while (lcd_getkeys()==4)
{
delay(1);
}
line_writePersistent();
do_blink(3);
}
while(lcd_getkeys());
delay(100);
}
}
// https://www.roboternetz.de/phpBB2/viewtopic.php?t=51863
int Batterie(void)
{
unsigned char temp1,temp2;
uint16_t ADCresult;
while ((ADMUX & 0x07) != 0x04);
cli();
while (!(ADCSRA & (1 << ADIF))); // wait for conversion complete
ADCSRA |= (1 << ADIF); // clear ADCIF
//Registerinhalte retten
temp1 = ADCSRA;
temp2 = ADMUX;
ADMUX = (1 << REFS0) | (1 << REFS1) | ANALOG_VOLT; //internal 2.56V reference with external capacitor
//ADCSRA löschen und neu setzen
ADCSRA = 0;
ADCSRA |= ((1 << ADPS2) | (1 << ADPS1) | (1 << ADPS0)); //ADC clock = Clock/128
ADCSRA |= (1 << ADEN); //Enable ADC (das aktiviert die 2.56V Referenz)
//Warten bis Kondensator an ARef = 2.56V hat
//Messung an ARef ergab 1,2msec
delay(6); // = ca. 5*Tau
//1. ADC Wandlung starten und Ergebnis ignorieren
ADCSRA |= (1 << ADSC); // Start conversion
while (!(ADCSRA & (1 << ADIF))); // wait for conversion complete
ADCSRA |= (1 << ADIF); // clear ADCIF
//2. ADC Wandlung starten und Ergebnis übernehmen
ADCSRA |= (1 << ADSC); // Start conversion
while (!(ADCSRA & (1 << ADIF))); // wait for conversion complete
ADCSRA |= (1 << ADIF); // clear ADCIF
ADCresult = ADCL + (ADCH << 8);
//Registerinhalte wiederherstellen
ADMUX = temp2;
ADCSRA = temp1 & ~(1 << ADSC);
//Warten bis Kondensator an ARef = AVcc hat
//Messung ergab sehr steile Flanke
delay(2); //nicht notwendig, nur zur Sicherheit
ADCSRA |= (1 << ADSC); // Start conversion
sei();
return ADCresult;
}
int main(void)
{
uint8_t i=0; // Hilfsvariable
analog_init(); // ist ätzend die Libteile einzubinden...
line_init();
motpwm_init();
enable_interrupts();
led_init();
lcd_init(); // lcd initialisieren
lcd_cls(); // lcd Inhalt löschen
lcd_locate(2,0);
lcd_writeString("NIBOBee mit LCD");
lcd_locate(4,2);
lcd_writeString("28.12.09 mic");
led_set(0,1);
delay(2000);
led_set(0,0);
lcd_locate(0,2);
lcd_writeString("Bitte Taste druecken");
while(!lcd_getkeys());
i=16;
while(1)
{
if(i & 8) led_set(0,1); else led_set(0,0);
if(i & 4) led_set(1,1); else led_set(1,0);
if(i & 2) led_set(2,1); else led_set(2,0);
if(i & 1) led_set(3,1); else led_set(3,0);
if(i & 16)
{
lcd_init();
while(lcd_getkeys());
delay(100);
while(!lcd_getkeys());
if(lcd_getkeys() & 8) liniensensoren_kalibrieren();
lcd_cls();
lcd_writeString("Liniensensoren");
while(lcd_getkeys());
lcd_locate(0,1);
lcd_writeString("L:");
lcd_locate(0,2);
lcd_writeString("C:");
lcd_locate(0,3);
lcd_writeString("R:");
i=0;
}
if(i & 1)
{
motpwm_setLeft(-1000);
motpwm_setRight(-1000);
}
else if(i & 2)
{
motpwm_setLeft(1000);
motpwm_setRight(1000);
}
else if(i & 4)
{
motpwm_setLeft(0);
motpwm_setRight(1000);
}
else if(i & 8)
{
motpwm_setLeft(1000);
motpwm_setRight(0);
}
else
{
motpwm_setLeft(0);
motpwm_setRight(0);
}
lcd_locate(15,0);
lcd_writeInteger(Batterie(),10);
lcd_locate(3,1);
lcd_writeInteger(line_get(LINE_L),10);
lcd_writeString(" ");
lcd_writeInteger(analog_getValue(ANALOG_L0),10);
lcd_writeString(" ");
lcd_writeInteger(analog_getValue(ANALOG_L1),10);
lcd_writeString(" ");
lcd_locate(3,2);
lcd_writeInteger(line_get(LINE_C),10);
lcd_writeString(" ");
lcd_writeInteger(analog_getValue(ANALOG_C0),10);
lcd_writeString(" ");
lcd_writeInteger(analog_getValue(ANALOG_C1),10);
lcd_writeString(" ");
lcd_locate(3,3);
lcd_writeInteger(line_get(LINE_R),10);
lcd_writeString(" ");
lcd_writeInteger(analog_getValue(ANALOG_R0),10);
lcd_writeString(" ");
lcd_writeInteger(analog_getValue(ANALOG_R1),10);
lcd_writeString(" ");
delay(100);
i=lcd_getkeys();
}
return 0;
}
Das Spannungsproblem dürfte mit meinen AAs nicht so dramatisch sein. Zur Darstellung der Werte ohne LCD: Lass dir die Werte doch blicken. Eine LED blinkt nacheinander die Ziffer der jeweiligen Stelle. Oder du "sendest" die Bits des Wertes in Nipples aufgeteilt nacheinender: 0123 4567 89. Zwischen den Nipples eine kurze Pause, zwischen den Werten jeweils eine ängere Pause:
Lesezeichen