Professional Documents
Culture Documents
Kombinasi Motor Led
Kombinasi Motor Led
#define motor_CW PORTD.0 #define motor_CCW PORTD.1 #define ADC_VREF_TYPE 0x00 // Read the AD conversion result unsigned int 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 ADCW; } void main(void) { int LDR; PORTA=0x00; DDRA=0xff; PORTB=0x00; DDRB=0xff; PORTC=0xff; DDRC=0x00; PORTD=0x00; DDRD=0xff; // ADC initialization // ADC Clock frequency: 86.400 kHz // ADC Voltage Reference: AREF pin // ADC Auto Trigger Source: Free Running ADMUX=ADC_VREF_TYPE & 0xff; ADCSRA=0xA7; SFIOR&=0x1F; while (1) { lcd_clear(); lcd_gotoxy(0,0); lcd_putsf("mulai"); delay_ms(200); LDR=read_adc(0); if (LDR < 100) { // cahaya paling redup
PORTB = 0b00000001; PORTB.3=1; lcd_putsf("min (gelap)"); } else if (LDR > 100 && LDR < 160) // { PORTB = 0b00000010; motor_CW=1; lcd_putsf("medium(normal)"); } else // cahaya paling terang { PORTB = 0b00000100; motor_CCW=1; lcd_putsf("maksimum(terang)"); } }; cahaya sedang