static void cmd_adc(Stream *chp, int argc, char* argv[]) { (void)argc; (void)argv; int32_t temp = adc_read_temp(); chprintf(chp,"Temperature = %d\r\n", temp); int32_t inp = adc_read_input(); chprintf(chp,"Input = %d\r\n", inp); }
//***************************************************************************************** // // Function : print_temp // Description : Print ADC0 and temparature to buffer // //***************************************************************************************** void print_temp ( BYTE *dest ) { WORD adc0_value; BYTE temp_value; adc0_value = adc_read ( 0 ); temp_value = adc_read_temp ( ); dest = print_decimal ( dest, 4, adc0_value ); *dest++ = ','; dest = print_decimal ( dest, 2, temp_value ); *dest++ = ASCII_DEGREE; *dest++ = 'C'; *dest = '\0'; }
//***************************************************************************************** // // Function : main // Description : main program, // //***************************************************************************************** int main (void) { // change your mac address here avr_mac.byte[0] = 'A'; avr_mac.byte[1] = 'V'; avr_mac.byte[2] = 'R'; avr_mac.byte[3] = 'P'; avr_mac.byte[4] = 'O'; avr_mac.byte[5] = 'R'; // read avr and server ip from eeprom eeprom_read_block ( &avr_ip, ee_avr_ip, 4 ); eeprom_read_block ( &server_ip, ee_server_ip, 4 ); // setup port as input and enable pull-up SW_DDR &= ~ ( _BV( SW_MENU ) | _BV( SW_EXIT ) | _BV( SW_UP ) | _BV( SW_DW ) ); SW_PORT |= _BV( SW_MENU ) | _BV( SW_EXIT ) | _BV( SW_UP ) | _BV( SW_DW ); SFIOR &= ~_BV( PUD ); // setup lcd backlight as output LCD_BL_DDR |= _BV( LCD_BL_PIN ); // lcd backlight on LCD_BL_PORT |= _BV( LCD_BL_PIN ); // setup clock for timer1 TCCR1B = 0x01; // clk/1 no prescaling // initial adc, lcd, and menu adc_init(); lcd_init (); menu_init (); // set LED1, LED2 as output */ LED_DDR |= _BV( LED_PIN1_DDR ) | _BV( LED_PIN2_DDR ); // set LED pin to "1" ( LED1,LED2 off) LED_PORT |= _BV( LED_PIN1 ) | _BV( LED_PIN2 ); // initial enc28j60 enc28j60_init( (BYTE*)&avr_mac ); // loop forever for(;;) { // wait until timer1 overflow while ( (TIFR & _BV ( TOV1 )) == 0 ); TIFR |= _BV(TOV1); TCNT1 = 1536; // Timer1 overflow every 1/16MHz * ( 65536 - 1536 ) = 4ms, 250Hz // general time base, generate by timer1 // overflow every 1/250 seconds time_base (); // read temparature adc_read_temp(); // server process response for arp, icmp, http server_process (); // send temparature to web server unsing http protocol // disable by default. client_process (); // lcd user interface menu // setup IP address, countdown timer menu_process (); // display AVR ethernet status // temparature, AVR ip, server ip, countdown time standby_display (); } return 0; }