Monday, December 30, 2013

Sharing dial-up Internet Connection in Local Network Using Router.


    In this tutorial I am going to show you how to share your dial-up internet connection (like USB dongle,bluetooth modem etc) with other computers or devices present in the network.This comes handy when you have no other internet options for all your devices.You can use a router to share your internet connection through wireless with others.Here are the steps to be followed.

Step-I:
    Configure you router as below.I have taken an IP of 192.168.0.125 but you can take anyone  like 192.168.0.xxx.Set the netmask and IP range and save it.I have used one Netgear router.





  Then configure the connection you want to share as follows.Go to sharing tab and share the connection which looks like this..

 This will pop a dialog saying your LAN IP has been changed click OK and move to the LAN properties and set the IPV4 settings as follows
 
 Its done with your PC now suppose you want to connect to Internet from other PC using Wi-Fi or LAN change the adapter properties of Wi-Fi or LAN (That is you are using to connect) as shown below..
  



Thats it you have set up the network successfully. You can check it out.





Friday, December 20, 2013

Static IP setup for Raspberry PI

Many time while using Raspberry PI people come across a situation that they have to connect their PI to the Internet through the Local n/ws.Usually a systemis assigned with IPs those are dynamic(DHCP) i.e. any IP is assigned to the device during the connection setup and that's the case for PI also and it works fine also.But in certain cases yo may have to configure your PI with a static IP ,like suppose you want to make your PI a server.Here i have given the steps to add a static IP to your Pi.

   Open the terminal and type
                    cd  /etc/network

then
                    sudo pico interfaces

   Then change the content to this,where you will have to set the corresponding values depending upon your network.

                     auto lo

                     iface lo inet loopback

                     iface eth0 inet static
                                    address  xx.xx.xx.xx

                                    network xx.xx.xx.xx

                                    broadcast xx.xx.xx.xx

                                    gateway xx.xx.xx.xx

press

ctrl+x
 
and then

 y
 
to save and exit.


 

       Now we have to set the DNS and that is done by esiting the file resolv.conf.So you can edit it by

sudo nano /etc/resolv.conf



and add below shown to the file and save it like before.

nameserver xx.xx.xx.xx
Now reboot your system by giving command

                   
 reboot


That's all you are ready to go.


Friday, December 13, 2013

RX-30 Finger Print Module Device Interfacing

     Many of  you have must heard about the finger print sensor which actually a nice way to provide security.Here  i have given the interfacing of the R30-X finger print sensor module with  ARM LPC2148 board but the basics remains same for all the micro-controllers.

    The first thing for interfacing the sensor with the controller is the handshaking,in which the controller first sends a signal or hex codes to the sensor and it acknowledges .After handshaking only the controller can talk to the sensor.


unsigned char Message[16] = {0XEF,0X01,0XFF,0XFF,0XFF,0XFF,0X01,0X00,0X07,0X13,0X00,0X00,0X00,0X00,0X00,0X1B};

   This line of commands are the first to be sent to the sensor so as to start the communication.I have given the complete code to communicate with the LPC 2148 below.

Code:
#include 
#include "Serial.h"
#include "Utility.h"
#include "LCD4.h"
#include "Glcd.h"

unsigned char Message[16] = {0XEF,0X01,0XFF,0XFF,0XFF,0XFF,0X01,0X00,0X07,0X13,0X00,0X00,0X00,0X00,0X00,0X1B};
unsigned char ack[12]={0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,};
unsigned char gim[12]={0XEF,0X01,0XFF,0XFF,0XFF,0XFF,0X01,0X00,0X03,0X01,0X00,0X05};
unsigned char uim[12]={0XEF,0X01,0XFF,0XFF,0XFF,0XFF,0X01,0X00,0X03,0X0A,0X00,0X0E};
int main (void)
{  int i;
 PINSEL0 = 0;
 PINSEL1 = 0;
 PINSEL2 &= 0x0000000C;
 PINSEL2 |= 0x00000030;
 DelayProc(0.2 * CCLOCK);

  LCD4_init(&IOPIN0, 20/*D4*/, 12/*RS*/, 14/*E*/);
 UART1_init(9600/*bps*/, 15000/*kHz*/,length_8_bit, stop_bit_1, parity_disable, parity_odd);
 UART0_init(9600/*bps*/, 15000/*kHz*/, length_8_bit, stop_bit_1, parity_disable, parity_odd);

 
 for(i=0;i<16;i++)
 {
 UART1_sendchar(Message[i]);
 
 }
    for(i=0;i<12;i++)
 {
    ack[i]=UART1_getchar();
 }
  if(ack[9]==0x00)
{
UART0_sendstring("password checked sucessfully\n\n");
LCD4_sendstr (0,2, "password checked sucessfully");
} 
  label:
    for(i=0;i<12;i++)
 {
 UART1_sendchar(gim[i]);
 
 }
 for(i=0;i<12;i++)
 {
    ack[i]=UART1_getchar();
 } 

  if(ack[9]==0x02)
{
UART0_sendstring("cant find finger\n\n");
LCD4_sendstr (0,1, "cant find finger");
DelayProc(.7 * CCLOCK);
LCD4_sendstr (0,1, "Put finger");
UART0_sendstring("Put finger\n\n");
DelayProc(.7* CCLOCK);
goto label;

}
if(ack[9]==0x00)
{
UART0_sendstring("finger scan sucessfully completed\n\n");
LCD4_sendstr (0,1, "finger scan sucessfully completed");
}

 for(i=0;i<12;i++)
 {
 UART1_sendchar(uim[i]);
 
 }
 for(i=0;i<40000;i++)
 {
    UART0_sendchar(UART1_getchar());
 } 


      LCD4_sendstr (0,1, "image downloaded");

}

Thursday, December 12, 2013

We are Dreamers

  We are the dreamers
             We are the dreamers
                                      with a dream of flying high,
     We try to touch the sky,
                                    And go to a boundless world.
            We believe in what we are,
                                  We do what we can.
             Nothing can stop us,
                                   because we are the dreamers.
              Our dream is to built an INDIA,
                                                  which world will know.
              We tempted to achieve our goal,
                                                   And eager to score it.
               Everybody will know us,
                                                   because we are the dreamers.
              We dream to reach beyond the universe,
                                                  To the house of stars.
              We and our knowledge,
                                                that will make our dream true.
     We never stops,
                                              because we are the dreamers.

Simple currency converter in JAVA

Here goes a simple JAVA code to convert rupees by using the online yahoo exchange rates.

Code:


package com.oksbwn.currencyRate;
import java.io.IOException;

import javax.swing.JOptionPane;

import org.apache.http.client.HttpClient;
import org.apache.http.client.ResponseHandler;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.*;

import com.oksbwn.popUp.popMe;

public class YahooCurrencyConverter
{ 
@SuppressWarnings({ "deprecation", "resource" })
public float convert(String currencyFrom, String currencyTo) throws IOException
 {  
    HttpClient httpclient = new DefaultHttpClient();  
 HttpGet httpGet = new HttpGet("http://quote.yahoo.com/d/quotes.csv?s=" + currencyFrom + currencyTo + "=X&f=l1&e=.csv"); 
 ResponseHandler responseHandler = new BasicResponseHandler();   
 String responseBody = httpclient.execute(httpGet, responseHandler);    
 httpclient.getConnectionManager().shutdown();    
 return Float.parseFloat(responseBody);   
 }    
public void convertToRs()
{String to = null;
 String amnt=JOptionPane.showInputDialog(null, "Any to rupee..","$");
 //if ("$".charAt(0).(();
 if(amnt.substring(0,1).compareTo("$")==0)
        to="USD";
 
 if(amnt.substring(0,1).compareTo("E")==0)
        to="EUR";
 double ghh=1;
 try{
       ghh=Double.parseDouble(amnt.substring(1));
 }catch (Exception e){}  
 YahooCurrencyConverter df= new YahooCurrencyConverter();
 try {
  float x=df.convert(to,"INR");
  new popMe( "Exchange rate is"+x,"From  "+to+" to INR", "exp", 6, 125);
  
  JOptionPane.showMessageDialog(null,x*ghh);
 } catch (IOException e) {
  // TODO Auto-generated catch block
  e.printStackTrace();
 }
 }
}


