int main(int argc, char *argv[]) { // Check input arguments if(argc>2){ printf("Too many arguments!\n"); exit(1); } else if(argc<2){ printf("Usage: (Start command) /path/to/target/file\n"); exit(1); } // Get user input file path. char *path = argv[1]; // Read and write loop. while (true){ gettemp(); writetemp(path); sleep(INTERVAL); } }
void main(void) { int i=0; // Declare your local variables here unsigned char devices; devices = w1_init(); // Crystal Oscillator division factor: 1 #pragma optsize- CLKPR=0x80; CLKPR=0x00; #ifdef _OPTIMIZE_SIZE_ #pragma optsize+ #endif // Input/Output Ports initialization // Port B initialization // Func7=Out Func6=Out Func5=Out Func4=Out Func3=Out Func2=Out Func1=Out Func0=Out // State7=0 State6=0 State5=0 State4=0 State3=0 State2=0 State1=0 State0=0 PORTB=0x00; DDRB=0xFF; // Port C initialization // Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In // State6=T State5=T State4=T State3=T State2=T State1=T State0=T PORTC=0x01; DDRC=0x01; // Port D initialization // Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In // State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=T PORTD=0b00000000; DDRD=0b01000000; // Timer/Counter 0 initialization // Clock source: System Clock // Clock value: Timer 0 Stopped // Mode: Normal top=0xFF // OC0A output: Disconnected // OC0B output: Disconnected TCCR0A=0x00; TCCR0B=0x00; TCNT0=0x00; OCR0A=0x00; OCR0B=0x00; // Timer/Counter 1 initialization // Clock source: System Clock // Clock value: Timer1 Stopped // Mode: Normal top=0xFFFF // OC1A output: Discon. // OC1B output: Discon. // Noise Canceler: Off // Input Capture on Falling Edge // Timer1 Overflow Interrupt: Off // Input Capture Interrupt: Off // Compare A Match Interrupt: Off // Compare B Match Interrupt: Off TCCR1A=0x00; TCCR1B=0x00; TCNT1H=0x00; TCNT1L=0x00; ICR1H=0x00; ICR1L=0x00; OCR1AH=0x00; OCR1AL=0x00; OCR1BH=0x00; OCR1BL=0x00; // Timer/Counter 2 initialization // Clock source: System Clock // Clock value: Timer2 Stopped // Mode: Normal top=0xFF // OC2A output: Disconnected // OC2B output: Disconnected ASSR=0x00; TCCR2A=0x00; TCCR2B=0x00; TCNT2=0x00; OCR2A=0x00; OCR2B=0x00; // External Interrupt(s) initialization // INT0: Off // INT1: Off // Interrupt on any change on pins PCINT0-7: Off // Interrupt on any change on pins PCINT8-14: Off // Interrupt on any change on pins PCINT16-23: Off EICRA=0x00; EIMSK=0x00; PCICR=0x00; // Timer/Counter 0 Interrupt(s) initialization TIMSK0=0x00; // Timer/Counter 1 Interrupt(s) initialization TIMSK1=0x00; // Timer/Counter 2 Interrupt(s) initialization TIMSK2=0x00; // USART initialization // Communication Parameters: 8 Data, 1 Stop, No Parity // USART Receiver: On // USART Transmitter: On // USART0 Mode: Asynchronous // USART Baud Rate: 9600 UCSR0A=0x00; UCSR0B=0x18; UCSR0C=0x06; UBRR0H=0x00; UBRR0L=0x33; // Analog Comparator initialization // Analog Comparator: Off // Analog Comparator Input Capture by Timer/Counter 1: Off ACSR=0x80; ADCSRB=0x00; DIDR1=0x00; // ADC initialization // ADC disabled ADCSRA=0x00; // SPI initialization // SPI disabled SPCR=0x00; // TWI initialization // TWI disabled TWCR=0x00; //printf("%u", devices); TCCR0A=0b10100011; //выбираем неинверсный режим шим дл¤ обоих светодиодов TCCR0B=0b00000001; for(i=0;i<256;i++) //увеличиваем ¤ркость первого диода, и уменьшаем ¤ркость второго каждые 10 мс { OCR0A=i; delay_ms(100); } while (1) { writetemp(); setPWM(temp); PORTB=0x00; delay_ms(3000); PORTB=0x01; delay_ms(3000); } /* devices=w1_search( DS18B20_SEARCH_ROM_CMD, RomCode ); if( devices ) { //printf("DS18B20 = "); printf(devices); // lcd_gotoxy( 0,1 ); lcd_puts( LcdBuffDevices ); lcd_gotoxy( 0,0 ); lcd_puts( str1 ); ds18b20_init( &RomCode[0][0], 30, 60, DS18B20_12BIT_RES ); // ds18b20_init( &RomCode[1][0], 30, 60, DS18B20_12BIT_RES ); // printf((int)DS18B20_12BIT_RES); while (1) { data=UDR0; printf("t1 %.2f \xefC", ds18b20_temperature( &RomCode[0][0] ) ); if(data=='1') { PORTB=0xFF; putchar('1'); printf("Hello, world!"); } if(data=='0') { PORTB=0x00; putchar('0'); } delay_ms(1000); } } else { printf("No devices");} */ }
int main(void) { int i, x, y; double u; char a[100], b[100]; FILE *f; TEST(i, !!(f=writetemp(" 42")), 1, "failed to make temp file"); if (f) { x=y=-1; TEST(i, fwscanf(f, L" %n%*d%n", &x, &y), 0, "%d != %d"); TEST(i, x, 6, "%d != %d"); TEST(i, y, 8, "%d != %d"); TEST(i, ftell(f), 8, "%d != %d"); TEST(i, !!feof(f), 1, "%d != %d"); fclose(f); } TEST(i, !!(f=writetemp("[abc123]....x")), 1, "failed to make temp file"); if (f) { x=y=-1; TEST(i, fwscanf(f, L"%10[^]]%n%10[].]%n", a, &x, b, &y), 2, "%d != %d"); TEST_S(a, "[abc123", "wrong result for %[^]]"); TEST_S(b, "]....", "wrong result for %[].]"); TEST(i, x, 7, "%d != %d"); TEST(i, y, 12, "%d != %d"); TEST(i, ftell(f), 12, "%d != %d"); TEST(i, feof(f), 0, "%d != %d"); TEST(i, fgetc(f), 'x', "%d != %d"); fclose(f); } TEST(i, !!(f=writetemp("0x1p 12")), 1, "failed to make temp file"); if (f) { x=y=-1; u=-1; TEST(i, fwscanf(f, L"%lf%n %d", &u, &x, &y), 0, "%d != %d"); TEST(u, u, -1.0, "%g != %g"); TEST(i, x, -1, "%d != %d"); TEST(i, y, -1, "%d != %d"); TEST(i, ftell(f), 4, "%d != %d"); TEST(i, feof(f), 0, "%d != %d"); TEST(i, fgetc(f), ' ', "%d != %d"); rewind(f); TEST(i, fgetc(f), '0', "%d != %d"); TEST(i, fgetc(f), 'x', "%d != %d"); TEST(i, fwscanf(f, L"%lf%n%c %d", &u, &x, a, &y), 3, "%d != %d"); TEST(u, u, 1.0, "%g != %g"); TEST(i, x, 1, "%d != %d"); TEST(i, a[0], 'p', "%d != %d"); TEST(i, y, 12, "%d != %d"); TEST(i, ftell(f), 7, "%d != %d"); TEST(i, !!feof(f), 1, "%d != %d"); fclose(f); } TEST(i, !!(f=writetemp("0x.1p4 012")), 1, "failed to make temp file"); if (f) { x=y=-1; u=-1; TEST(i, fwscanf(f, L"%lf%n %i", &u, &x, &y), 2, "%d != %d"); TEST(u, u, 1.0, "%g != %g"); TEST(i, x, 6, "%d != %d"); TEST(i, y, 10, "%d != %d"); TEST(i, ftell(f), 13, "%d != %d"); TEST(i, !!feof(f), 1, "%d != %d"); fclose(f); } TEST(i, !!(f=writetemp("0xx")), 1, "failed to make temp file"); if (f) { x=y=-1; TEST(i, fwscanf(f, L"%x%n", &x, &y), 0, "%d != %d"); TEST(i, x, -1, "%d != %d"); TEST(i, y, -1, "%d != %d"); TEST(i, ftell(f), 2, "%d != %d"); TEST(i, feof(f), 0, "%d != %d"); fclose(f); } return t_status; }