Saturday, 29 April 2017

Interfacing of Raspberry pi with Led

Interfacing of Raspberry pi with Led:

1)   Led Blinking for Finite Time:
Now ready to write code to switch the LED on and LED off.  Turn on your Raspberry Pi and Open the terminal window.
Create a new text file “led1.py” by typing the following:
Sudo nano led1.py
After that write following code to the Text editer page:

import RPi.GPIO as GPIO
import time
GPIO.setmode(GPIO.BCM) #
board usage gpio pin , bcm usasge pin mnumber
GPIO.setwarnings(False)
GPIO.setup(18,GPIO.OUT)
print "LED on"
GPIO.output(18,GPIO.HIGH)
time.sleep(1)
print "LED off"
GPIO.output(18,GPIO.LOW)

After writing the code we checked it, save and exit the text editor with
 “Ctrl + x” then “y” then “enter”.
To Running this Code Type:

sudo python led1.py
then
You will see the LED turn on for a second and then turn off for a second.



2)   Led Blinking for Infinite Time:

Now ready to write code to switch the LED on and LED off for infinite time.  Turn on your Raspberry Pi and Open the terminal window.
Create a new text file “led2.py” by typing the following:
Sudo nano led2.py
After that write following code to the Text editer page:

import RPi.GPIO as GPIO
from time import sleep
GPIO.setmode(GPIO.BOARD)#board usage gpio pin , bcm usasge pin mnumber
GPIO.setwarnings(False)

for i in range(2,5):
    GPIO.setup(i,GPIO.OUT)
while(1):
    for i in range(2,5):
        GPIO.output(i,True)
        print("true")
        sleep(1)
        GPIO.output(i,False)
        print("false")
        sleep(1)

After writing the code we checked it, save and exit the text editor with
 “Ctrl + x” then “y” then “enter”.
To Running this Code Type:

sudo python led2.py
then
You will see the Leds turn on and  turn off for infinite time .


Circuit Diagram:






Saturday, 28 January 2017

Interfacing of lcd 4 bit with AVR


LCD (Liquid Crystal Display): 
LCD screen is an electronic display module and find a wide range of applications. A 16x2 LCD display is very basic module and is very commonly used in various devices and circuits. These modules are preferred over seven segment and other multi segment LED's. The reasons being: LCDs are economical; easily programmable; have no limitation of displaying special & even custom character (unlike in seven segments), animation and so on. A 16x2 LCD means it can display 16 characters per line and there are 2 such lines. In this LCD each character is displayed in 5x7 pixel matrix. This LCD has two registers, namely, Command and Data.
                      The command register stores the command instructions given to the LCD. A command is an instruction given to LCD to do a predefined task like initializing it, clearing its screen, setting the cursor position, controlling display etc. The data register stores the data to be displayed on the LCD. The data is the ASCII value of the character to be displayed on the LCD. Click to learn more about internal structure of a LCD.
           
Block Diagram of LCD:

LCD stands for liquid crystal display. They come in many sizes 8x1 , 8x2 ,10x2, 16x1 , 16x2 , 16x4 , 20x2 , 20x4 ,24x2 , 30x2 , 32x2 , 40x2 etc . Many multinational companies like Philips Hitachi Panasonic make their own special kind of lcd's to be used in their products. All the lcd’s performs the same functions (display characters numbers special characters ASCII characters etc).Their programming is also same and they all have same 14 pins (0-13) or 16 pins (0 to 15). 

ALL LCDs have
  • Eight(8) Data pins
  • VCC (Apply 5v here)
  • GND (Ground this pin)
  • RS (Register select)
  • RW (read - write)
  • EN (Enable)
  • V0 (Set Lcd contrast)

  • 8-Data pins carries 8-bit data or command from an external unit such as microcontroller.


Lcd have two registers:
1     1   Command Register 
        2   Data Register
 1)  Command Register:   When we send commands to lcd these commands go to Command register and are processed there. Commands with their full description are given in the picture below.
  When RS=0    Command Register is Selected.

2) Data Register: When we send Data to lcd it goes to data register and is processed their.
  When RS=1    Data Register is selected.