JFrame that pops-up from the taskbar like notifications.

Here i have given the JAVA code to make a popup that happens exactly like the gmail desktop application does.It uses a JFrame to make the window.

Code:
package com.oksbwn.popUp;
import java.awt.*;
import java.awt.event.*;

import javax.swing.*;

import com.oksbwn.ErrorHandling.handleExceptions;

import resources.RscLoader;

public class popMe extends JFrame {
 private static final long serialVersionUID = 1L;
 public static void main(String[] args) throws Exception{
   new popMe("hi", "from Bikash", "ok",15, 125);
  }
public popMe(String message,String header,String image, final int time,int height) 
       {

 Runnable r = new newThreadPop(message,header,image,time,height);
 new Thread(r).start();
       }
 }
 
class newThreadPop implements Runnable {
 private String message;
 private String header;
 private String image;
 private  int time;
 private  int height;

  public newThreadPop(String message1,String header1,String image1, final int time1,int height1) {
         // store parameter for later user
   this.message=message1;
   this.header=header1;
   this.image=image1;
   this.time=time1;
   this.height=height1;
     }

     public void run() {
    final Runnable runnable = (Runnable) Toolkit.getDefaultToolkit().getDesktopProperty("win.sound.exclamation");
    //default 
     if (runnable != null)
       runnable.run();
  final JFrame frame = new JFrame();
  frame.setUndecorated(true);
  frame.setType(javax.swing.JFrame.Type.UTILITY);frame.setUndecorated(true);
     frame. setBackground(new Color(Color.black.getRed(), Color.black.getGreen(),Color.black.getBlue(),0));
  ((JComponent)frame.getContentPane()).setBorder(    
          BorderFactory.createMatteBorder( 2, 2, 2, 2, Color.black ) );
  frame.setSize(300,height);
  frame.setLayout(new GridBagLayout());
  GridBagConstraints constraints = new GridBagConstraints();
  constraints.gridx = 0;
  constraints.gridy = 0;
  constraints.weightx = 1.0f;
  constraints.weighty = 1.0f;
  constraints.insets = new Insets(5, 5, 5, 5);
  constraints.fill = GridBagConstraints.BOTH;
  JLabel headingLabel = new JLabel(header);
  headingLabel.setForeground(Color.red);
  ImageIcon headingIcon = new ImageIcon(RscLoader.getImage(image)); 
  headingLabel .setIcon(headingIcon); // --- use image icon you want to be as heading image.
  headingLabel.setOpaque(false);
  frame.add(headingLabel, constraints);
  constraints.gridx++;
  constraints.weightx = 0f;
  constraints.weighty = 0f;
  constraints.fill = GridBagConstraints.NONE;
  constraints.anchor = GridBagConstraints.NORTH;
  
  final JLabel lblX = new JLabel("X");
  lblX.setToolTipText("Close\r\n");
  lblX.addMouseListener(new MouseAdapter() {
   @Override
   public void mouseClicked(MouseEvent arg0) {
    frame.dispose();
   }
   @Override
   public void mouseEntered(MouseEvent e) {
    lblX.setForeground(new Color(255, 0, 0));
   }
   public void mouseExited(MouseEvent e) {
    lblX.setForeground(new Color(0, 0, 0));
   }
  });
  lblX.setSize(10,10);
  lblX.setFocusable(false);
  frame.add(lblX,constraints);
  constraints.gridx = 0;
  constraints.gridy++;
  constraints.weightx = 1.0f;
  constraints.weighty = 1.0f;
  constraints.insets = new Insets(5, 5, 5, 5);
  constraints.fill = GridBagConstraints.BOTH;
  JLabel messageLabel = new JLabel(""+message);
  messageLabel.setForeground(Color.blue);
  frame.add(messageLabel, constraints);
  frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
  frame.setVisible(true);
  frame.setAlwaysOnTop(true);
  Dimension scrSize = Toolkit.getDefaultToolkit().getScreenSize();// size of the screen  
        Insets toolHeight = Toolkit.getDefaultToolkit().getScreenInsets(frame.getGraphicsConfiguration());// height of the task bar  
        frame.setLocation(scrSize.width - frame.getWidth(), scrSize.height - toolHeight.bottom - frame.getHeight()); 
                new Thread(){  
           @Override 
            public void run() {  
                  try {  
                   Thread.sleep(time*1000); // time after which pop up will be disappeared.  
                      frame.dispose();  
                      }
                  catch (Exception e)
                  {new handleExceptions(e);} };}.start(); 

 }
}


A Transparent screen to lock the Desktop.

In this code i am sharing the code to lock the PC screen by using a transparent JFrame so as to restrict others to use it.The frame disappears  only when the user enters the right username and password.This enables the user to let the background tasks going on and lock the screen.This has the only problem that it can be closed by the task manager.If you find a solution to it please let me know.

Code:

package com.oksbwn.systeminteraction;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Toolkit;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.io.IOException;

import javax.microedition.io.Connection;
import javax.microedition.io.Connector;
import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JComponent;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPasswordField;
import javax.swing.JTextField;

import com.oksbwn.popUp.popMe;
import com.oksbwn.voiceEnable.Voice;

