document.write('
Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. #include <stdlib.h>
  2. #include <mega8.h>
  3. #include <delay.h>
  4. #include <alcd.h>
  5. #include <LM35.h>
  6. #define ADC_VREF_TYPE ((0<<REFS1) | (1<<REFS0) | (0<<ADLAR))
  7.  
  8. float celcius; char bf[20];
  9.  
  10. // Read the AD conversion result
  11. unsigned int read_adc(unsigned char adc_input)
  12. {
  13. ADMUX=adc_input | ADC_VREF_TYPE;
  14. // Delay needed for the stabilization of the ADC input voltage
  15. delay_us(10);
  16. // Start the AD conversion
  17. ADCSRA|=(1<<ADSC);
  18. // Wait for the AD conversion to complete
  19. while ((ADCSRA & (1<<ADIF))==0);
  20. ADCSRA|=(1<<ADIF);
  21. return ADCW;
  22. }
  23.  
  24. void main(void)
  25. {
  26. //DDRB = 0xff;
  27. //DDRD |= (1<<PORTD.7);
  28. // ADC initialization
  29. // ADC Clock frequency: 125,000 kHz
  30. // ADC Voltage Reference: AVCC pin
  31. ADMUX=ADC_VREF_TYPE;
  32. ADCSRA=(1<<ADEN) | (0<<ADSC) | (0<<ADFR) | (0<<ADIF) | (0<<ADIE) | (1<<ADPS2) | (0<<ADPS1) | (1<<ADPS0);
  33. SFIOR=(0<<ACME);
  34.  
  35. // Alphanumeric LCD initialization
  36. // Connections are specified in the
  37. // Project|Configure|C Compiler|Libraries|Alphanumeric LCD menu:
  38. // RS - PORTB Bit 0
  39. // RD - PORTB Bit 1
  40. // EN - PORTB Bit 2
  41. // D4 - PORTB Bit 3
  42. // D5 - PORTB Bit 4
  43. // D6 - PORTB Bit 5
  44. // D7 - PORTD Bit 7
  45. // Characters/line: 16
  46. lcd_init(16);
  47.  
  48. while (1)
  49.       {
  50.       celcius=LM35_C(0);
  51.       ftoa(celcius,1,bf);
  52.       lcd_puts("Temp = ");
  53.       lcd_gotoxy(0,1);
  54.       lcd_puts(bf);
  55.       lcd_gotoxy(5,1);
  56.       lcd_putchar(\'C\');
  57.       delay_ms(500);        
  58.       lcd_clear();
  59.       }
  60. }
');