16×2 LCD module commands:
16×2 LCD module has a set of preset command instructions. Each command will make the module to do a particular task. These commands are very important for displaying data in LCD. The list of commands given below:

Command
Function
0F
For switching on LCD, blinking the cursor.
1
Clearing the screen
2
Return home.
4
Decrement cursor
6
Increment cursor
E
Display on and also cursor on
80
Force cursor to beginning of the first line
C0
Force cursor to beginning of second line
38
Use two lines and 5x7 matrix
83
Cursor line 1 position 3
3C
Activate second line
0C3
Jump to second line position 3
0C1
Jump to second line position1

LCD initialization:

The steps that has to be done for initializing the LCD display is given below and these steps are common for almost all applications.
§  Send 38H to the 8 bit data line for initialization
§  Send 0FH for making LCD ON, cursor ON and cursor blinking ON.
§  Send 06H for incrementing cursor position.
§  Send 01H for clearing the display and return the cursor.

Sending data to the LCD:

The steps for sending data to the LCD module is given below. I have already said that the LCD module has pins namely RS, R/W and E. It is the logic state of these pins that make the module to determine whether a given data input  is a command or data to be displayed.
- Make R/W low.
-  Make RS=0 if data byte is a command and make RS=1 if the data byte is a data to be displayed.
-  Place data byte on the data register.
-  Pulse E from high to low.
-   Repeat above steps for sending another data.


Interfacing of lcd 4 bit  with AVR


#include <avr/io.h>
#include<util/delay.h>
#define rs PA0
#define rw PA1
#define en PA2

void CMD()
{
PORTA&=~(1<<rs);
PORTA&=~(1<<rw);
PORTA|=(1<<en);
_delay_ms(400);
PORTA&=~(1<<en);

}
void display()
{
PORTA|=(1<<rs);
PORTA&=~(1<<rw);
PORTA|=(1<<en);
_delay_ms(400);
PORTA&=~(1<<en);
}

int main(void)
{int j,i,k;
unsigned char a[]={0x02,0x28,0x0e,0x01,0x80,0x06};
char b[]={"welcome to all"};
   char c[]={"GOD BLESS U "};
while(1)

    {
DDRA=0xFF;
for(i=0;i<=5;i++)
{
PORTA=(a[i]&0xF0);
CMD();
PORTA=((a[i]<<4)&0xF0);
CMD();
}

for(j=0;j<=14;j++)
{
PORTA=(b[j]&0xF0);
display();
PORTA=((b[j]<<4)&0xF0);
display();
}
PORTA=(0xC0&0xF0);
CMD();
PORTA=((0xC0<<4)&0xF0);
CMD();
for(k=0;k<=15;k++)
{

PORTA=(c[k]&0xF0);
display();
PORTA=((c[k]<<4)&0xF0);
display();
}
}



     
    }

Saturday, 17 September 2016

Token Display

Token Display:


Code:


#include<lpc214x.h>
#define PLLE 0
#define PLLC 1
#define PLOCK 10
#define rs 16
#define rw 17
#define en 18
#define lcdport IO0SET
#define lcdportclr IO0CLR
void daten(void);
void cmnd(void);
void pllinit(void);
void delay(int);
void convert(unsigned long int);
void lcdcmd(char);
void lcddata(char);
void lcdinit(void );
void lcdstring(char *);
int main()
{
 IO0DIR=IO0DIR|(0x7f<<16);
 pllinit();
 lcdinit();
 //PINSEL0=PINSEL0|0x20

IO0DIR=IO0DIR|(0xff<<19);
PINSEL0=PINSEL0|(2<<4);//select CAP0.0
T0CTCR=0x01;
T0TC=0;
T0PC=0;
T0TCR=0x02;
T0TCR=0x01;
lcdstring("wainting for pulse or event");
while(1)
{
lcdcmd(0x01);lcdcmd(0x80);
convert(T0TC);
}
return 0;
}

void lcdstring(char *p)
{
lcdcmd(0x8f);
while(*p)
{
lcddata(*p);
lcdcmd(0x1c);
p++;
}
}