public class Hibernate
{
   JFrame frame2=new JFrame();
//public static void main(String args[]) throws Exception
 public void doit() throws IOException
    {
 try {
        Connection connection = Connector.open( "btgoep://" +"04A82A5A62FB" + ":9");
           connection.close();
  //int x=1/0;//The condition which will trigger the frame to come up
       } 
    catch (Exception e) {
     //r.exec("shutdown -h");//s for shutdown r restart
 // Runtime rt = Runtime.getRuntime();
    // rt.exec("C:\\Windows\\System32\\rundll32.exe user32.dll,LockWorkStation");
     
     Dimension scrSize = Toolkit.getDefaultToolkit().getScreenSize();// size of the screen
   frame2.setBounds(0,0,scrSize.width, scrSize.height);
     frame2.getContentPane().setLayout(null);
     frame2.setAlwaysOnTop(true);
     frame2.setUndecorated(true);
      frame2.setBackground(new Color(Color.black.getRed(), Color.black.getGreen(),Color.black.getBlue(),1));
      frame2.getContentPane().setBackground(new Color(Color.black.getRed(), Color.black.getGreen(),Color.black.getBlue(),50));
     ((JComponent)frame2.getContentPane()).setBorder(    
              BorderFactory.createMatteBorder( 2, 2, 2, 2, Color.black ) );
     frame2.setType(javax.swing.JFrame.Type.UTILITY);
     frame2.setAlwaysOnTop(true);
     
     final JTextField textField = new JTextField();
     textField.addKeyListener(new KeyAdapter() {
     @Override
     public void keyPressed(KeyEvent arg0) { 
       frame2.repaint();
     }
    });
     textField.setBounds(scrSize.width-150, scrSize.height-100, 140, 30);
     textField.setBackground(new Color(Color.black.getRed(), Color.black.getGreen(),Color.black.getBlue(),1));
     frame2.getContentPane().add(textField);
     textField.setColumns(10);
   
     final JPasswordField passwordField = new JPasswordField();
     passwordField.addKeyListener(new KeyAdapter() {
     @Override
     public void keyPressed(KeyEvent arg0) { 
       frame2.repaint();
     }
    });
     frame2.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
     passwordField.setBounds(scrSize.width-150, scrSize.height-65,140,30);
     passwordField.setBackground(new Color(Color.black.getRed(), Color.black.getGreen(),Color.black.getBlue(),1));
     frame2.getContentPane().add(passwordField);
     
    JButton btnLogIn = new JButton("login");
    btnLogIn.setBounds(scrSize.width-127,scrSize.height-30,77,24);
       frame2.getContentPane().add(btnLogIn);
        btnLogIn.addMouseListener(new MouseAdapter() {
     @Override
     public void mouseClicked(MouseEvent arg0) 
     {
      @SuppressWarnings("deprecation")
      String pass=passwordField.getText();
      logClicked(pass,textField.getText());
      passwordField.setText(null);
      textField.setText(null);
      //frame2.dispose();
     }
    });
     
        final JLabel Snap = new JLabel();
           Snap.setForeground(Color.RED);
           Snap.setBounds(scrSize.width/2-100, scrSize.height/2-100,200,200);
     frame2.getContentPane().add(Snap);
     
     frame2.addMouseListener(new MouseAdapter() {
       @Override
       public void mouseClicked(MouseEvent arg0) {
     final Runnable runnable = (Runnable) Toolkit.getDefaultToolkit().getDesktopProperty("win.sound.exclamation");
     //default 
      if (runnable != null)
        runnable.run();
      Snap.setText("OOOOps   You are Not Bikash");
         }
     });
     frame2.setVisible(true);
     }
    }
protected  void logClicked(String pass, String user) 
{
 String aPass="******";//Password
 String aUser="oksbwn";//Username
 if (aPass.compareTo(pass) == aUser.compareTo(user)==true)
    {
   //sucess message
  }
 else {
     //failure message
      }
 }
}

Drive space usage information in JAVA

This JAVA code gives the dpace usage by the 'c:' drive you can modify it for others.

Code:

package com.oksbwn.systeminteraction;
import java.io.File;
public class DiskSpaceDetail
{
 public String FreeSpaceInDrive()
    { 
  String space="";
     File file = new File("C:");
     long totalSpace = file.getTotalSpace(); //total disk space in bytes.
     long usableSpace = file.getUsableSpace(); ///unallocated / free disk space in bytes.
      space=space+"C:";
     space="T:  "+ totalSpace /1024 /1024 + " MB  F: "+ usableSpace /1024 /1024+" MB";
     return space;
     }
 }

Taking a snap of the Desktop in JAVA

Here i have gioven the code to take a snap of the desktop using JAVA.Hope you will use it in your own way.

Code:
package com.oksbwn.systeminteraction;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.MouseInfo;
import java.awt.Point;
import java.awt.Rectangle;
import java.awt.Robot;
import java.awt.Toolkit;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.image.BufferedImage;
import java.io.File;

import javax.imageio.ImageIO;
import javax.swing.*;

import resources.RscLoader;

import com.oksbwn.ErrorHandling.handleExceptions;
import com.oksbwn.popUp.popMe;
public class CaptureScreen {
 static JFrame frame2=new JFrame();
 static Point p;
 static Point R;
 static Point D;
 static int Finaly;
 static int Startx;
 static int Starty;
 static int Finalx;
 static JTextField jt=new JTextField();
  public static void main(String[] args) 
  {
   CaptureScreen cS=new CaptureScreen();
   cS.SnapTaker();
  }
 public void SnapTaker()
   {
    Dimension scrSize = Toolkit.getDefaultToolkit().getScreenSize();// size of the screen
  frame2.setBounds(0,0,scrSize.width, scrSize.height);
    frame2.getContentPane().setLayout(null);
    frame2.setAlwaysOnTop(true);
    frame2.setUndecorated(true);
     frame2.setBackground(new Color(Color.black.getRed(), Color.black.getGreen(),Color.black.getBlue(),1));
     frame2.getContentPane().setBackground(new Color(Color.black.getRed(), Color.black.getGreen(),Color.black.getBlue(),50));
    ((JComponent)frame2.getContentPane()).setBorder(    
             BorderFactory.createMatteBorder( 2, 2, 2, 2, Color.black ) );
    frame2.setType(javax.swing.JFrame.Type.UTILITY);
    frame2.setAlwaysOnTop(true);
    
    jt.setBounds(0,0,0,0);
    jt.addMouseListener(mouseListener);
    jt.setBorder(BorderFactory.createMatteBorder( 2, 2, 2, 2, Color.black ));
    jt.addMouseMotionListener(mouseListener);
    jt.setEditable(false);
     jt.setBackground(new Color(Color.black.getRed(), Color.black.getGreen(),Color.black.getBlue(),0));
    frame2.getContentPane().add(jt);
    
          final JLabel cloesButton = new JLabel("X");
    cloesButton.setForeground(Color.white);
    cloesButton.setToolTipText("Close");
    cloesButton.addMouseListener(new MouseAdapter() {
       @Override
       public void mouseClicked(MouseEvent arg0) {
         frame2.dispose();
         }
      @Override
      public void mouseEntered(MouseEvent arg0) {
        cloesButton.setForeground(Color.red);
       }
     @Override
      public void mouseExited(MouseEvent arg0) {
        cloesButton.setForeground(Color.white);
       }});
    cloesButton.setSize(15,15);
    cloesButton.setBounds(scrSize.width-15, scrSize.height-20,15,20);
    
          final JLabel Snap = new JLabel();
          Snap.setIcon(new ImageIcon(RscLoader.getImage("cam")));
          Snap.setForeground(Color.white);
          Snap.setToolTipText("Take Snap");
          Snap.addMouseListener(new MouseAdapter() {
       @Override
       public void mouseClicked(MouseEvent arg0) {
         takeSnap();
         }
      @Override
      public void mouseEntered(MouseEvent arg0) {
       Snap.setForeground(Color.GREEN);
       }
     @Override
      public void mouseExited(MouseEvent arg0) {
      Snap.setForeground(Color.white);
       }});
          Snap.setBounds(scrSize.width-100, scrSize.height-20,60,20);
    frame2.getContentPane().add(Snap);
    
    frame2.addMouseListener(new MouseAdapter() {
     
      @Override
      public void mousePressed(MouseEvent arg0) {
        p= MouseInfo.getPointerInfo().getLocation();
         //jt.setBounds(0,0,p.x,p.y);
       }
      @Override
      public void mouseReleased(MouseEvent arg0) {
        R= MouseInfo.getPointerInfo().getLocation();
           jt.setBounds(p.x,p.y,R.x-p.x,R.y-p.y);
       }});
    frame2.getContentPane().add(cloesButton);
    frame2.setVisible(true);

  }
  private final static void takeSnap()
  {
    try {
       Robot robot = new Robot();       
       Rectangle area = new Rectangle(jt.getBounds());
       BufferedImage bufferedImage = robot.createScreenCapture(area);
       File file = new File("C:\\users\\oksbwn\\desktop\\screenshot_small.png");
       boolean i=ImageIO.write(bufferedImage, "jpg", file);
       if (i)
       {
        new popMe("Snap taken Sucessfully.","Screen Capture","ok",2,125);
       }
    } catch (Exception e) {new handleExceptions(e);}
  }
  private final static MouseAdapter mouseListener = new MouseAdapter() {
      int x, y;
      @Override
      public void mousePressed(MouseEvent e) {
          if (e.getButton() == MouseEvent.BUTTON1) {
              x = e.getX();
              y = e.getY();
          }
      }

      @Override
      public void mouseDragged(MouseEvent e) {
          if ((e.getModifiersEx() & MouseEvent.BUTTON1_DOWN_MASK) != 0) {
           jt. setLocation(e.getXOnScreen() - x, e.getYOnScreen() - y);
          }
      }
  };
  
}

