Minggu, 30 Maret 2014

ATMEGA16











Susunan pada pemasangan ICSP.

 

 

 

 

 





Pin Diagram: 
ATmega16 Pin Diagram, PinOut


Pin Description: 
Pin No.
Pin name
Description
Alternate Function
1
(XCK/T0) PB0
I/O PORTB, Pin 0
T0: Timer0 External Counter Input.
XCK : USART External Clock I/O
2
(T1) PB1
I/O PORTB, Pin 1
T1:Timer1 External Counter Input
3
(INT2/AIN0) PB2
I/O PORTB, Pin 2
AIN0: Analog Comparator Positive I/P
INT2: External Interrupt 2 Input
4
(OC0/AIN1) PB3
I/O PORTB, Pin 3
AIN1: Analog Comparator Negative I/P
OC0 : Timer0 Output Compare Match Output
5
(SS) PB4
I/O PORTB, Pin 4
In System Programmer (ISP)
Serial Peripheral Interface (SPI)
6
(MOSI) PB5
I/O PORTB, Pin 5
7
(MISO) PB6
I/O PORTB, Pin 6
8
(SCK) PB7
I/O PORTB, Pin 7
9
RESET
Reset Pin, Active Low Reset
10
Vcc
Vcc = +5V
11
GND
GROUND
12
XTAL2
Output to Inverting Oscillator Amplifier
13
XTAL1
Input to Inverting Oscillator Amplifier
14
(RXD) PD0
I/O PORTD, Pin 0
USART Serial Communication Interface
15
(TXD) PD1
I/O PORTD, Pin 1
16
(INT0) PD2
I/O PORTD, Pin 2
External Interrupt INT0
17
(INT1) PD3
I/O PORTD, Pin 3
External Interrupt INT1
18
(OC1B) PD4
I/O PORTD, Pin 4
PWM Channel Outputs
19
(OC1A) PD5
I/O PORTD, Pin 5
20
(ICP) PD6
I/O PORTD, Pin 6
Timer/Counter1 Input Capture Pin
21
PD7 (OC2)
I/O PORTD, Pin 7
Timer/Counter2 Output Compare Match Output
22
PC0 (SCL)
I/O PORTC, Pin 0
TWI Interface
23
PC1 (SDA)
I/O PORTC, Pin 1
24
PC2 (TCK)
I/O PORTC, Pin 2
JTAG Interface
25
PC3 (TMS)
I/O PORTC, Pin 3
26
PC4 (TDO)
I/O PORTC, Pin 4
27
PC5 (TDI)
I/O PORTC, Pin 5
28
PC6 (TOSC1)
I/O PORTC, Pin 6
Timer Oscillator Pin 1
29
PC7 (TOSC2)
I/O PORTC, Pin 7
Timer Oscillator Pin 2
30
AVcc
Voltage Supply = Vcc for ADC
31
GND
GROUND
32
AREF
Analog Reference Pin for ADC
33
PA7 (ADC7)
I/O PORTA, Pin 7
ADC Channel 7
34
PA6 (ADC6)
I/O PORTA, Pin 6
ADC Channel 6
35
PA5 (ADC5)
I/O PORTA, Pin 5
ADC Channel 5
36
PA4 (ADC4)
I/O PORTA, Pin 4
ADC Channel 4
37
PA3 (ADC3)
I/O PORTA, Pin 3
ADC Channel 3
38
PA2 (ADC2)
I/O PORTA, Pin 2
ADC Channel 2
39
PA1 (ADC1)
I/O PORTA, Pin 1
ADC Channel 1
40
PA0 (ADC0)
I/O PORTA, Pin 0
ADC Channel 0

 

 

Rabu, 12 Maret 2014

HARAPAN DAN CITA CITA SAYA

SeekBar Pada Android

1. layout - activity_main.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >
    <SeekBar
        android:id="@+id/seekBar1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:layout_marginTop="112dp" />
    <TextView
        android:id="@+id/txtSeekBar"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/seekBar1"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="31dp"
        android:text="0 %"
        android:textAppearance="?android:attr/textAppearanceLarge" />
