This is default featured slide 1 title

Go to Blogger edit html and find these sentences.Now replace these sentences with your own descriptions.This theme is Bloggerized by Mirza - www.mirzaahcmad.ml

This is default featured slide 2 title

Go to Blogger edit html and find these sentences.Now replace these sentences with your own descriptions.This theme is Bloggerized by Lasantha Bandara - Premiumbloggertemplates.com.

This is default featured slide 3 title

Go to Blogger edit html and find these sentences.Now replace these sentences with your own descriptions.This theme is Bloggerized by Lasantha Bandara - Premiumbloggertemplates.com.

This is default featured slide 4 title

Go to Blogger edit html and find these sentences.Now replace these sentences with your own descriptions.This theme is Bloggerized by Lasantha Bandara - Premiumbloggertemplates.com.

This is default featured slide 5 title

Go to Blogger edit html and find these sentences.Now replace these sentences with your own descriptions.This theme is Bloggerized by Lasantha Bandara - Premiumbloggertemplates.com.

Kamis, 21 April 2016

MultiChatClient Menggunakan Java



Baiklah pada kali ini kita akan membuat program chatting dengan Java. Aplikasi ini membutuhkan satu koneksi, misalnya LAN, satu WIFI, dll. Untuk membuat aplikasi ini, dibutuhkan Java dan Netbeans. Jika sudah terinstal, kita lanjut saja ke programnya.

Pertama-tama kita buat terlebih dahulu Program Chat Servernya.

*****************************************************
import java.io.*;
import java.net.*;
import java.util.*;
public class ChatServer {
private static int uniqueId;
private ArrayList clients;
private int port;
private boolean keepGoing;
public ChatServer() {
this.port = 9999;
clients = new ArrayList();
}
public void start() {
keepGoing = true;
try {
ServerSocket serverSocket = new ServerSocket(port);
while (keepGoing) {
System.out.println("ChatServer waiting for Clients on port " + port + ".");
Socket socket = serverSocket.accept();
if (!keepGoing) {
break;
}
ChatServer.ClientThread t = new ChatServer.ClientThread(socket);
clients.add(t);
t.start();
send("login~" + t.username + "~" + t.username + " sedang login...~Server~\n");
}
try {
serverSocket.close();
for (int i = 0; i < clients.size(); ++i) { ChatServer.ClientThread tc = clients.get(i); try { tc.sInput.close(); tc.sOutput.close(); tc.socket.close(); } catch (IOException ioE) { } } } catch (Exception e) { System.out.println("Exception closing the server and clients: " + e); } } catch (IOException e) { String msg = "Exception on new ServerSocket: " + e + "\n"; System.out.println(msg); } } private synchronized void send(String message) { for (int i = clients.size(); --i >= 0;) {
ChatServer.ClientThread ct = clients.get(i);
if (!ct.writeMsg(message)) {
clients.remove(i);
System.out.println("Disconnected Client " + ct.username + " removed from list.");
}
}
}
private String getClients() {
String s = "";
for (ClientThread clientThread : clients) {
s += clientThread.username + ":";
}
s += "---";
System.out.println(s);
return s;
}
private synchronized void remove(int id) {
for (int i = 0; i < clients.size(); ++i) {
ChatServer.ClientThread ct = clients.get(i);
if (ct.id == id) {
clients.remove(i);
return;
}
}
}
public static void main(String[] args) {
ChatServer server = new ChatServer();
server.start();
}
private class ClientThread extends Thread {
private Socket socket;
private ObjectInputStream sInput;
private ObjectOutputStream sOutput;
private int id;
private String username;
public ClientThread(Socket socket) {
id = ++uniqueId;
this.socket = socket;
System.out.println("Menciptakan Object Input/Output Streams");
try {
sOutput = new ObjectOutputStream(socket.getOutputStream());
sInput = new ObjectInputStream(socket.getInputStream());
String message = (String) sInput.readObject();
username = message.split("~")[1];
System.out.println(username + " masuk.");
} catch (IOException e) {
System.out.println("Exception creating new Input/output Streams: " + e);
} catch (ClassNotFoundException e) {
}
}
@Override
public void run() {
boolean keepGoing = true;
while (keepGoing) {
String message;
try {
message = sInput.readObject().toString();
} catch (IOException e) {
System.out.println(username + " Exception reading Streams: " + e);
break;
} catch (ClassNotFoundException e2) {
break;
}
String type = message.split("~")[0];
String pengirim = message.split("~")[1];
String text = message.split("~")[2];
String kepada = message.split("~")[3];
String response;
switch (type) {
case "postText":
response = "recieveText~" + pengirim + "~" + text + "~" + kepada + "~\n";
send(response);
break;
case "postPrivateText":
response = "recievePrivateText~" + pengirim + "~" + text + "~" + kepada + "~\n";
send(response);
break;
case "login":
response = "login~" + pengirim + "~" + text + "~" + kepada + "~\n";
send(response);
break;
case "logout":
response = "logout~" + pengirim + "~" + text + "~" + kepada + "~\n";
send(response);
break;
case "list":
response = "list~server~" + getClients() + "~ ~ ~ ~ ~\n";
send(response);
break;
}
}
remove(id);
close();
}
private void close() {
try {
if (sOutput != null) {
sOutput.close();
}
} catch (Exception e) {
}
try {
if (sInput != null) {
sInput.close();
}
} catch (Exception e) {
}
try {
if (socket != null) {
socket.close();
}
} catch (Exception e) {
}
}
private boolean writeMsg(String msg) {
if (!socket.isConnected()) {
close();
return false;
}
try {
sOutput.writeObject(msg);
} catch (IOException e) {
System.out.println("Error sending message to " + username);
System.out.println(e.toString());
}
return true;
}
}
}



