Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <at89c51cc03er.h>
- __sbit __at 0x91 BEEP;
- __sbit __at 0x92 LED1;
- __sbit __at 0x93 LED2;
- __sbit __at 0x94 LED3;
- __sbit __at 0x95 LED4;
- // Serielle Schnittstelle Initialisieren
- void initSerial(void)
- {
- SCON = 0x52; // 9600 Baud, 8 Datenbit, 1 Stopp-Bit, asynchroner Betrieb,
- TMOD |=0x20; // keine Paritätsprüfung.
- TH1 = 0xfd; //
- TR1 = 1; // Datenübertragungs-Parameter übernehmen
- TI = 1; // nichts übertragen
- }
- void clearscreen(void)
- {
- printf("\x1B[H"); //VT100: goto 0,0
- printf("\x1B[J"); //VT100: clear screen
- printf("rough values:\n");
- printf("----------\n");
- printf("poti outer:\n");
- printf("poti inner:\n");
- printf("\n");
- printf("precise values:\n");
- printf("----------\n");
- printf("poti outer:\n");
- printf("poti inner:");
- }
- void showValueWithLEDs(float value)
- {
- LED1=1;
- LED2=1;
- LED3=1;
- LED4=1;
- BEEP=1;
- if (value >= 1)
- {
- LED1 = 0;
- }
- if (value >= 2)
- {
- LED2 = 0;
- }
- if (value >= 3)
- {
- LED3 = 0;
- }
- if (value >= 4)
- {
- LED4 = 0;
- }
- if (value > 4.2 && value < 4.3)
- {
- BEEP = 0; //42 yeah
- }
- }
- void main(void)
- {
- int convResult = 0;
- int i = 0;
- initSerial();
- ADCF = 128+64; //P1.7 und P1.6 analog
- ADCON |= 32; //enable ADC
- clearscreen();
- while (1) {
- /*
- * rough values
- */
- ADCON &= 255-7; //clear channel selection
- ADCON |= 6; // set channel 6
- ADCON |= 8; // start conversion
- while ((ADCON & 16) == 0){} //wait for conversion to complete
- ADCON &= 255-16; //clear ADEOC
- convResult = ADDH;
- printf("\x1B[3;15H"); //place cursor
- printf("\x1B[K"); //clear to eofl
- printf_fast_f("%d\t= %fV\n", convResult, convResult*5/256.0);
- showValueWithLEDs(convResult*5/256.0);
- ADCON &= 255-7; //channel reset
- ADCON |= 7; //channel select
- ADCON |= 8; //start conversion
- while ((ADCON & 16) == 0){} //wait for completion
- ADCON &= 255-16; //clear ADCON
- convResult = ADDH;
- printf("\x1B[4;15H"); //place cursor
- printf("\x1B[K"); //clear to eofl
- printf_fast_f("%d\t= %fV\n", convResult, convResult*5/256.0);
- /*
- * precise values
- */
- ADCON &= 255-7; //clear channel selection
- ADCON |= 6; // set channel 6
- ADCON |= 64+8; // start conversion with high precision
- while ((ADCON & 16) == 0){} //wait for conversion to complete
- ADCON &= 255-16; //clear ADEOC
- convResult = (ADDH<<2)+ADDL;
- printf("\x1B[8;15H"); //place cursor
- printf("\x1B[K"); //clear to eofl
- printf_fast_f("%d\t= %fV\n", convResult, convResult*5/1024.0);
- ADCON &= 255-7; //channel reset
- ADCON |= 7; //channel select
- ADCON |= 64+8; //start conversion
- while ((ADCON & 16) == 0){} //wait for completion
- ADCON &= 255-16; //clear ADCON
- convResult = (ADDH<<2)+ADDL;
- printf("\x1B[9;15H"); //place cursor
- printf("\x1B[K"); //clear to eofl
- printf_fast_f("%d\t= %fV\n", convResult, convResult*5/1024.0);
- _wait_ms(250);
- if (i == 10)
- {
- clearscreen();
- i=-1;
- }
- i++;
- }
- }
Add Comment
Please, Sign In to add comment