PC Login Duration in JAVA

This code snippest is about getting the time duration from which the user has been logged in using JAVA.

 code:

package com.oksbwn.systeminteraction;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.text.SimpleDateFormat;
import java.util.Date;
public class OsLoginTime {
 public static long getSystemUptime() throws Exception {
  long uptime =0000;
  
      Process uptimeProc = Runtime.getRuntime().exec("net stats srv");
      BufferedReader in = new BufferedReader(new InputStreamReader(uptimeProc.getInputStream()));
      String line;
      while ((line = in.readLine()) != null) {
          if (line.startsWith("Statistics since")) {
              SimpleDateFormat format = new SimpleDateFormat("'Statistics since' MM/dd/yyyy hh:mm:ss a");
              Date boottime = format.parse(line);
              uptime = System.currentTimeMillis() - boottime.getTime();
              break;
         }
  }
  return uptime/36000;//in millisecond
  }
}

Get own IP address in JAVA

This is a code snippest to get the current IP address of own system.

code:
package com.oksbwn.systeminteraction;
import java.net.InetAddress;
import java.net.UnknownHostException;
 
public class IpAdress{
 
  //public static void main(String[] args){
public static InetAddress getIP(){
 InetAddress ip;
 try {ip = InetAddress.getLocalHost();
  return ip;
  } catch (UnknownHostException e) {e.printStackTrace();}
 return null;
 
 }
 
   }


Draggable Transparent JFrame in JAVA

Here i am going to post about a JFrame that is transparent ,having a close button and is draggable.The JAVA code is given below.

Code:
public class transparentJFrame {
 public static void main(String[] args)
 {
    new transparentJFrame(Date,Head,Detal);
     }
public transparentJFrame(String Date,String Head,String Detal) 
     {  
  
  JFrame frame = new JFrame();
  frame.setUndecorated(true);
  frame.setBackground(new Color(Color.black.getRed(), Color.black.getGreen(),Color.black.getBlue(),1));
  //Change value of '1' above to have diff transparency
    ((JComponent)frame.getContentPane()).setBorder(    
           BorderFactory.createMatteBorder( 3, 2, 2, 2, Color.black));
  frame.setBounds(100, 50, 500, 400);
  frame.getContentPane().setLayout(null);
  
   final JLabel lblX = new JLabel("X");
   lblX.setBounds(frame.getWidth()-15,5,15,15);
   lblX.setForeground(new Color(255, 255,255));
   lblX.setToolTipText("Close\r\n");
   lblX.addMouseListener(new MouseAdapter() {
   @Override
   public void mouseClicked(MouseEvent arg0) {
    frame.dispose();
   }
   @Override
   public void mouseEntered(MouseEvent e) {
    lblX.setForeground(new Color(255, 0, 0));
   }
   public void mouseExited(MouseEvent e) {
    lblX.setForeground(new Color(255, 255,255));
   }
  });
  lblX.setFocusable(false); 
  frame.getContentPane().add(lblX);
  frame.setVisible(true);
 }
}


Thursday, December 5, 2013

Clickable image gallery using JAVA

This is a sample project that gives the user a simple image gallery of 44 images those are clickable and prints the clicked image names to the prompt .This can be used as menu or any other way.Hope you would like it.

Code:
MainFrame.java

import java.awt.*;
public class JIFrameDemo{
 static createFrame f1=new createFrame();
 static createFrame f2=new createFrame();
 
 static createFrame f3=new createFrame();
 static createFrame f4=new createFrame();
 static createFrame f5=new createFrame();
 static createFrame f6=new createFrame();
 static createFrame f7=new createFrame();
 static createFrame f8=new createFrame();
 static createFrame f9=new createFrame();

 static createFrame f10=new createFrame();
 static createFrame f11=new createFrame();
 static createFrame f12=new createFrame();
 static  createFrame f13=new createFrame();
 static createFrame f14=new createFrame();
 static createFrame f15=new createFrame();
 static createFrame f16=new createFrame();
 static createFrame f17=new createFrame();
 static createFrame f18=new createFrame();
 
 static createFrame f19=new createFrame();
 static createFrame f20=new createFrame();
 static createFrame f21=new createFrame();
 static createFrame f22=new createFrame();
 static createFrame f23=new createFrame();
 static createFrame f24=new createFrame();
 static createFrame f25=new createFrame();
 static createFrame f26=new createFrame();
 static createFrame f27=new createFrame();

 static createFrame f28=new createFrame();
 static createFrame f29=new createFrame();
 static createFrame f30=new createFrame();
 static  createFrame f31=new createFrame();
 static createFrame f32=new createFrame();
 static createFrame f33=new createFrame();
 static createFrame f34=new createFrame();
 static createFrame f35=new createFrame();
 static createFrame f36=new createFrame();
 
 static createFrame f37=new createFrame();
 static createFrame f38=new createFrame();
 static  createFrame f39=new createFrame();
 static createFrame f40=new createFrame();
 static createFrame f41=new createFrame();
 static createFrame f42=new createFrame();
 static createFrame f43=new createFrame();
 static createFrame f44=new createFrame();
 static lastframe f45=new lastframe();
 String std="f45";
 public static void main(String[] args) {
  Dimension gh=java.awt.Toolkit.getDefaultToolkit().getScreenSize();
  int i=0,j=0;
  f1.frame(20,20,"samosa");
  f18.frame(900,130,"aloo_bharta");
  f17.frame(790,130,"vada 3");
  f16.frame(680,130,"tea");
  f15.frame(570,130,"roti");
  f14.frame(460,130,"rice");
  f3.frame(240,20,"biscuit");f2.frame(130,20,"aluchup");
  f13.frame(350,130,"puri");
  f12.frame(240,130,"paratha");
  f11.frame(130,130,"paneer_masala");
  f10.frame(20,130,"mudhi");
  f9.frame(900,20,"mixture");
  f8.frame(790,20,"dosa");
  f7.frame(680,20,"dal");
  f6.frame(570,20,"cold_drink");
  f5.frame(460,20,"cofee");
  f4.frame(350,20,"chowmin");

  f44.frame(790,460,"1");
  f43.frame(680,460,"1");
  f42.frame(570,460,"1");
  f41.frame(460,460,"1");
  f40.frame(350,460,"1");
  f39.frame(240,460,"1");
  f38.frame(130,460,"1");
  f37.frame(20,460,"1");
  f36.frame(900,350,"1");
  f35.frame(790,350,"1");
  f34.frame(680,350,"1");
  f33.frame(570,350,"tomatto_khatta");
  f32.frame(460,350,"alu_beans");
  f31.frame(350,350,"alu_potal");
  f30.frame(240,350,"dahi_baigan");
  f29.frame(130,350,"saga");
  f28.frame(20,350,"salad");
  f27.frame(900,240,"ghnta_curry_fry");
  f26.frame(790,240,"dalma");
  f25.frame(680,240,"ghanta_curry_masala");
  f24.frame(570,240,"gaja_muga");
  f23.frame(460,240,"chilly_paneer");
  f22.frame(350,240,"dahi_salad");
  f21.frame(240,240,"dahi");
  f20.frame(130,240,"baigan_bharta");
  f19.frame(20,240,"alu_govi");
  f45.frame(900,460);
 }
 void allDispose()
  {
  f1.dispose().dispose();
  f2.dispose().dispose();
  f3.dispose().dispose();
  f4.dispose().dispose();
  f5.dispose().dispose();
  f6.dispose().dispose();
  f7.dispose().dispose();
  f8.dispose().dispose();
  f9.dispose().dispose();
  f10.dispose().dispose();
  f11.dispose().dispose();
  f12.dispose().dispose();
  f13.dispose().dispose();
  f14.dispose().dispose();
  f15.dispose().dispose();
  f16.dispose().dispose();
  f17.dispose().dispose();
  f18.dispose().dispose();
  f19.dispose().dispose();
  f20.dispose().dispose();
  f21.dispose().dispose();
  f22.dispose().dispose();
  f23.dispose().dispose();
  f24.dispose().dispose();
  f25.dispose().dispose();
  f26.dispose().dispose();
  f27.dispose().dispose();
  f28.dispose().dispose();
  f29.dispose().dispose();
  f30.dispose().dispose();
  f31.dispose().dispose();
  f32.dispose().dispose();
  f33.dispose().dispose();
  f34.dispose().dispose();
  f35.dispose().dispose();
  f36.dispose().dispose();
  f37.dispose().dispose();
  f38.dispose().dispose();
  f39.dispose().dispose();
  f40.dispose().dispose();
  f41.dispose().dispose();
  f42.dispose().dispose();
  f43.dispose().dispose();
  f44.dispose().dispose();
  f45.dispose().dispose();
  
  
  }
}
Createframe.java//To create small frames
 
