0% found this document useful (0 votes)
18 views

Program No Error

This document contains code for a temperature reading program. It initializes an LCD display, ADC, and ports. It defines a function to read the ADC and returns the 8 MSB. The main function sets up variables, displays "TEMPERATURE" on the LCD, and enters a loop to continuously read the ADC channel 0, convert it to a float, display the value on the LCD, and delay.

Uploaded by

jkl
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views

Program No Error

This document contains code for a temperature reading program. It initializes an LCD display, ADC, and ports. It defines a function to read the ADC and returns the 8 MSB. The main function sets up variables, displays "TEMPERATURE" on the LCD, and enters a loop to continuously read the ADC channel 0, convert it to a float, display the value on the LCD, and delay.

Uploaded by

jkl
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

PROGRAM PEMBACA SUHU

#include <mega16.h>
#include <delay.h>
#include <stdlib.h>
#include <alcd.h>
#define ADC_VREF_TYPE 0x60
// Read the 8 most significant bits
// of the AD conversion result
unsigned char read_adc(unsigned char
adc_input)
{
ADMUX=adc_input | (ADC_VREF_TYPE &
0xff);
// Delay needed for the stabilization of the ADC
input voltage
delay_us(10);
// Start the AD conversion
ADCSRA|=0x40;
// Wait for the AD conversion to complete
while ((ADCSRA & 0x10)==0);
ADCSRA|=0x10;
return ADCH;
}
// Declare your global variables here
void main(void)
{
unsigned int adc;
float y;
char temp[6];
PORTD=0x00;
DDRD=0x00;

ADMUX=ADC_VREF_TYPE & 0xff;


ADCSRA=0x84;

SPCR=0x00;

lcd_init(16);
lcd_gotoxy(0,0);

lcd_putsf("VISKOSITAS");
lcd_gotoxy(7,1);
lcd_putsf("C");
while (1)
{
// Place your code here
adc=read_adc(0);
y=(float)adc;
lcd_gotoxy(0,1);
ftoa(y,2,temp);
lcd_puts(temp);
}
}

PROGRAM PEMBACA VISKOSITAS


#include <mega16.h>
#include <delay.h>
#include <stdlib.h>
#include <alcd.h>
#define ADC_VREF_TYPE 0x60
// Read the 8 most significant bits
// of the AD conversion result
unsigned char read_adc(unsigned char
adc_input)
{
ADMUX=adc_input | (ADC_VREF_TYPE &
0xff);
// Delay needed for the stabilization of the ADC
input voltage
delay_us(10);
// Start the AD conversion
ADCSRA|=0x40;
// Wait for the AD conversion to complete
while ((ADCSRA & 0x10)==0);
ADCSRA|=0x10;
return ADCH;
}
// Declare your global variables here
void main(void)
{
unsigned int adc;
float y;

char temp[6];
PORTD=0x00;
DDRD=0x00;

ADMUX=ADC_VREF_TYPE & 0xff;


ADCSRA=0x84;

SPCR=0x00;

lcd_init(16);
lcd_gotoxy(0,0);
lcd_putsf("NILAI VISKOSITAS");
lcd_gotoxy(7,1);
lcd_putsf("POISE");
while (1)
{
// Place your code here
adc=read_adc(0);
y=-0.003*(2*(float)adc)+0.19;
lcd_gotoxy(0,1);
ftoa(y,4,temp);
lcd_puts(temp);
}
}

You might also like