void lcdinit()
{
lcdcmd(0x02);
lcdcmd(0x28);
lcdcmd(0x01);
lcdcmd(0x0e);
lcdcmd(0x80);
}
void lcdcmd(char ch)
{
lcdport = ((ch&0xf0)<<15);
cmnd();
lcdportclr = ((ch&0xf0)<<15);

lcdport = (((ch<<4)&0xf0)<<15);
cmnd();
lcdportclr = (((ch<<4)&0xf0)<<15);
}

void lcddata(char ch)
{
lcdport = ((ch&0xf0)<<15);
daten();
lcdportclr = ((ch&0xf0)<<15);

lcdport = (((ch<<4)&0xf0)<<15);
daten();
lcdportclr = (((ch<<4)&0xf0)<<15);
}
void cmnd()
{
lcdportclr = (1<<rs);
lcdportclr = (1<<rw);
lcdport = (1<<en);
delay(1);
lcdportclr = (1<<en);
delay(2);
}
void daten()
{
lcdport = (1<<rs);
lcdportclr = (1<<rw);
lcdport = (1<<en);
delay(1);
lcdportclr = (1<<en);
delay(5);
}
void convert(unsigned long int a) //say a=678
{
int i;int a1;
char pos=0xcd;
for(i=0;i<=9;i++)
{
  lcdcmd(pos);
a1=a%10; //a1=8//7//6//0
a=a/10; //a=67//6//0//0
lcdstring("EVENT NO:");
lcddata(0x30+a1);
pos--;
}

}
void delay(int ms)
{
T1CTCR=0x00;
T1TC=0;
T1PC=0;
T1PR=59999;
T1TCR=0x02;
T1TCR=0x01;
while( T1TC != ms);
T1TCR=0;
}
void pllinit()
{
 PLL0CFG=0x24;
 PLL0CON=PLL0CON|(1<<PLLE);
 PLL0FEED=0xAA;
 PLL0FEED=0x55;
 //PLL0CON=PLL0CON|(1<<PLLC);
 while( (PLL0STAT & (1<<PLOCK))==0);
 PLL0CON=PLL0CON|3;
 PLL0FEED=0xAA;
 PLL0FEED=0x55;
 VPBDIV=0x01;
}
*/



#include<lpc214x.h>
#include<stdio.h>
#define PLLE 0
#define PLLC 1
#define PLOCK 10
#define rs 16
#define rw 17
#define en 18
#define lcdport IO0SET
#define lcdportclr IO0CLR
void daten(void);
void cmnd(void);
void pllinit(void);
void delay(int);
void convert(unsigned long int);
void lcdcmd(char);
void lcddata(char);
void lcdinit(void );
void lcdstring(char *);
char result[4];
int main()
{
 IO0DIR=IO0DIR|(0x7f<<16);
 IO0DIR=IO0DIR|(0xff<<19);
 PINSEL0=PINSEL0|(2<<4);//select CAP0.0
 pllinit();
 lcdinit();
 lcdcmd(0x80);
 lcdstring("EVENT COUNTING");

 delay(200);
 lcdcmd(1);
 lcdstring("EVENT NO:");
 delay(200);
 sprintf(result,"%d",T0TC);
 lcdcmd(0x8A);
 lcdstring(result);
 //PINSEL0=PINSEL0|0x20


T0CTCR=0x01;
T0TC=0;
T0PC=0;
T0TCR=0x02;
T0TCR=0x01;
//lcdstring("wainting for pulse or event");
//lcdcmd(0x80);
//lcdstring("EVENT NO:");
while(1)
{
lcdcmd(0x01);lcdcmd(0x80);
convert(T0TC);
}
return 0;
}