import java.awt.Color;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;

import javax.swing.BorderFactory;
import javax.swing.JComponent;
import javax.swing.JDesktopPane;
import javax.swing.JFrame;
import javax.swing.JLabel;


public class createFrame {
    final JFrame jf = new JFrame("JIFrameDemo Main Window");
	public JFrame dispose(){
		return jf;
	}
	public void frame(int xPos,int yPos,final String img){
    jf.setUndecorated(true);
    jf.setBackground(new Color(Color.black.getRed(), Color.black.getGreen(),Color.black.getBlue(),0));
    jf.setSize(100,100);
    jf.setLocation(xPos, yPos);
    JDesktopPane dtp = new JDesktopPane();
    dtp. setBackground(new Color(Color.black.getRed(), Color.black.getGreen(),Color.black.getBlue(),100));
   // dtp.setBackground(Color.GREEN);
    jf.setContentPane(dtp);  
    jf.setType(javax.swing.JFrame.Type.UTILITY);
    
	((JComponent)jf.getContentPane()).setBorder(    
	        BorderFactory.createMatteBorder( 2, 2, 2, 2, Color.black ) );
	
	final JLabel lblX = new JLabel("X");
	lblX.setLocation(89,5);
	lblX.setForeground(new Color(255, 255,255));
	lblX.setToolTipText("Close\r\n");
	lblX.addMouseListener(new MouseAdapter() {
		@Override
		public void mouseClicked(MouseEvent arg0) {
			jf.dispose();
		}
		@Override
		public void mouseEntered(MouseEvent e) {
			lblX.setForeground(new Color(255, 0, 0));
		}
		public void mouseExited(MouseEvent e) {
			lblX.setForeground(new Color(255, 255,255));
		}
	});
	lblX.setSize(10,10);
	lblX.setFocusable(false);	
	jf.add(lblX);
	
	final JLabel lblX1 = new JLabel("");
	lblX1.setLocation(0,0);
	lblX1.setForeground(new Color(255, 255,255));
	final addFood fd=new addFood();
	lblX1.addMouseListener(new MouseAdapter() {
		@Override
		public void mouseClicked(MouseEvent e) 
		{
			//jf.getName();
			//System.out.println(img);
			String list;
			String bef=fd.returnlast();
			if (bef=="")
				list=bef+""+img;
			else 
			  {
				list=bef+","+img;
			  }
			fd.addnew(list);
		}
	});
	lblX1.setSize(110,110);
	lblX1.setToolTipText(img);
	lblX1.setFocusable(false);
	jf.add(lblX1);
    jf.setVisible(true);
    }
}
LastFrame.java//Added to close all the opened frames when clicked.
import java.awt.Color;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;

import javax.swing.BorderFactory;
import javax.swing.JComponent;
import javax.swing.JDesktopPane;
import javax.swing.JFrame;
import javax.swing.JLabel;


public class lastframe {

    final JFrame jf = new JFrame("JIFrameDemo Main Window");
	public JFrame dispose(){
	return jf;
}
	public void frame(int xPos,int yPos){
    jf.setUndecorated(true);
    jf.setBackground(new Color(Color.black.getRed(), Color.black.getGreen(),Color.black.getBlue(),0));
    jf.setSize(100,100);
    jf.setLocation(xPos, yPos);
    JDesktopPane dtp = new JDesktopPane();
    dtp. setBackground(new Color(Color.black.getRed(), Color.black.getGreen(),Color.black.getBlue(),100));
   // dtp.setBackground(Color.GREEN);
    jf.setContentPane(dtp);  
    jf.setType(javax.swing.JFrame.Type.UTILITY);
    
	((JComponent)jf.getContentPane()).setBorder(    
	        BorderFactory.createMatteBorder( 2, 2, 2, 2, Color.black ) );
	
	final JLabel lblX = new JLabel("X");
	lblX.setLocation(89,5);
	lblX.setForeground(new Color(255, 255,255));
	lblX.setToolTipText("Close\r\n");
	lblX.addMouseListener(new MouseAdapter() {
		@Override
		public void mouseClicked(MouseEvent arg0) {
			jf.dispose();
		}
		@Override
		public void mouseEntered(MouseEvent e) {
			lblX.setForeground(new Color(255, 0, 0));
		}
		public void mouseExited(MouseEvent e) {
			lblX.setForeground(new Color(255, 255,255));
		}
	});
	lblX.setSize(10,10);
	lblX.setFocusable(false);	
	jf.add(lblX);
	
	final JLabel lblX1 = new JLabel("");
	lblX1.setLocation(0,0);
	lblX1.setForeground(new Color(255, 255,255));
	lblX1.addMouseListener(new MouseAdapter() {
		@Override
		public void mouseClicked(MouseEvent e) 
		{
			//jf.getName();
			System.out.println("completed");
			JIFrameDemo xy=new JIFrameDemo();
			xy.allDispose();
		}
	});
	lblX1.setSize(110,110);
	lblX1.setToolTipText("Completed");
	lblX1.setFocusable(false);
	jf.add(lblX1);
    jf.setVisible(true);
    }
}
addFood.java//To make a string of clicked images
 

public class addFood { 
	static String before="" ;
	public String returnlast(){
		return before;
	}
public void addnew(String food)
    {
	  before=food;
	  System.out.println(before);
	}
}

Thursday, November 14, 2013

Lock PC using Mobile Bluetooth

   This article describes a method of locking the PC when the user is not around.Actually it detects the user mobile phone's bluetooth (Obviously it has to be turned on all the time.) and if the application can't find the phone it sends a command to lock down the workstation.The codes are of JAVA and it uses the Bluecove library ,which is a open source one.The app uses the bluetooth mac address instead of the name so as to provide security.Hope this will help you.

 Codes:
  • To find the Bluetooth mac address :
package com.oksbwn.bluetooth;
import java.io.IOException;
import javax.bluetooth.*;
import javax.swing.JOptionPane;
public class BluetoothSearchAddress implements DiscoveryListener {
    private LocalDevice localDevice;
    private DiscoveryAgent agent;
   public BluetoothSearchAddress () throws BluetoothStateException {
        localDevice = LocalDevice.getLocalDevice();
        agent = localDevice.getDiscoveryAgent();
    }
    