*****************************************************
Jika sudah, Compile dan simpan dengan nama ChatServer.Java. Lalu kita akan membuat untuk chat clientnya. Caranya sama diatas, hanya programnya saja yang dirubah. Berikut programnya.
*****************************************************

import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.net.Socket;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.table.DefaultTableModel;
public class ChatClient extends javax.swing.JFrame {
    /**
     * Creates new form ChatClient
     */
    private ObjectInputStream input;
    private ObjectOutputStream output;
    private Socket socket;
    private String server, username;
    private int port;
    private List<String> clients;
    public ChatClient() {
        clients = new ArrayList();
        initComponents();
    }
    public boolean start() {
        try {
            socket = new Socket(server, port);
        } catch (Exception ec) {
            System.out.println("Error connectiong to server:" + ec);
            return false;
        }
        String msg = "Connection accepted " + socket.getInetAddress() + ":" + socket.getPort();
        System.out.println(msg);
        try {
            input = new ObjectInputStream(socket.getInputStream());
            output = new ObjectOutputStream(socket.getOutputStream());
        } catch (IOException eIO) {
            System.out.println("Exception creating new Input/output Streams: " + eIO);
            return false;
        }
        new ChatClient.ListenFromServer().start();
        try {
            output.writeObject("login~" + username + "~" + username + " sedang login...~server~\n");
            output.writeObject("list~" + username + "~" + username + " sedang login...~server~\n");
        } catch (IOException eIO) {
            System.out.println("Exception doing login : " + eIO);
            disconnect();
            return false;
        }
        return true;
    }
    private void disconnect() {
        try {
            // TODO add your handling code here:
            output.writeObject("logout~" + username + "~" + username + " sudah logout...~Server~\n");
        } catch (IOException ex) {
            //Logger.getLogger(ChatClient.class.getName()).log(Level.SEVERE, null, ex);
        }
        try {
            if (input != null) {
                input.close();
            }
        } catch (Exception e) {
        }
        try {
            if (output != null) {
                output.close();
            }
        } catch (Exception e) {
        }
        try {
            if (socket != null) {
                socket.close();
            }
        } catch (Exception e) {
        }
    }
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">
    private void initComponents() {
        jScrollPane1 = new javax.swing.JScrollPane();
        viewTextArea = new javax.swing.JTextArea();
        jScrollPane2 = new javax.swing.JScrollPane();
        clientTable = new javax.swing.JTable();
        postTextField = new javax.swing.JTextField();
        kirimButton = new javax.swing.JButton();
        lbljpg   = new javax.swing.JLabel(new ImageIcon("E:/rara.jpg"));
        jLabel2 = new javax.swing.JLabel();
        serverTextField = new javax.swing.JTextField();
        jLabel3 = new javax.swing.JLabel();
        portTextField = new javax.swing.JTextField();
        masukButton = new javax.swing.JButton();
        jLabel4 = new javax.swing.JLabel();
        usernameTextField = new javax.swing.JTextField();
        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        viewTextArea.setEditable(false);
        viewTextArea.setColumns(20);
        viewTextArea.setLineWrap(true);
        viewTextArea.setRows(5);
        viewTextArea.setFocusable(false);
        jScrollPane1.setViewportView(viewTextArea);
        jScrollPane2.setViewportView(clientTable);
        postTextField.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                postTextFieldActionPerformed(evt);
            }
        });
        kirimButton.setText("Kirim");
        kirimButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                kirimButtonActionPerformed(evt);
            }
        });
        jLabel2.setText("Server");
        serverTextField.setText("10.17.0.0");
        jLabel3.setText("Port");
        portTextField.setText("9999");
        masukButton.setText("Masuk");
        masukButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                masukButtonActionPerformed(evt);
            }
        });
        jLabel4.setText("Username");
        usernameTextField.setText("Gian Azhari");
        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
               .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
             .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                                .addComponent(postTextField)
                             .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(kirimButton))
                            .addComponent(jScrollPane1))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 259, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(lbljpg)
                        .addComponent(jLabel2)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(serverTextField, javax.swing.GroupLayout.PREFERRED_SIZE, 167, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(jLabel3)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(portTextField, javax.swing.GroupLayout.PREFERRED_SIZE, 46, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(jLabel4)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(usernameTextField, javax.swing.GroupLayout.DEFAULT_SIZE, 194, Short.MAX_VALUE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(masukButton)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lbljpg)
                    .addComponent(jLabel2)
                    .addComponent(serverTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel3)
                    .addComponent(portTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(masukButton)
                    .addComponent(jLabel4)
                    .addComponent(usernameTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
               .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane2, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 427, Short.MAX_VALUE)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jScrollPane1)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(postTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(kirimButton))))
                .addContainerGap())
        );

        pack();
    }// </editor-fold>

    private void masukButtonActionPerformed(java.awt.event.ActionEvent evt) {
        // TODO add your handling code here:
        this.server = serverTextField.getText();
        this.port = new Integer(portTextField.getText());
        this.username = usernameTextField.getText();
        start();
    }

    private void kirimButtonActionPerformed(java.awt.event.ActionEvent evt) {
        // TODO add your handling code here:
        try {
            String message = "postText~" + username + "~" + postTextField.getText() + "~all~\n";
            output.writeObject(message);
            postTextField.setText("");
        } catch (IOException ex) {
            Logger.getLogger(ChatClient.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    private void postTextFieldActionPerformed(java.awt.event.ActionEvent evt) {
        // TODO add your handling code here:
        kirimButtonActionPerformed(evt);
    }

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
                /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(ChatClient.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(ChatClient.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(ChatClient.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(ChatClient.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            @Override
            public void run() {

                new ChatClient().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify
    private javax.swing.JTable clientTable;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JButton kirimButton;
    private javax.swing.JButton masukButton;
    private javax.swing.JTextField portTextField;
    private javax.swing.JTextField postTextField;
    private javax.swing.JTextField serverTextField;
    private javax.swing.JTextField usernameTextField;
    private javax.swing.JTextArea viewTextArea;
    private JLabel lbljpg ;
    // End of variables declaration

    class ListenFromServer extends Thread {

        @Override
        public void run() {
            while (true) {
                try {
                    String msg = (String) input.readObject();
                    String res;
                    String type = msg.split("~")[0];
                    String pengirim = msg.split("~")[1];
                    String text = msg.split("~")[2];
                    String kepada = msg.split("~")[3];
                    switch (type) {
                        case "recieveText":
                            res = pengirim + ": " + text;
                            viewTextArea.setText(viewTextArea.getText() + res + "\n");
                            break;
                        case "recievePrivateText":
                            res = pengirim + ": " + text;
                            if (kepada.equals(username)) {
                                viewTextArea.setText(viewTextArea.getText() + res + "\n");
                            }
                            break;
                        case "login":
                            viewTextArea.setText(viewTextArea.getText() + pengirim + " sudah login..." + "\n");
                            clients.add(pengirim);
                            break;
                        case "logout":
                            viewTextArea.setText(viewTextArea.getText() + pengirim + " telah logout..." + "\n");
                            clients.remove(pengirim);
                            break;
                        case "list":
                            setTable(text);
                            break;
                    }
                } catch (IOException e) {
                    System.out.println("Server has close the connection: " + e);
                    break;
                } catch (ClassNotFoundException e2) {
                }
            }
        }

        private void setTable(String text) {
            int rows = text.split(":").length - 1;
            Object[][] data = new Object[rows][1];
            for (int i = 0; i < rows; i++) {
                String t = text.split(":")[i];
                data[i][0] = t;
            }

            String[] header = {"Clients"};

            clientTable.setModel(new DefaultTableModel(data, header));
        }
    }

}

DOWNLOAD

Simulasi Seven Segment 12 Digit Menggunakan Proteus


 Langsung saja kita buat rangkaiannya.


1. Buka terlebih dahulu CodeVisionAVR, kita akan membuat programnya terlebih dahulu. Langsung saja buat project baru.

2. Pada pilihan IC, pilih ATMEGA.

 

3. Pada pilihan Chip, pilih ATmega8, dan Setting crystalnya menjadi 11.059200.

 

4. Pilih Generate Files terlebih dahulu, agar programnya dibuat.

 

5. Setelah program dibuat, lalu pilih Generate, Save, and Exit untuk menyimpan. Dalam menyimpan filenya, diusahakan untuk membuat dalam satu folder, dengan penggunaan nama tanpa angka (hanya huruf), dan tidak melakukan apapun saat proses menyimpan, karena bisa menyebabkan file yang akan disimpan gagal.


6. Setelah selesai, block semua program yang dibuat otomatis tadi, lalu copy dengan program Seven Segment dibawah ini.


Programnya :
/*******************************************************
This program was created by the CodeWizardAVR V3.24 
Automatic Program Generator
© Copyright 1998-2015 Pavel Haiduc, HP InfoTech s.r.l.
http://www.hpinfotech.com

Project : 7Segment NIM

Version : 1
Date    : 4/13/2016
Author  : Mirza Ahcmad Fazry
Company : POLSRI
Comments: Tugas Pak Ali


Chip type               : ATmega8

Program type            : Application
AVR Core Clock frequency: 11.059200 MHz
Memory model            : Small
External RAM size       : 0
Data Stack size         : 256
*******************************************************/
#include <mega8.h>
#include <delay.h>
// Declare your global variables here
#define PIN_SCK PORTB5
#define PIN_MOSI PORTB3
#define PIN_SS PORTB2

#define PIN_SS1 PORTB1


#define ON 1

#define OFF 0

#define cs_lo PORTB |= (1<<PIN_SS)

#define cs_hi PORTB &= ~(1<<PIN_SS)

#define cs1_lo PORTB |= (1<<PIN_SS1)

#define cs1_hi PORTB &= ~(1<<PIN_SS1)

#define MAX7219_MODE_DECODE 0x09

#define MAX7219_MODE_INTENSITY 0x0A
#define MAX7219_MODE_SCAN_LIMIT 0x0B
#define MAX7219_MODE_POWER 0x0C
#define MAX7219_MODE_TEST 0x0F
#define MAX7219_MODE_NOOP 0x00

// I only have 3 digits, no point having the

// rest. You could use more though.
#define MAX7219_DIGIT0 0x01
#define MAX7219_DIGIT1 0x02
#define MAX7219_DIGIT2 0x03
#define MAX7219_DIGIT3 0x04
#define MAX7219_DIGIT4 0x05
#define MAX7219_DIGIT5 0x06
#define MAX7219_DIGIT6 0x07
#define MAX7219_DIGIT7 0x08

#define MAX7219_CHAR_BLANK 0xF

#define MAX7219_CHAR_NEGATIVE 0xA

char jumlah_digit = 8;


void spiSendByte (char databyte)

{
SPDR = databyte;
while (!(SPSR & (1 << SPIF)));
}

void MAX7219_writeData(char data_register, char data,unsigned char chip)

{
cs_hi;
if(chip==0)
{
spiSendByte(MAX7219_MODE_NOOP);
spiSendByte(MAX7219_MODE_NOOP);
spiSendByte(data_register);
spiSendByte(data);
}
if(chip==1)
{
spiSendByte(data_register);
spiSendByte(data);
spiSendByte(MAX7219_MODE_NOOP);
spiSendByte(MAX7219_MODE_NOOP);

}

if(chip==2)
{
spiSendByte(data_register);
spiSendByte(data);
spiSendByte(MAX7219_MODE_NOOP);
spiSendByte(MAX7219_MODE_NOOP);
spiSendByte(MAX7219_MODE_NOOP);
spiSendByte(MAX7219_MODE_NOOP);
}
cs_lo;
}

void clear_display()

{
unsigned char i,j;
for(j=0;j<3;j++)
{
for(i=1;i<=jumlah_digit;i++)
{
MAX7219_writeData(i, MAX7219_CHAR_BLANK,j);
}
}
}

void kirim_display()

{
MAX7219_writeData(MAX7219_DIGIT0, 0,0);
MAX7219_writeData(MAX7219_DIGIT1, 6,0);
MAX7219_writeData(MAX7219_DIGIT2, 1,0);
MAX7219_writeData(MAX7219_DIGIT3, 4,0);

MAX7219_writeData(MAX7219_DIGIT0, 3,1);

MAX7219_writeData(MAX7219_DIGIT1, 0,1);
MAX7219_writeData(MAX7219_DIGIT2, 7,1);
MAX7219_writeData(MAX7219_DIGIT3, 0,1);

MAX7219_writeData(MAX7219_DIGIT0, 2,2);

MAX7219_writeData(MAX7219_DIGIT1, 0,2);
MAX7219_writeData(MAX7219_DIGIT2, 1,2);
MAX7219_writeData(MAX7219_DIGIT3, 0,2);

}


void main(void)

{
unsigned int j;
DDRB |= (1 << PIN_SCK) | (1 << PIN_MOSI) | (1 << PIN_SS)| (1 << PIN_SS1);
SPCR |= (1 << SPE) | (1 << MSTR)| (1<<SPR1);

for(j=0;j<3;j++)

{
MAX7219_writeData(MAX7219_MODE_DECODE, 0xFF,j);
MAX7219_writeData(MAX7219_MODE_SCAN_LIMIT,jumlah_digit - 1,j);
MAX7219_writeData(MAX7219_MODE_INTENSITY, 8,j);
MAX7219_writeData(MAX7219_MODE_POWER, ON,j);
}
while(1)
{
kirim_display();
}
}
7. Untuk mengubah tampilan angka yg akan muncul, cari program berikut ini, lalu ubah pada angka pada awalnya. Program ini telah dibuat dengan nim saya (061430701434). Urutannya dari atas ke bawah.

8. Jika sudah, pilih Compile terlebih dahulu, lalu pilih Build, setelah itu pilih Build All untuk mencegah file tidak tercompile seluruhnya. Caranya dapat dengan menekan tombol F9, lalu Ctrl + F9.

 

9. Jika muncul pesan Warning, tidak apa-apa. Ini hanya pesan warning, namun program tetap tercompile. Jangan hapus program yg ditunjukkan sebagai penyebab warning, karena program akan salah atau error. Jadi biarkan saja pesan warning nya.

 

10. Buka Proteus, lalu buat rangkaian seperti dibawah ini. Saya menggunakan port agar mudah dan rapi dalam penyusunan jalurnya. Untuk penggunaan Seven Segment nya menggunakan jenis CC atau Common Cathode (katoda). Namanya dalam proteus 7SEG-MPX4-CC.


11. Klik 2 kali pada IC ATMEGA8 nya, lalu klik pada tombol folder untuk memilih programnya.

12. Cari program yang tadi kita buat, lalu pilih open.

 

13. Jalankan rangkaiannya. Jika muncul tampilan sesuai dengan angka yang kalian buat, rangkaian berhasil dibuat. 

 

 Terimakasih.

Rabu, 13 April 2016

Tutorial simulasi 7Segment dan Install CodeVisionAVR



TUTORIAL MENGINSTAL CodeVisionAVR
1.     Download softwarenya terlebih dahulu di sini.

 2.     Setelah didownload, buka folder yang berhasil didownload.
 

3.     Klik Next.
TUTORIAL MEMBUAT FILE .HEX MENGGUNAKAN COMPILER CodeVisionAVR DENGAN BAHASA C
Buka aplikasi CodeVisionAVR yang telah diinstal (biasanya ada di Desktop)
1.     Klik File – New – Project.
2.     Klik Yes.
3. Pilih ATmega, ATtiny, AT90.


 





TUTORIAL MEMBUAT SIMULASI RANGKAIAN 7SEGMENT
pada SISTEM MINIMUM ATMega 8535
                                   di PROTEUS 8 PROFESIONAL

   Buka aplikasi Proteus 8 Profesional. Buat Schematic seperti pada gambar. Klikombol P untuk menambahkan komponen yang ditandai seperti pada gambar. Letakkan wire/kabel pada PORT A di MIKRO ATMega 8535.


Untuk tutorial lengkapnya dapat didownload DISINI.
Terima kasih.

Aplikasi Chat JAVA TEXTPAD

Program ChatClient

import java.net.*;
import java.io.*;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;

class ChatClient extends JFrame{



JLabel lblPesan =  new JLabel  ("Kirim Pesan :");
TextArea taPesan=new TextArea(4,50);
JLabel lblBalasan = new JLabel ("Dari Teman  :");
TextArea taBalasan=new TextArea(4,50);
JButton btnSend=new JButton("Send");
JButton btnOpen=new JButton("Open Connection");
JButton btnClose=new JButton("Close Connection");
Socket con=null;
ObjectOutputStream toServer;
ObjectInputStream fromServer;
String balasan=null;
String inputIPServer;

public void openConnection(){
           try{
                     //input dialog u/ memasukkan IP Address Chat Server
                     inputIPServer=JOptionPane.showInputDialog("Inputkan IP Server");

                     //koneksi ke port 2000 pada IP Address Server
                     con=new Socket(InetAddress.getByName(inputIPServer),2000);
                     toServer=new ObjectOutputStream(con.getOutputStream());
           }//end try
           catch (EOFException ex){
                       ;
           }
           catch(IOException io){
                       System.out.println("IO Exception");
                       io.printStackTrace();
           }
}//end openConnection();

public void sendData(){
           try{
                       toServer.writeObject(taPesan.getText());
                       taPesan.setText("");
               taPesan.requestFocus();
           }
           catch (EOFException ex){
                       ;
           }
           catch(IOException io){
                       System.out.println("IO Exception");
                       io.printStackTrace();
           }
}//end void sendData()

public void getData(){
           try{
                       fromServer=new ObjectInputStream(con.getInputStream());
                       balasan=(String) fromServer.readObject();
                       //System.out.println(balasan);
                       taBalasan.setText(balasan);
           }
           catch (ClassNotFoundException ex){
                       System.out.println("Error");
           }
           catch (EOFException ex){
                       ;
           }
           catch(IOException io){
                       System.out.println("IO Exception");
                       io.printStackTrace();
           }
}//end void getData()
public void closeConnection(){
           try{
                     toServer.writeObject("bye");
                     con.close();
                     con=null;
           }//end try
           catch (EOFException ex){
                       ;
           }
           catch(IOException io){
                       System.out.println("IO Exception");
                       io.printStackTrace();
           }
}//end closeConnection();

public ChatClient(){
           Container c = getContentPane();
           c.setLayout (new FlowLayout());
           c.add (lblPesan);
           c.add (taPesan);
           c.add (lblBalasan);
           c.add (taBalasan);
           c.add (btnOpen);
           c.add (btnSend);
           c.add (btnClose);

           btnOpen.addActionListener (new ActionListener(){
                       public void actionPerformed(ActionEvent evt){
                                   openConnection();
                       }//end void actionPerformed
           });

           btnSend.addActionListener (new ActionListener(){
                       public void actionPerformed(ActionEvent evt){
                                   sendData();
                                   getData();
                       }//end void actionPerformed
           });

           btnClose.addActionListener (new ActionListener(){
                       public void actionPerformed(ActionEvent evt){
                                   closeConnection();
                       }//end void actionPerformed
           });
  
           //pack();
}//end public ChatClient()

         public static void main(String[] args)
         {
                     ChatClient klien = new ChatClient();
                     klien.setTitle("Chatting - Client");
                     klien.setLocation (300,300);
                     klien.setSize(500,250);
                     klien.setVisible(true);        
                     klien.addWindowListener(new WindowAdapter(){
                                 public void windowClosing(WindowEvent ev){                               
                                             System.exit(0);
                                 }//end void
                     });

         }//main

}//class


Program ChatServer

import java.net.*;
import java.io.*;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;

class ChatServer extends JFrame{

JLabel lblPesan =  new JLabel  ("Kirim Pesan :");
TextArea taPesan=new TextArea(4,50);
JLabel lblBalasan = new JLabel ("Dari Teman  :");
TextArea taTeman=new TextArea(4,50);
JButton btnSend=new JButton("Send");
JButton btnClose=new JButton("Close Connection");
ServerSocket sktServer;
Socket conClient;

ObjectInputStream fromClient;
ObjectOutputStream toClient;
String s=null;
Container c;
  

public void sendData(){
           try{
                       toClient=new ObjectOutputStream(conClient.getOutputStream());
                       toClient.writeObject(taPesan.getText());
                       System.out.println(taPesan.getText());
                       taPesan.setText("");
               taPesan.requestFocus();
             
           }
           catch (EOFException ex){
                       ;
           }
           catch(NullPointerException npe){
                     JOptionPane.showMessageDialog(null, "Koneksi Belum Tersambung ! ",
                                 "Pesan", JOptionPane.ERROR_MESSAGE);
           }
           catch(SocketException se){
                     JOptionPane.showMessageDialog(null, "Koneksi Putus !",
                                 "Pesan", JOptionPane.ERROR_MESSAGE);
           }
           catch(IOException io){
                       System.out.println("IO Exception");
                       io.printStackTrace();
           }
}//end void sendData()


public void closeConnection(){
           try{
                     //toClient.writeObject("bye");
                     conClient.close();
                     conClient=null;
                     System.exit(0);
           }//end try
           catch (EOFException ex){
                       ;
           }
           catch(IOException io){
                       System.out.println("IO Exception");
                       io.printStackTrace();
           }
}//end closeConnection();

public ChatServer()throws IOException{
                     c = getContentPane();
                     c.setLayout (new FlowLayout());
                     c.add (lblPesan);
                     c.add (taPesan);
                     c.add (lblBalasan);
                     c.add (taTeman);
                     c.add (btnSend);
                     c.add (btnClose);
                        

           btnSend.addActionListener (new ActionListener(){
                       public void actionPerformed(ActionEvent evt){
                                   sendData();
                       }//end void actionPerformed
           });

           btnClose.addActionListener (new ActionListener(){
                       public void actionPerformed(ActionEvent evt){
                                   closeConnection();
                       }//end void actionPerformed
           });

}//end public ChatServer()

         public void terimaKoneksi() throws IOException{
             //sktServer=new ServerSocket(2000,1000);
                     sktServer=new ServerSocket(2000);
                     conClient=sktServer.accept();
                     //tunggu sampai client masuk melalui port 2000

                     //System.out.println("Tersambung dengan client " +
                                 //conClient.getInetAddress());

                     JOptionPane.showMessageDialog(null, "Tersambung dengan Client " +
                                 conClient.getInetAddress().toString(), "Pesan",
                                 JOptionPane.INFORMATION_MESSAGE);
                     sktServer.close();

                     try{
                                                
                                 fromClient=new ObjectInputStream(conClient.getInputStream());
                                 do{
                                             try{
                                                         s=(String) fromClient.readObject();
                                                         //System.out.println(s);
                                                         taTeman.setText(s);
                                             }//end try
                                             catch(ClassNotFoundException ex){
                                                         System.out.println("Error");
                                             }//end catch
                                 }//end do
                                 while (!s.equals("bye"));
                     }//end try
                     catch (EOFException ex){
                                 ;
                     }
                     catch (IOException io) {
                                 System.out.println("IO Exception");
                                 io.printStackTrace();
                     }
                     finally {
                                 System.out.println("Closed");
                                 conClient.close();
                     }//end finally
         }//end void terimaKoneksi()

         public static void main(String[] args) throws IOException
         {
                     ChatServer svr = new ChatServer();
                     svr.setTitle("Chatting - Server");
                     svr.setLocation (300,300);
                     svr.setSize(500,250);
                     svr.setVisible(true);          
                     svr.addWindowListener(new WindowAdapter(){
                                 public void windowClosing(WindowEvent ev){                               
                                             System.exit(0);
                                 }//end void
                     });
                     //supaya GUI muncul dulu & bisa terima koneksi, maka
                     //method terimaKoneksi() diletakkan di sini
                     svr.terimaKoneksi();

         }//end main
}//end class

untuk menggunakannya pertama run terlebih dahulu ChatServer, kemudian run ChatClient

ChatServer


ChatClient

kemudian klik Open Connection, dan beri IP servernya.





buka kembali ChatServer

sudah  bisa melakukan chat