void lcdstring(char *p)
{
//lcdcmd(0x8f);
while(*p)
{
lcddata(*p);
//lcdcmd(0x1c);
p++;
}
}
void convert(unsigned long int a) //say a=678
{
  sprintf(result,"%d",a);
  lcdcmd(0x80);
  lcdstring("EVENT NO:");
  lcdstring(result);
  delay(2000);
  return;

}
void lcdinit()
{
lcdcmd(0x02);
lcdcmd(0x28);
lcdcmd(0x01);
lcdcmd(0x0e);
lcdcmd(0x80);
}
void lcdcmd(char ch)
{
lcdport = ((ch&0xf0)<<15);
cmnd();
lcdportclr = ((ch&0xf0)<<15);

lcdport = (((ch<<4)&0xf0)<<15);
cmnd();
lcdportclr = (((ch<<4)&0xf0)<<15);
}

void lcddata(char ch)
{
lcdport = ((ch&0xf0)<<15);
daten();
lcdportclr = ((ch&0xf0)<<15);

lcdport = (((ch<<4)&0xf0)<<15);
daten();
lcdportclr = (((ch<<4)&0xf0)<<15);
}
void cmnd()
{
lcdportclr = (1<<rs);
lcdportclr = (1<<rw);
lcdport = (1<<en);
delay(1);
lcdportclr = (1<<en);
delay(2);
}
void daten()
{
lcdport = (1<<rs);
lcdportclr = (1<<rw);
lcdport = (1<<en);
delay(1);
lcdportclr = (1<<en);
delay(5);
}

void delay(int ms)
{
T1CTCR=0x00;
T1TC=0;
T1PC=0;
T1PR=59999;
T1TCR=0x02;
T1TCR=0x01;
while( T1TC != ms);
T1TCR=0;
}
void pllinit()
{
 PLL0CFG=0x24;
 PLL0CON=PLL0CON|(1<<PLLE);
 PLL0FEED=0xAA;
 PLL0FEED=0x55;
 //PLL0CON=PLL0CON|(1<<PLLC);
 while( (PLL0STAT & (1<<PLOCK))==0);
 PLL0CON=PLL0CON|3;
 PLL0FEED=0xAA;
 PLL0FEED=0x55;
 VPBDIV=0x01;
}

GSM Based System:

GSM Based System:

Code:


#include<lpc214x.h>
#include<string.h>
#define THRE 5
#define TEMT 6
#define RDR 0
#define PLOCK 10
#define DLAB 7

#define lcdport IO0SET
#define lcdportclr IOCLR0
#define rs 16
#define rw 17
#define en 18
void uart0_init()
{
PINSEL0|=5;
U0LCR=0x83;
U0DLL=97;
U0DLM=0x00;
U0LCR=U0LCR&~(1<<DLAB);
}
void delay(int ms)
{
T1CTCR=0x00;
T1TC=0;
T1PC=0;
T1PR=59999;
T1TCR=0x02;
T1TCR=0x01;
while( T1TC != ms);
T1TCR=0;
}

void cmnd()
{
lcdportclr=(1<<rs);
lcdportclr = (1<<rw);
lcdport = (1<<en);
delay(4);
lcdportclr=(1<<en);
}
void lcdcmd(char ch)
{
lcdport = ((ch&0xf0)<<15);
cmnd();
lcdportclr = ((ch&0xf0)<<15);

lcdport = (((ch<<4)&0xf0)<<15);
cmnd();
lcdportclr = (((ch<<4)&0xf0)<<15);
}

void daten()
{
lcdport=(1<<rs);
lcdportclr = (1<<rw);
lcdport = (1<<en);
delay(4);
lcdportclr=(1<<en);
}

void lcddata(char ch)
{
lcdport = ((ch&0xf0)<<15);
daten();
lcdportclr = ((ch&0xf0)<<15);

lcdport = (((ch<<4)&0xf0)<<15);
daten();
lcdportclr = (((ch<<4)&0xf0)<<15);
}

void lcdstring(char *str)
{
int j;
for(j=0;str[j]!='\0';j++)
{
lcddata(str[j]);
}
}
void lcd_init()
{
lcdcmd(0x02);
lcdcmd(0x28);
lcdcmd(0x01);
lcdcmd(0x0e);
}
void clk_init()
{
PLL0CON=0x01;
PLL0CFG=0x24;
PLL0FEED=0xAA;
PLL0FEED=0x55;
while(!(PLL0STAT & (1<<PLOCK)));
PLL0CON=0x3;
PLL0FEED=0xAA;
PLL0FEED=0x55;
VPBDIV=0x00;
}
void txdata(char ch)
{
U0THR=ch;
while(!(U0LSR & (1<<TEMT)));
}
void txstring(char *str)
{
while(*str)
{
txdata(*str);
U0FCR=0x07;
str++;
}
}