    public void inquiry() throws BluetoothStateException {
        agent.startInquiry(DiscoveryAgent.GIAC, this);
    }
    public void deviceDiscovered(RemoteDevice device, DeviceClass devClass) {
        String devicesAndAdress="<html><body>";
        try {
            devicesAndAdress=devicesAndAdress+device.getFriendlyName(false)+":"+device.getBluetoothAddress();
        } catch (IOException ex) {}      
JOptionPane.showMessageDialog(null, devicesAndAdress);
    }
    public void servicesDiscovered(int transID, ServiceRecord[] servRecord) { }
    public void serviceSearchCompleted(int transID, int responseCode) { }
    public void inquiryCompleted(int discType){}
}
  • To lock PC if mobile not found.
     package com.oksbwn.System;
     import java.io.IOException;
     import javax.microedition.io.Connection;
     import javax.microedition.io.Connector;
public class Hibernate
{
// public static void main(String args[]) throws Exception
 public void doit() throws IOException{
       try {
           Connection connection = Connector.open( "btgoep://" +"THE DEVIC BT. ADDRESS" + ":9");
           connection.close();
       }
       catch (Exception e) {
     //r.exec("shutdown -h");//s for shutdown r restart
     Runtime rt = Runtime.getRuntime();
     rt.exec("C:\\Windows\\System32\\rundll32.exe user32.dll,LockWorkStation");
     }
       }
}



Saturday, September 28, 2013

SIM300 Module

SIM 300:
       When accessing GSM networks comes in picture in embedded system ,one of the best way is to use SIMCOM modules which provides RS-232 interfacing and supports for AT command sets (Commands used for calling,Messaging etc) and usually easy to integrate with embedded modules.In this post i have tried to explain how to Interface the SIM300 module to LPC2148 using UART and send message to a no.

Hardware Connection :
      The SIM module is connected to the LPC2148 by using the UART port.Simple 2 wire connection is made between the board and the module.The Rx and Tx pins are connected accordingly.


CODE:

#include <LPC214X.H>
#include "Serial.h"
#include "Utility.h"
#include "LCD4.h"
int main (void)
{
unsigned char x[200];
int PosAck,y=0;
//hex code of "at enter" command for checking comm status of uart-reply should be ok
 unsigned char AckComm[3]={0x61,0x74,0x0d};
//hex code - for checking balance  -here sim-airtel so,atd*123# 
 unsigned char BalChkComm[9]={0x61 ,0x74 ,0x64 ,0x2A ,0x31 ,0x32 ,0x33 ,0x23,0x0d};
//hex code for selecting text mode-
 unsigned char SmsConfigComm[10]={0x41 ,0x54 ,0x2B ,0x43  ,0x4D ,0x47 ,0x46 ,0x3D ,0x31,0x0d};
// Setting No-9439421905   Bikash
unsigned char SendMsgComm[21]={0x61,0x74,0x2B,0x63,0x6D,0x67,0x73,0x3D,0x22,0x39,0x34 ,0x33 ,0x39 ,0x34 ,0x32 ,0x31 ,0x39,0x30 ,0x35,0x22,0x0D};
 //message body NISt (change it to have diff content )
unsigned char SendMsgBody[5]={0x4E,0x49,0x53,0x54,0x1A};
//lcd data is used temoporarily to store data for lcd display
 unsigned char LcdData[16];
//data used to clear the display
unsigned char LcdClear[16]={0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20};
int i;
LCD4_init (&IOPIN0, 20/*D4*/, 12/*RS*/, 14/*E*/);//initialization of LCD in 4 bit mode
DelayProc(2*CCLOCK);
PINSEL0 = 0;
PINSEL1 = 0;
PINSEL2 &= 0x0000000C;
PINSEL2 |= 0x00000030;
DelayProc(0.2 * CCLOCK);


 UART0_init(9600, 15000, length_8_bit, stop_bit_1, parity_disable, parity_odd);//UART initilization connected to PC
 UART1_init(9600, 15000, length_8_bit, stop_bit_1, parity_disable, parity_odd);//UART initilizaton connected to MODEM

LCD4_sendstr (0,2,"Modem Status :");
      for(i=0;i<3;i++)
                    {
                  UART1_sendchar(AckComm[i]);//Sending At command to check Status
                      }
                      for(i=0;i<7;i++)
                              {
                              x[i]=UART1_getchar();//receiving Status
                              UART0_sendchar(x[i]);
                                }
LcdData[0]=x[5];
LcdData[1]=x[6];

  LCD4_sendstr (1,1,LcdData);
DelayProc(2*CCLOCK);


LCD4_sendstr (1,1,LcdClear);
LCD4_sendstr (0,2,LcdClear);


LCD4_sendstr (0,2,"Account Balance:");
DelayProc(2*CCLOCK);
       for(i=0;i<9;i++)
                    {
                  UART1_sendchar(BalChkComm[i]);//Sending Command to Check balance

                      }
          
                    for(i=0;i<100;i++)
                              {
                              x[i]=UART1_getchar();//getting reply
                              UART0_sendchar(x[i]);
if (x[i]==0x3A && y<2)
{
PosAck=i;
//LCD4_sendstr (1,1,"reached");
y++;
                                    }
                                }

LcdData[0]=x[PosAck];
LcdData[1]=x[PosAck+1];
LcdData[2]=x[PosAck+2];
LcdData[3]=x[PosAck+3];
LcdData[4]=x[PosAck+4];
LcdData[5]=x[PosAck+5];
LCD4_sendstr (1,1,LcdData);


            DelayProc(2*CCLOCK);

                                LCD4_sendstr (1,1,LcdClear);
LCD4_sendstr (0,2,LcdClear);

LCD4_sendstr(0,2,"TEXT mode:");
   DelayProc(2*CCLOCK);
      for(i=0;i<10;i++)
                    {
                  UART1_sendchar(SmsConfigComm[i]);//cONfiguring MODEM in TEXT Mode

                      }
                    for(i=0;i<15;i++)
                              {
                              x[i]=UART1_getchar();
                              UART0_sendchar(x[i]);
if (x[i]==0x31)
{
PosAck=i;
//LCD4_sendstr (1,1,"reached");
//y++;
                                    }
                                }

LCD4_sendstr(1,1,"ok");

DelayProc(2*CCLOCK);
LCD4_sendstr (1,1,LcdClear);
LCD4_sendstr (0,2,LcdClear);



LCD4_sendstr(0,2,"Sending Message");

DelayProc(2*CCLOCK);
for(i=0;i<21;i++)
                    {
                  UART1_sendchar(SendMsgComm[i]);//Adding no to send Message

                      }
                   for(i=0;i<25;i++)
                              {
                              x[i]=UART1_getchar();
                              UART0_sendchar(x[i]);
                                }
     for(i=0;i<5;i++)
                    {
                  UART1_sendchar(SendMsgBody[i]);//Sending Message Body To Receipient. ctrl+z hex code 1A is used at last.

                      }
               for(i=0;i<170;i++)
                              {
                              x[i]=UART1_getchar();
                              UART0_sendchar(x[i]);
                                }

                 LCD4_sendstr(1,1,"ok");
DelayProc(2*CCLOCK);
 LCD4_sendstr (1,1,LcdClear);
LCD4_sendstr (0,2,LcdClear);

}

16X2 LCD Interfacing With Microcntrollers

What is 16x2 LCD:
              LCD is an output display device abbreviation for Liquid Crystal Display .Many varieties and types of LCD comes into market and out of them 16x2 LCD is the simplest one and is easy to be interfaced.As the name suggest it is a 2 line diplay and each line supports up-to 16 characters.