</RelativeLayout>

2. MainActivity.Java
package com.seekbar;
import android.app.Activity;
import android.os.Bundle;
import android.widget.SeekBar;
import android.widget.SeekBar.OnSeekBarChangeListener;
import android.widget.TextView;
import android.widget.Toast;
public class MainActivity extends Activity {
SeekBar dim;
TextView txt;
       @Override
       protected void onCreate(Bundle savedInstanceState) {
              super.onCreate(savedInstanceState);
              setContentView(R.layout.activity_main);
              txt=(TextView)findViewById(R.id.txtSeekBar);
              dim=(SeekBar)findViewById(R.id.seekBar1);
              // mengeset nilai maksimum seekbar
              dim.setMax(100);
             
              /* event seek bar ,setOnSeekBarChangeListener
               * 1. onStopTrackingTouch , fungsi yang akan di jalankan ketika objek selesai                 *    di gunakan
               * 2. onStartTrackingTouch , fungsi yang di jalankan ketika objek mulai di                     *   gunakan
               * 3. onProgressChanged, fungsi yang akan di jalankan ketika objek sedang di                   *   gunakan,int progress merupakan   nilai value dari objek
               *                        
               */
      
              dim.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {
                    
                     @Override
                     public void onStopTrackingTouch(SeekBar seekBar) {
                           // TODO Auto-generated method stub
                           tampil("stop" );
                     }
                    
                     @Override
                     public void onStartTrackingTouch(SeekBar seekBar) {
                           // TODO Auto-generated method stub
                           tampil("start" );   
                     }
                    
                     @Override
                     public void onProgressChanged(SeekBar seekBar, int progress,
                                  boolean fromUser) {
                           // TODO Auto-generated method stub
                           tampil("progress");
                           txt.setText(String.valueOf(progress));
                     }
              });
       }
       private void tampil(String h){
       Toast.makeText(getApplication(), h, Toast.LENGTH_SHORT)
               .show();
       }
      
}
3. Running



List View Activity Android

Kali akan di contohkan sebuah ListView pada android
Terdapat beberapa nama buah, jika nama buah tersebut di klik maka akan menampilkan pesan nama buah tersebut
1. File Xml
File : res/layout/main.xml
-       code
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context=".MainActivity" >
    <ListView
        android:id="@+id/android:list"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
    >
    </ListView>
</RelativeLayout>
-       Grapichal Layout
 
2 Sourcode di Main Activity.Java
package com.fu.contohlistview;
import java.util.ArrayList;
import java.until.List;
import android.app.ListActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.Toast;
public class MainActivity extends ListActivity {
       //buat objek list Array String
       List listnew ArrayList() ;
       @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        // menambahkan nama-nama buah ke objek list
        list.add("Mangga");
        list.add("Jeruk");
        list.add("Jambu");
        // buat objek adapter array
        ArrayAdapteradapter = new ArrayAdapter(this, android.R.layout.simple_list_item_1, list);
        // tampilkan objek list
        setListAdapter(adapter);
    }
       // pada saat salah satu nama buah di klik maka akan menjalankan fungsi di onListItemClick
       protected void onListItemClick(ListView l, View v, int posisi, long id) {
       String a =    "Nama Buah = "+ list.get(posisi) ;
       Toast.makeText(this, a, Toast.LENGTH_LONG)
       .show();
             
       }
}
3. Running Demo
-       Pada saat saa menekan mangga di layar android.





-       

Intent untuk kirim data antar Activity Android