int main()
{
PINSEL0=0x05;
PINSEL2=0x00;

IODIR0=0xfffffff<<2;
clk_init();
lcd_init();
  uart0_init();
//while(1)
{
 lcdcmd(0x01);
 lcdstring("GSM APPLICATION");
txstring("AT\r\n");
delay(100);
txstring("AT+CMGF=1\r\n");
delay(100);
txstring("AT+CMGS=");
txdata(0x22);
txstring("+918888888888");
 delay(10);
txdata(0x22);
txdata('\r');
delay(100);
txstring("welcome to all");
txdata(0x1a);
while(1);
}
}


Simulation:





RFID Attendence System

RFID Attendence System:


Code:


#include<lpc214x.h>
#include<string.h>
#define PLLE 0
#define PLLC 1
#define PLOCK 10
#define DLAB 7
#define TEMT 6
#define DR 0
#define rs 16
#define rw 17
#define en 18
#define lcdport IO0SET
#define lcdportclr IO0CLR
void pll_init(void);
void delay(int);
void uart0_init(void);
void lcd_init(void );
void daten(void);
void cmnd(void);
void delay(int);
void lcdcmd(char);
void lcddata(char);
void lcdstring(char *);
char emp1[]="1600669C55B0";
char emp2[]="160066C78555";
char emp3[]="160055083149";
char emp4[]="110000342F04";
char id[12];
int i;
int main()
{
pll_init();
uart0_init();
lcd_init();
xyz: lcdcmd(0x01);lcdcmd(0x80);
  lcdstring("PLACE CARD");delay(100);
  while(1)
{
for(i=0;i<=11;i++)
{
   while( (U0LSR & (1<<DR)) ==0);
      id[i]=U0RBR;
    }
      id[i]='\0';

if((strcmp(id,emp1)==0))
{
lcdcmd(0x01);lcdcmd(0xc0);
lcdstring("U R EMP1");delay(500);
}
else if((strcmp(id,emp2)==0))
{
lcdcmd(0x01);lcdcmd(0xc0);
lcdstring("U R EMP2");delay(500);
}
else if((strcmp(id,emp3)==0))
{
lcdcmd(0x01);lcdcmd(0xc0);
lcdstring("U R EMP3");delay(500);
}
else if((strcmp(id,emp4)==0))
{
lcdcmd(0x01);lcdcmd(0xc0);
lcdstring("U R EMP4");delay(500);
}
else{
  lcdcmd(0x01);lcdcmd(0xc0);
lcdstring("WORONG ENTRY");delay(500);
}
  goto xyz;
  }
return 0;
}
void uart0_init()
{
PINSEL0|=5;
U0LCR=0x83;
U0DLL=97;
U0DLM=0x00;
U0LCR=U0LCR&~(1<<DLAB);
}
void pll_init()
{
 PLL0CFG=0x24;
 PLL0CON=PLL0CON|(1<<PLLE);
 PLL0FEED=0xAA;
 PLL0FEED=0x55;
 //PLL0CON=PLL0CON|(1<<PLLC);
 while( (PLL0STAT & (1<<PLOCK))==0);
 PLL0CON=PLL0CON|3;
 PLL0FEED=0xAA;
 PLL0FEED=0x55;
 VPBDIV=0x00;
}
void delay(int ms)
{
T1CTCR=0x00;
T1TC=0;
T1PC=0;
T1PR=59999;
T1TCR=0x02;
T1TCR=0x01;
while( T1TC != ms);
T1TCR=0;
}
void lcd_init()
{
IO0DIR=IO0DIR|(0x7f<<16);
lcdcmd(0x02);
lcdcmd(0x28);
lcdcmd(0x01);
lcdcmd(0x0e);
lcdcmd(0x80);
}
void lcdcmd(char ch)
{
lcdport = ((ch&0xf0)<<15);
cmnd();
lcdportclr = ((ch&0xf0)<<15);

lcdport = (((ch<<4)&0xf0)<<15);
cmnd();
lcdportclr = (((ch<<4)&0xf0)<<15);
}

