Perancangan Alat Pengisi Baterai Smartphone Berbayar dengan Tenaga Surya

55

LAMPIRAN

Universitas Sumatera Utara

56

GAMBAR RANGKAIAN KESELURUHAN

Universitas Sumatera Utara

LISTING PROGRAM
#include
#include
#include
#include
#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;
}
unsigned char x,T,i;
unsigned int V;
char buf[16];
void Display(void){
lcd_clear();
lcd_gotoxy(0,0);
lcd_putsf(" masukkan coin");
sprintf(buf,"Waktu : %i mnt ",T);
lcd_gotoxy(0,1);
lcd_puts(buf);

delay_ms(200);}
void BatCheck(void){
V = read_adc(0);
if (V < 126){PORTB.1 = 1;}
if (V >= 138){PORTB.1 = 0;}
}
void main(void)
{
PORTA=0x00;
DDRA=0x00;
PORTB=0x00;

57
Universitas Sumatera Utara

58

DDRB=0xFF;
PORTC=0x00;
DDRC=0x00;

PORTD=0xFF;
DDRD=0x00;

// ADC initialization
ADMUX=ADC_VREF_TYPE & 0xff;
ADCSRA=0x82;
SFIOR&=0xEF;
lcd_init(16);
lcd_gotoxy(0,0);
lcd_putsf(" ALAT ISI ULANG");
lcd_gotoxy(0,1);
lcd_putsf(" PONSEL MANDIRI");
delay_ms(2000);
lcd_clear();
while (1)
{ x = 0;
lcd_gotoxy(0,0);
lcd_putsf(" masukkan coin");
lcd_gotoxy(0,1);
lcd_putsf(" Rp500; Rp1000;");

while (PIND.2 == 1){ BatCheck();
if (PIND.0 == 1){delay_ms(10);
if ((PIND.0 == 1)&&(PIND.1 == 1)){x++;
if(x > 18){x = 18;}
T = 10 * x;delay_ms(100);
while(PIND.0 == 1){}
goto a;}

a:

if (PIND.0 == 1){x++;x++;
if(x > 18){x = 18;}
T = 10 * x;delay_ms(100);
while(PIND.0 == 1){}
Display();}
}
}
lcd_clear();
lcd_gotoxy(0,0);


Universitas Sumatera Utara

59

lcd_putsf("Sedang mengisi..");
PORTB.0 =1;
while (T > 0){
for (i=60;i>0;i--)
{
sprintf(buf,"Waktu : %i ",T);
lcd_gotoxy(0,1);
lcd_puts(buf);
sprintf(buf,"%i ",i);
lcd_gotoxy(12,1);
lcd_puts(buf);
BatCheck();
delay_ms(1000);
}
T--;
}

PORTB.0 = 0;
lcd_clear();
lcd_gotoxy(0,0);
lcd_putsf("Charging selesai");
delay_ms(5000);
}
}

Universitas Sumatera Utara