Pin Diagram & Connections:
            The 16x2 LCD is a  16 pin device having a PCB mounted controller and a display.The controller listen to the data ports and generate the pattern to be displayed according to the i/p data.Out of 16b pins 8 pins are data pins,2 pins for power supply,1 for contrast setting of the display,1 is Register Select,1 is Read/Write select,1 enable and 2 for the background lightening LED.


Data Pins: The device has 8 data pins which receives data to be displayed from the interfaced device.All the 8 pins  carries data in 8 bit mode but in case of 4 bit (Explained later) only  MSB(D5 to D7) pins are used and rest 4 pins are grounded.One more job is done by the data lines ,that is these transfers the control signals also from the interfaced circuit to the LCD.

  Power Supply : The device needs an external power supply to work.About required voltage can be found from the LCD datasheet.

   Contrast Setting : This pins takes input from outside interfaced circuit or voltage source in the
range 'Gnd' to 'Vcc'.And according to the voltage level the contrast of the LCD is set.This is simply done by using one Potentiometer(Variable Resistance) between 'Vcc' and 'Gnd' and putting the third pin to the LCD  'Vee' pin'.

    Register Select: Two types of data comes to the LCD Controller one is the 'Control' data  and the second type of data are the data to be displayed on the screen.But their arrives the confusion which data is what ,as all are send to the same data lines.To get rid of the confusion and complexity of differentiation the LCD is provided with a Register Select(R/S) pin which tells the LCD controller the available data is actually what ?If '0'is set on R/S pin the controller treats the available data as DATA.If it is set to '1' it treats it as Control Signal .

      Enable:This pin enables the LCD to communicate with other devices.Only when their is a pulse at this pin the values given to the LCD data pins received by the LCD.So to establish any type of communication with the LCD you need to supply a pulse at the Enable pin.

     R/W: The R/W pin is responsible for all read and write operations.When the pin is LOW it performs the WRITE operations and when the pin is HIGH it performs the READ operations.During Write the data available at the data pins are written to the respective registers depending upon the RS value.And when Read operation is carried out the ,the only reading operation is carried out that is reading the Busy Flag.The red data is available on pin D7.


LCD Controller Memories:
             Different types of memory are present inside the LCD controller namely
                               DDRAM  ( 80 Bytes ):
                                        
                               • CGROM :

                               • CGRAM :
                                        These are used for Special character generation.

                               • BF - Busy Flag :
                                        This shows that a process is currently going on or not inside the controller.The BF is set to '1'  if  a process   is going on or else to '0' if nothing is going on. the BF can be red through the D7 pin of the LCD module.
                               • Instruction Register (IR) : 
                                        Instruction register temporarily holds the instructions coming to the module from the data bus (D0-D7).
                               • Data Register (DR) :
                                        Data register temporarily holds the data coming to the module from the data bus (D0-D7). 

Operating Modes of the Controller:
           
        The module is operated in 2 modes.First one is 4 bit mode and second one is 8 bit modes.Both modes are different in the sense that in case of 4 bit mode only 4 data pins are used whereas in 8 bit mode 8 data pins are used.The 4 bit mode saves 4 pins of the interfacing circuits which becomes important when LCD is to be interfaced to a circuit whose output pins are less.But the 4 bit mode is slower as compared to the 4 bit mode as data has to be transmitted in 4 bit blocks and are transmitted separately as MSB and LSB.
    4bit mode;
          In 4 bit mode the MSB(D5-D7) data pins are only connected and other  connections are same as the 8 bit mode or usual configuration.The remaining data pins are grounded.

    




    8bit mode:
          In 8 bit mode all data pins are  connected and other connections are  like the enable pin,Register Select Pin,R/W pin are connected.

Programming:
   Sending Command :
       1.Move Command to port or D0 to D7 pins.
         2.Select the Command register by setting R/S pin 0.
         3.Select Write Operation by selecting R/W pin to 0.
         4.Send a pulse to the enable pin.
   Sending Data :
       1.Move Data to port or D0 to D7 pins.
         2.Select the Data register by setting R/S pin 1.
         3.Select Write Operation by selecting R/W pin to 0.
         4.Send a pulse to the enable pin.
   Initialization of LCD  in 8 bit mode:

       1.Delay for 20 millisecond.
         2.Send command 0x03
         3. Delay for 10 millisecond.
         4.Send command 0x03.
         5.Delay for 10 millisecond.
         6.Send command 0x03.
         7.Delay for 10 millisecond.
         8.Send command   0x02     //Cursor Home
         9.Send command   0x38 //8 Bit 2 Line Interface
       10.Send command   0x08   //Display Blank
       11.Send command   0x0c  // Display on Cursor off
       12.Send command   0x01 // Clear Screen
       13.Send command   0x06   // Entry Mode
Initialization of LCD in 8 bit mode:

       1.Delay for 20 millisecond.
         2.Send command 0x03
         3. Delay for 10 millisecond.
          
         4.Send command 0x03.
         5.Delay for 10 millisecond.
         6.Send command 0x03.
         7.Delay for 10 millisecond.
         8.Send command   0x02     //Cursor Home
         9.Send command   0x
28 //4 Bit 2 Line Interface
       10.Send command   0x08   //Display Blank
       11.Send command   0x0c  // Display on Cursor off
       12.Send command   0x01 // Clear Screen
       13.Send command   0x06   // Entry Mode
In 4 bit mode the data and commands are send in two parts each having 4 bits so, the Command and Data send functions are different for 4 bit and 8 bit modes.
   4-Bit mode: 
          1.Mask lower 4-bits(MSB is exposed)
          2.Send to the LCD port
          3.Send enable signal
          4.Mask higher 4-bits(LSB is exposed)
          5.Send to LCD port
          6.Send enable signal
.
Example Code using uVision on LPC2148 board :

#include <LPC214X.H>
#include "Serial.h"
#include "Utility.h"
 void cw()
   {
      IOCLR0=0x00001000;  //  Clear RS  pin
                                            // Write Grounded
      IOSET0=0x00004000; //    Set Enable
      DelayProc(CCLOCK * 0.05);
      IOCLR0=0x00004000;  // Clear Enable
      DelayProc(CCLOCK * 0.05);
    }
void dw()
    {
       IOSET0=0x00001000;    //  Set RS  pin
                                               // Write Grounded
       IOSET0=0x00004000;
       DelayProc(CCLOCK * 0.05);
       IOCLR0=0x00004000;
       DelayProc(CCLOCK * 0.05);
     }
SendComm(unsigned int Comm)
     {
   Comm = Comm << 16;
   IO0SET = Comm;
   cw();
   IO0CLR= Comm;
   Comm = Comm << 4;    IO0SET = Comm;
    cw();
   IO0CLR = Comm;
}
SendData( unsigned int Data)
{
   Data = Data << 16;
   IO0SET = Data;
   dw();
   IO0CLR = Data;
   Data = Data << 4;
   IO0SET= Data;
   dw();
   IO0CLR = Data;
}  
char writestring(char *s)
{
   int i=0;
   char c;
   c=*s;
    while(c!='\0')
      {
        SendData(c);
         i=i+1;
         c=*(s+i);
      }
}
void initialization()
{
    DelayProc(CCLOCK * 0.15);
SendComm(0x03);
DelayProc(CCLOCK * 0.05);
SendComm(0x03);
DelayProc(CCLOCK *0.05);
SendComm(0x03);
DelayProc(CCLOCK * 0.05);

  SendComm(0x02);//Cursor Home


//SendComm(0x28); //4 bit 2 rows 5x7 font

//SendComm(0x2c); //4 Bit 2 Rows 5x10 font
SendComm(0x2c);

//SendComm(0x08);//display off cursor off blink off

//SendComm(0x0c);//display on cursor off blink off
SendComm(0x0E);//display on cursor on blink off
//SendComm(0x0F);//display on cursor off blink  on
//SendComm(0x0E);

SendComm(0x01);//Clear screen

//SendComm(0x06);//increment shift 0
SendComm(0x07);//increment shift 1
//SendComm(0x04);//Decrement shift 0
//SendComm(0x05);//Decrement shift 1
//SendComm(0x06);
}
int main()
{
PINSEL0=0x00000000;
PINSEL1=0x00000000;
IODIR0=0xffffffff;
initialization();

while(1)

{
 // SendComm(0x00000001);
  SendComm(0xc4);
  //SendData('A');
  //DelayProc(CCLOCK * 5);
writestring("CHANDAN PATRA");

//DelayProc(CCLOCK * 0.05);

//SendComm(0x01);//Clear screen
//SendComm(0x07);//increment shift 1
//writestring("NIST");
  }
}