void lcddata(char ch)
{
lcdport = ((ch&0xf0)<<15);
daten();
lcdportclr = ((ch&0xf0)<<15);

lcdport = (((ch<<4)&0xf0)<<15);
daten();
lcdportclr = (((ch<<4)&0xf0)<<15);
}
void cmnd()
{
lcdportclr = (1<<rs);
lcdportclr = (1<<rw);
lcdport = (1<<en);
delay(1);
lcdportclr = (1<<en);
delay(2);
}
void daten()
{
lcdport = (1<<rs);
lcdportclr = (1<<rw);
lcdport = (1<<en);
delay(1);
lcdportclr = (1<<en);
delay(2);
}

void lcdstring(char  *x)
{
while( *x != '\0')
{
lcddata(*x);
x++;
}
}

Simulation:




Friday, 16 September 2016

LINE_FOLLOWER

LINE_FOLLOWER:


Code:



#include<avr/io.h>
#define F_CPU 8000000ul
#include<util/delay.h>

void main()
{
DDRD=0b00000000;   //set PORTC as input port
DDRC=0b00111100;  //PB1, PB2, PB3, PB4 as output port
int ls=0, rs=0;   // define & initialize ls, rs integer as 0 to
// acquire the left sensor status in ls and right sensor
// status in rs
PORTD=0XFF;
while(1)          // create infinite loop
{
ls=(PIND&0b0000001);   //acquire only left sensor status connected at PC0
rs=(PIND&0b0000010);   // acquire only right sensor status connected at PC3

if((ls==0b0000000)&(rs==0b0000000)) //check sensor status for both sensor OFF
{
PORTC=0b00000000;  //stop
_delay_ms(1000);
PORTC=0b00101000;
_delay_ms(500);
PORTC=0b00000100;
_delay_ms(500);
ls=0;              //set sensor status off
rs=0;              //set sensor status off
}

else if((ls==0b0000001)&(rs==0b0000000))  //check sensor status for left sensor=ON and
// right sensor=OFF
{

PORTC=0b00000000;
_delay_ms(200);
PORTC=0b00101000;
_delay_ms(500);
PORTC=0b00000100;    //turn right
_delay_ms(400);
ls=0;                //set sensor status off
rs=0;                //set sensor status off
}

else if((ls==0b0000000)&(rs==0b00000010))  //check sensor status for left sensor=OFF and
// right sensor=ON
{
PORTC=0b00000000;
_delay_ms(200);
PORTC=0b00101000;
_delay_ms(500);
PORTC=0b00010000;   //turn left
_delay_ms(400);
ls=0;               //set sensor status off
rs=0;               //set sensor status off
}

else if((ls==0b0000001)&(rs==0b0000010)) //check sensor status for both sensor ON
{
PORTC=0b00010100;  //move forward
ls=0;              //set sensor status off
rs=0;              //set sensor status off
}
}
}



Simulation:







Mobile_Controlled_Robot

 Mobile_Controlled_Robot:


Code:


#include <avr/io.h>

#define key2 0xfd
#define key4 0xfb
#define key6 0xf9
#define key8 0xf7
#define key5 0xfa

#define left 0x01
#define right 0x02
#define forward 0x03
#define reverse 0x0c
#define stop 0x00

#define key PINA
#define direction PORTC

int main(void)
{
DDRA=0xf0;
DDRC=0xff;
    while(1)
    {
PORTA=0xff;
      if(key==key2)
 direction=forward;

 else if(key==key4)
 direction=left;

 else if(key==key6)
 direction=right;

 else if(key==key8)
 direction=reverse;

 else if(key==key5)
 direction= stop;
    }
}


Circuit Diagram:




Layout: