Ejemplo n.º 1
0
void clock_print(){

	serial_print_dec(clock_hours, 2);		
	serial_printf(":");
	serial_print_dec(clock_mins, 2);
	serial_printf(".");
	serial_print_dec(clock_secs, 2);
		
	return;	
}
Ejemplo n.º 2
0
void main()
{
    init();

    while (1) {

        // Allow wakeup
        delay_ms(100);

        // Reset the one wire bus
        oo_busreset();

        // Start the temparature conversion (non-blocking function)
        oo_start_conversion();

        // Wait for completion, you could do other stuff here
        // But make sure that this function returns zero before
        // reading the scratchpad
        if (oo_wait_for_completion() == 1) {
            serial_printf("Temperature conversion timed out");
        }

        // Read the scratchpad
        if (oo_read_scratchpad()) {
            serial_printf("OO read scratchpad failed");
            while(1);
        }

        // And extract the temperature information
        short temp = oo_get_temp();

        // The temperature is
        serial_printf("Temperature: ");
        serial_print_hex(temp);
        serial_printf(" -- ");

        // And for positive temps you can simply convert this to
        char tmp_work = (char)(temp >> 1);
        serial_print_dec(tmp_work);
        if (temp & 0x0001) {
            serial_printf(".5");
        } else {
            serial_printf(".0");
        }
        serial_printf(" degrees C.\r\n");

        // A more accurate conversion is described in the DS1820 datasheet.

        delay_s(1);
    }

}
Ejemplo n.º 3
0
void main()
{
	init();

	while (1){
	
		char input;
		// Check if something was received from the serial port
		if (serial_peek()){
			// If it was, go get it...
			input = serial_getch();
			
			// Print it as 'char'
			serial_printf("You have pressed the key: ");
			serial_printf(input);
			serial_print_lf();
			
			serial_printf("It has the following value:\r\n");
			
			// Print it as hex value
			serial_printf(" * hex: ");
			serial_print_hex(input);
			serial_print_lf();
			
			// Print it as decimal value
			serial_printf(" * dec: ");
			serial_print_dec(input);
			serial_print_lf();
				
			// Print it as binary value
			serial_printf(" * bin: ");
			serial_print_bin(input);
			serial_print_lf();

		    // Show off the function overloading  ;-)
			serial_printf("\r\nYou can also print shorts in hex format: 0x");
			serial_print_hex((short)0xBABE);
			serial_print_lf();
		}
	}
	
}