Saturday, June 29, 2013

List Of Digital IC

IC No No of    gate(s)




Gate Type








74LS01 4x 




 Two input NAND, Open collector
74LS02 4x




Two input NOR gate
74LS03       4x      




Two input NAND, Open collector    
74LS04   6x  




Inverter (NOT)
74LS05   6x  




Inverter (NOT), Open collector  
74LS06   6x  




Inverter (NOT), High voltage Open collector  
74LS07   6x   




Buffer (NO-OP), High voltage Open collector  
74LS08   4x  




Two input AND  
74LS09   4x   




Two inout AND, Open collector  
74LS10   3x   




Three input NAND  
74LS11    3x  




Three inout AND  
74LS12   3x  




Three input NAND, Open collector  
74LS13   2x  




Four input, Schmitt Trigger NAND   
74LS14   6x  




Inverter (NOT), Schmitt Trigger
74LS16   6x  




Inverter (NOT), High voltage Open collector  
74LS17N   6x  




Buffer (NO-OP), High voltage Open collector  
74LS20   2x




Four input NAND  
74LS21   2x  




Four input AND  
74LS22   2x  




Four input NAND, Open collector  
7423   2x  




Four input NOR with Strobe  
7425   2x  




Four input NOR with Strobe  
74LS26   4x  




Two input NAND, High voltage  
74LS27   3x  




Three input NOR
74LS57P   3x




Frequency divider, 5:1, 6:1, 10:1  
74LS28   4x  




Two input NOR  
74LS30   6x  




Eight input NAND  
74LS31   4x  




DELAY (6nS to 48nS)  
74LS32   4x  




Two input OR  
74LS33   4x  




Two input NOR, Open collector  
74LS37    4x  




Two inout NAND  
74LS38   4x  




Two input NAND, Open collector  
74LS42  





Four-to-Ten (BCD to Decimal) DECODER  
74LS45   --




Four-to-Ten (BCD to Decimal) DECODER, High current  
74LS46   --




BCD to Seven-Segment DECODER, Open Collector, lamp test and leading zero handling   
74LS48   --




BCD to Seven-Segment DECODER, lamp test and leading zero handling  
74LS49    --




BCD to Seven-Segment DECODER, Open collector  
74LS51   --




(a AND b AND c) NOR (c AND e AND f) plus (g AND h) NOR (i AND j)
74LS54   --




NOR of Four Two input ANDs  
74LS55   --




NOR of Two Four input ANDs  
74LS56P    3x  




Frequency divider, 5:1, 5:1, 10:1  
74LS68   2x  




Four bit BCD decimal COUNTER
74LS69   2x  




Four bit binary COUNTER  
74LS73    2x   




JK FLIPFLOP with clear  
74LS74   2x   




D LATCH, edge triggered with clear  
74LS75   4x   




D LATCH, gated  
74LS76A   2x  




JK FLIPFLOP with preset and clear  
74LS77     4x  




D LATCH, gated  
74LS78A   2x  




JK FLIPFLOP with preset and clear  
74LS83    --




Four bit binary ADDER  
74LS85   --




Four bit binary COMPARATOR  
74LS86   4x  




Two input XOR (exclusive or)  
74LS90   --




Four bit BCD decimal COUNTER  
74LS91   --




Eight bit SHIFT register  
74LS93   --




Four bit binary COUNTER   
74LS95B   --




Four bit parallel access SHIFT register  
74LS107A 2x   




JK FLIPFLOP with clear  
74LS109A   2x  




JK FLIPFLOP, edge triggered, with preset and clear 
74LS112A   2x  




JK FLIPFLOP, edge triggered, with preset and clear  
74LS114A    2x




JK FLIPFLOP, edge triggered, with preset  
74LS122   --




Retriggerable Monostable Multivibrator  
74LS123   --




Retriggerable Monostable Multivibrator  
74LS125   4x  




Buffer (NO-OP), (low gate) Tri-state  
74LS132    4x   




Two input NAND, Schmitt trigger  
74LS136   4x   




  Two input XOR (exclusive or), Open collector   
74LS137   --




3-8 DECODER (demultiplexer)  
74LS138   --




3-8 DECODER (demultiplexer)  
74LS139A   2x   




2-4 DECODER (demultiplexer)  
74LS145  





BCD to Decimal decoder and LED driver  
74LS147    --




10-4 priority ENCODER  
74LS148    --




8-3 gated priority ENCODER  
74LS150   --




16-1 SELECTOR (multiplexer)  
74LS151   --




8-1 SELECTOR (multiplexer)  
74LS153    2x




4-1 SELECTOR (multiplexer)  
74LS154   --




4-16 DECODER (demultiplexer)  
74LS155A   2x  




2-4 DECODER (demultiplexer)  
74LS156   2x   




2-4 DECODER (demultiplexer)  
74LS157   4x   




2-1 SELECTOR (multiplexer)  
74LS158   4x  




2-1 SELECTOR (multiplexer)  
74LS160A   --




Four bit synchronous BCD COUNTER with load and asynchronous clear 
74LS161A   --




Four bit synchronous binary COUNTER with load and asynchronous clear  
74LS162A   --




Four bit synchronous BCD COUNTER with load and synchronous clear 
74LS163A   --




Four bit synchronous binary COUNTER with load and synchronous clear  
74LS164   --




Eight bit parallel out SHIFT register  
74LS166A   --




Eight bit parallel in SHIFT register  
74LS169A    --




Four bit synchronous binary up+down COUNTER  
74LS174   6x  




D LATCH with clear
74LS175   4x   




D LATCH with clear and dual outputs  
74LS190   --




Four bit Synchronous up and down COUNTER  
74LS191   --




Four bit Synchronous up and down COUNTER  
74LS193   --




Four bit Synchronous up and down COUNTER  
74LS221   2x  




Monostable multivibrator  
74LS240   8x 




Inverter (NOT), Tri-state  
74LS241   8x   




Buffer (NO-OP), Tri-state
74LS244 8x   




Buffer (NO-OP), Tri-state Line driver  
74LS245    8x   




Bidirectional Tri-state BUFFER  
74LS259 --




Eight bit addressable LATCH  
74LS260   2x  




Five input NOR  
74LS273   8x  




D FLIPFLOP with clear    
74LS279    4x   




SR LATCH  
74LS283  --




Four bit binary full ADDER
74LS373 8x




Transparent (gated) LATCH, Tri-state
74LS374 8x




Edge-triggered LATCH, Tri-state
74LS629  --




Volatge controlled OSCILLATOR
74LS688 --




Eight bit binary COMPARATOR