//--------------------------------------------------------------------------------------- void main(void) { if(BD == 0) // Baudratengenerator noch nicht aktiv init_seriell(); // serielle Kommunikation ermöglichen init_timer0(); // Timer 0 initialisieren init_ad(); init_p33(); EAL=1; // Interrupts generell freigegeben while(1) // Endlos { maske=0x01; sec=0; // Sec reset printstring("Portpin: "); // Portpin Eingabeaufforderung pin=getchar(); // Einlesen putchar(pin); putchar('\n'); printstring("Vorwahl: "); // Eingabeaufforderung ADDATL=1; while(BSY==1); vorwahl=ad10bit/100; printuintdez(vorwahl); putchar('s'); pin-=0x30; // ASCII Konvertierung maske=maske<<pin; // Pin in maske schieben P5=P5&~maske; // LED an TR0=1; // Timer0 starten while(vorwahl!=sec); // Warten bis die Zeit erreicht wurde P5=P5|maske; // LED aus TR0=0; // Timer 0 stoppen } }
///////////////////////// // Simple application. void main (void) { unsigned char cdata[4]={0,0,0,0}; unsigned char status; unsigned long conv = 0; unsigned char buf[14]; unsigned char na = 0; float reads = 0; float avr = 0; ///////////////////////////////////////////////////////////////////// // Initialize lcd init_lcd(); // Initialize LTC2440 init_ad(); // Turn off blinking cursor control (BLINK_OFF_CURSOR_OFF); // Clean lcd screen clr_lcd(); // Display first message wrstr_lcd (" LTC2440 TEST"); locate_lcd(1, 0); wrstr_lcd (" DIGITAL VOLTMETER "); delay (30000); clr_lcd(); // Screen template locate_lcd(0, 0); wrstr_lcd ("INPUT: "); while (1) { if (LTC2440_eoc() == IDLE) { delay(300); } else { // Get status and raw conversion from ADC status = LTC2440_rd(&cdata) ; conv = LTC2440_get_value (&cdata); // Test if Over or Under flow if (status == ADOVF) sprintf (buf, "%s ", "+++ OVL +++ "); else if (status == ADUNF) sprintf (buf, "%s ", "--- UNF --- "); else { // If readings are valid convert in signed floating number if (status == (ADRDY | ADOVF)) reads = (float) (conv * VREF) / RANGE ; else if (status == (ADRDY | ADUNF)) reads = (float) (conv * VREF) / RANGE - VREF ; // Add averages if (na++ < MAXAVR) avr += reads; else { // Display averaged value sprintf (buf, "%+1.7f V", avr/(na-1)); na = 0; avr = 0; } } } // display value in the right position. locate_lcd(0, 7); wrstr_lcd (buf); } }