1. sourcode java
- Form1.Java
package com.example.intentkirimdata;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
public class Form1 extends Activity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_form1);
        Button btnKirimKeForm2 = (Button)findViewById(R.id.btnKirimKeForm2);
        final EditText txtKirimKeForm2 =(EditText)findViewById(R.id.editText1);
        btnKirimKeForm2.setOnClickListener(new OnClickListener() {
                    
              @Override
              public void onClick(View v) {
              // TODO Auto-generated method stub
              String  datanya= txtKirimKeForm2.getText().toString();
              // pastikan ada text yang di massukan   
              if(!datanya.isEmpty()){
              // buat objek intent
              Intent x = new Intent();
              x.putExtra("dari form 1",datanya);
              x.setClass(Form1.this, Form2.class);
              startActivity(x);
              txtKirimKeForm2.setText("");
              }
              else{
                     Toast.makeText(getApplication(), "isi data", Toast.LENGTH_SHORT)
                     .show();
                     }
              }
       });
       
    }
   
}
-    Form2.Java
package com.example.intentkirimdata;
import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;
public class Form2 extends Activity {
static String datana;
   @Override
   protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_form2);
          TextView txtDataDariForm1=(TextView)findViewById(R.id.textView1);
          Bundle extras=getIntent().getExtras();
          // ambil data intent dengan key "dari form 1"
       datana=extras.getString("dari form 1");
       // tampikan data dari form 1
       txtDataDariForm1.setText(datana);
   }
}
2. File Xml
- activity_form1
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context=".Form1" >
    <EditText
        android:id="@+id/editText1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
       android:ems="10" >
        <requestFocus android:layout_width="match_parent" />
    </EditText>
    <Button
        android:id="@+id/btnKirimKeForm2"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@+id/editText1"
        android:layout_below="@+id/editText1"
        android:text="Kirim Ke Form 2" />
</RelativeLayout>
-activity_form2
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context=".Form2" >
    <TextView
        android:id="@+id/textView1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:layout_marginBottom="330dp"
        android:text="x"
        android:textAppearance="?android:attr/textAppearanceLarge" />
</RelativeLayout>
3. Running Demo
 - Tampilan Awal
-    Misal saya isi text dengan edy , dan tekkan button



Dan pada saat pindah ke form 2 akan muncul text yang di tulis pada form 1




Edit Text dan Button Untuk Password di Android

Demo kali ini akan membuat contoh form login dengan menggunakan komponen Button dan EditText .
 1. File Xml
Buat sebuah Button  dan Edit Text pada Layout
File : res/layout/main.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context=".MainActivity" >
    <EditText
        android:id="@+id/editText1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:ems="10"
        android:inputType="textPassword" >
        <requestFocus />
    </EditText>
    <Button
        android:id="@+id/btnOk"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@+id/editText1"
        android:layout_alignRight="@+id/editText1"
        android:layout_below="@+id/editText1"
        android:text="OK" />
</RelativeLayout>
 2. Sour Code pada MainActivity.Java
package com.fu.contohpassword;
import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
public class MainActivity extends Activity {
       /* Objek String Passku untuk membandingkan dengan
        * Password ang di massukan oleh User
        */
       String passku="aku";
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        Button btnOk = (Button)findViewById(R.id.btnOk);
      
        final EditText txtPass=(EditText)findViewById(R.id.editText1);
        btnOk.setOnClickListener(new OnClickListener() {
                    
       @Override
       public void onClick(View v) {
       // TODO Auto-generated method stub
       /* jika password yang di massukan oleh user  sama dengan objek string
* passku (disini isi string = aku) maka akan muncul klimat di layar *password benar,
* jika password yang di massukan user berbeda maka akan muncul password *salah
                            */
                           if(txtPass.getText().toString().equalsIgnoreCase(passku)){                        Toast.makeText(getApplication(), "Password Benar", Toast.LENGTH_LONG)
       .show();
       }else{
       Toast.makeText(getApplication(), "Password Salah", Toast.LENGTH_LONG)
       .show();
       }
       }
       });
    }
   
}
3. Coba jalankan Aplikasi Anda
Massukan password sesuai dengan Objek string passku 
String passku="aku";
Jika user memassukan password “aku” maka akan tampil password benar, jika berbeda maka akan muncul password salah.