Total Pageviews

Tuesday, January 28, 2014

4x4x4 led cube connection diagram



8 bit lcd library function for hitech-c

8 bit lcd library function for hitech-c



#ifndef D0
#define D0 RB0
#define D1 RB1
#define D2 RB2
#define D3 RB3
#endif



void Lcd8_Port(char a)
{
if(a & 1)
D0 = 1;
else
D0 = 0;

if(a & 2)
D1 = 1;
else
D1 = 0;

if(a & 4)
D2 = 1;
else
D2 = 0;

if(a & 8)
D3 = 1;
else
D3 = 0;

if(a & 16)
D4 = 1;
else
D4 = 0;

if(a & 32)
D5 = 1;
else
D5 = 0;

if(a & 64)
D6 = 1;
else
D6 = 0;

if(a & 128)
D7 = 1;
else
D7 = 0;
}
void Lcd8_Cmd(char a)
{
  RS = 0;
  RW=  0;         // => RS = 0
  Lcd8_Port(a);             //Data transfer
  EN  = 1;             // => E = 1
  __delay_ms(5);
  EN  = 0;             // => E = 0
}

Lcd8_Clear()
{
 Lcd8_Cmd(1);
}

void Lcd8_Set_Cursor(char a, char b)
{
if(a == 1)
 Lcd8_Cmd(0x80 + b);
else if(a == 2)
Lcd8_Cmd(0xC0 + b);
}

void Lcd8_Init()
{
Lcd8_Port(0x00);
RS = 0;
RW=0;
__delay_ms(25);

  Lcd8_Cmd(0x30);
__delay_ms(5);
  Lcd8_Cmd(0x30);
__delay_ms(15);
  Lcd8_Cmd(0x30);

  Lcd8_Cmd(0x38);    //function set
  Lcd8_Cmd(0x0C);    //display on,cursor off,blink off
  Lcd8_Cmd(0x01);    //clear display
  Lcd8_Cmd(0x06);    //entry mode, set increment
}

void Lcd8_Write_Char(char a)
{
   RS = 1;             // => RS = 1
RW=0;
   Lcd8_Port(a);             //Data transfer
   EN  = 1;             // => E = 1
  __delay_ms(4);
   EN  = 0;             // => E = 04
}

void Lcd8_Write_String(char *a)
{
int i;
for(i=0;a[i]!='\0';i++)
Lcd8_Write_Char(a[i]);
}

void Lcd8_Shift_Right()
{
Lcd8_Cmd(0x1C);
}

void Lcd8_Shift_Left()
{
Lcd8_Cmd(0x18);
}

EXTERNALINTERRUPT(PIC16F877A)-programming





PROGRAM

#include<pic.h>
#include<htc.h>

#define RS RC0
#define RW RC1
#define EN RC2
#define D0 RD0
#define D1 RD1
#define D2 RD2
#define D3 RD3
#define D4 RD4
#define D5 RD5
#define D6 RD6
#define D7 RD7 

#define _XTAL_FREQ 4000000
__CONFIG(WDTDIS & XT & UNPROTECT);
#include"lcd.h"
char a[10];
int count=0,i;
void interrupt isr()
{
if(INTF==1)
{
count++;
i=count;
a[1]=i%10+0x30;
i=i/10;
a[2]=i%10+0x30;
if(count<10)
{
Lcd8_Clear();
Lcd8_Set_Cursor(1,0);
Lcd8_Write_Char(a[1]);
}

if(count>9)
{
Lcd8_Clear();
Lcd8_Set_Cursor(1,0);
Lcd8_Write_Char(a[2]);
Lcd8_Set_Cursor(1,1);
Lcd8_Write_Char(a[1]);
}
INTF=0;
}
}



void main()
{

TXSTA=0X24;
RCSTA=0X90;
SPBRG=0X19;
TRISC=0x80;
TRISD=0x00;
TRISB=0x01;
TXIF=0;
RCIF=0;
GIE=1;
PEIE=1;
RCIE=1;
INTE=1;
INTEDG=1;
INTF=0;
Lcd8_Init();
Lcd8_Clear();
Lcd8_Set_Cursor(1,0);
Lcd8_Write_String("interrupt");
while(1);
}

EXTERNAL INTERRUPT CONFIGURATION IN PIC16F877A

EXTERNAL INTERRUPT CONFIGURATION IN PIC16F877A


  1. External interrupt pin of pic16f877a is RB0.
  2. for setting external interrupt first set TRISB=0x00;(as output)
  3. Then GIE=1,PEIE=1 and INTE=1
  4. Then write interrupt service routine
  5. When interrupt happen the flag INTF will set.
  6. Then clear the flag in interrupt routine itself for next interrupt
  7. sample code is given below.
   #include<pic.h>
    int i;
    void interrupt isr()
   {
     if(INTF==1)
     {
         i++;
         INTF=0;
      }
    }
 
    void main()
    {
        TRISB=0x00;
        GIE=1;
        PEIE=1;
        INTE=1;
      while(1);
     }


This is the program for external interrupt in pic 16f877a micro controller

Friday, January 24, 2014

PIC16F877A basic tutorial

PIC16F877A
PIN DIAGRAMS

I/O PORTS                DIRECTION CONTROL REG.    NO OF PINS
PORTA                                  TRISA                                                6
PORTB                                  TRISB                                                8
PORTC                                  TRISC                                                8
PORTD                                  TRISD                                                8
PORTE                                  TRISE                                                3

EXAMPLE:
                        TRISB=0XFF     MAKE PORTB AS INPUT PORT
                        TRISB=0X00      MAKE PORTB AS OUTPUT PORT
BASIC PROGRAM TO ON/OFF LED’S
#include<pic.h>
void delay()
{
int i;
for(i=0;i<10000;i++);
}

void main()
{
TRISA=0X00;                       // MAKE PORTA AS OUTPUT//
while(1)
{
PORTA=0XFF;                    //LED’S - ON//
delay();
PORTA=0X00;                     //LED’S-OFF//
delay();
}
}

UNIVERSAL SYNCHRONOUS ASYNCHRONOUS RECEIVER TRANSMITTER (USART)



SPBRG=X
BAUD RATE =FOSC / (16(X+1))

BASIC PGM FOR TRANSMISSION
# include<pic.h>
#define _XTAL_FREQ 4000000
__CONFIG(WDTDIS & XT & UNPROTECT);

void main()
{
TXSTA=0X24;
RCSTA=0X90;
SPBRG=0X19;
TRISC=0X80;
while(1)
{
TXREG='k';
while(TXIF==0);
TXIF=0;
}
}
LCD INTERFACING PROGRAM
#include<pic.h>
#define _XTAL_FREQ 4000000
__CONFIG(WDTDIS & XT & UNPROTECT);
void delay()
{
int i;
for(i=0;i<10;i++);
}
void COMMAND(char t)
{
PORTD=t;
RC0=0;
RC1=0;
RC2=1;
delay();
RC2=0;
}
void data(char t)
{
PORTD=t;
RC0=1;
RC1=0;
RC2=1;
delay();
RC2=0;
}
void main()
{
TRISC=0X00;
TRISD=0X00;
COMMAND(0X06);
COMMAND(0X0E);
COMMAND(0X01);
COMMAND(0X80);
COMMAND(0X38);
while(1)
{
data('w');
delay();
}

}

Basic Circuit Of PIC16F877A


Basic Circuit Of PIC16F877A

Power Supply

To start up your PIC16F877A, there are 7 pins you should connect correctly. Likes others electronic component, the supply pin is the most important. The ideal voltage for PIC16F877A is 5V (Direct Current). It should not be higher then 5.5V because it going to blow up. It also should not be less then 2V because it not going to be operate. You will have various type of supply such as battery and DC adapter. The problem is, if you use battery, it hard to fine normal battery in 5V. Yes you can use 3 normal 1.5V battery that connected in series. But I don’t think it will be efficient enough. So how if I use 9V battery? Yes I can use it but I need to step it down to 5V. How? You can use voltage regulator. LM7805 the part number of the voltage regulator that I used. The two number at the end of the part number is 05 which is mean it will step down the larger input voltage to 5V. Let say if use LM7809 it will step down the higher voltage then 9V to 9V. Here is the datasheet. This is the basic connection to step down 9V to 5V by using LM7805.

Using LM7805 is not only limited to battery supply source. But you can also use it at your rectifier circuit. Picture below show how the connection from the output of rectifier to the LM7805 and to PIC16F877.

Reset Pin
So, how to give power supply to PIC is already covered. As I said before, there are 7 pins should be connect in order to let your PIC operate. 4 pins is already connected which is 2 pins for 5V and 2 pin for ground (negative). It 3 more pins left. The other important pin is Reset pin (MCLR - Master Clear Reset at Pin number 1). If PIC read 0V at MCLR pin, it will reset the program, so if you not connect the MCLR pin with 5V, PIC will remain reset and your program will not execute. You can directly connect the MCLR with 5V (series with resistor likes picture below) but you will unable to reset if your system goes wrong.


If you want to use the reset function, you need to create logic condition which is 1 and 0 to the reset pin. 1 is mean the reset pin get 5V. If the reset pin logic is 1, then the program in your PIC will execute, but if the reset pin logic condition is 0 (which is 0V) then your PIC will not execute the program.
Logic Condition
Voltage
Program Status
0
0V
Not Execute
1
5V
Execute
So, how you can get this condition? The answer is simple, you just need a switch. But you cannot simply add a switch between the 5V and the reset pin. You will need the Pull Up Resistor. What is that thing? See the picture below, that is the correct way how to add up a switch in order to create the logic condition.



When the switch is not pushed, current will flow trough 10K resistor and MCLR Pin. As a result, MCLR Pin receive 5V and PIC read it as logic 1. But when switch is push, current will flow through 10K resistor, switch and directly to ground. There is no voltage will receive at MCLR Pin. This give 0 logic at MCLR Pin.


The Oscillator
Five from seven of important pins already covered, now there are only 2 pin left which is pin number 13 and 14. Those pin was named as OSC1 and OSC2. You can connect the crystal osillator from various frequency. Pulse generated from the oscillator will some time have the noise. To reduce the noise, two capacitors in piko farad value is needed. The value of capacitor is depend on the speed of oscillator that you use. Here is the way how to connect the the crstal oscillator and capacitor value table.
VCC (+5V)
GND
PIN 11
PIN 12
PIN 32
PIN 31
















SAMPLE TRANSMISSION PROGRAM FOR PIC16F877A

SAMPLE TRANSMISSION PROGRAM FOR PIC16F877A



# include<pic.h>

#define _XTAL_FREQ 4000000

__CONFIG(WDTDIS & XT & UNPROTECT);

void main()
{
TXSTA=0X24;
RCSTA=0X90;
SPBRG=0X19;
TRISC=0X80;
while(1)
{
TXREG='k';
while(TXIF==0);
TXIF=0;
}
}

This is a sample program for transmitting character 'k' continuously.

DISASTER MANAGEMENT ROBOT CONNECTION DIAGRAM


Wednesday, January 22, 2014

Tuesday, January 21, 2014

SERIAL COMMUNICATION FOR PROTEUS

To do serial communication through putty or terminal software for proteus just follow the below steps.

1.
   Use COMPIM in devices->miscellaneous as DB9

In COMPIM  edit properties as follow


 Then use a software named as VPSE


Configure VPSE as follows


1.

Select device in toolbar. Select device type as connector. Then click next.

2.

Select the desired com port . Then tick emulate baud rate. Press finish.


3.

  Now press the play button. Thats all now you can do the serial communication using terminal or putty for proteus.

THANKS,


PUTTY - faster serial communication software

http://www.putty.org/
.http://www.downloadputty.net/

Putty is a faster serial communication software . For configuration check the previous post

TERMINAL SOFTWARE FOR SERIAL COMMUNICATION

http://free-serial-port-terminal.software.informer.com/1.0/

Use terminal software for view serial communication between PC and micro controllers.
-> Select port for your serial cable
-> Set baud rate as 9600
-> Bit used is 8
-> Parity as none
-> Stop bit as 1
-> Handshaking as none

Plug your serial cable and play......................................

MPLAB programming for PIC

while opening MPLAB we will get this window.

From project select project wizard.

Click next and select the device that you want.Here i am using pic16f877a.


Click next . Then select Hitech-c compiler.


Then select next and name your project by browsing.


Then click next.
Next.



Then click finish.

After finish you will get this window . Then create a new file .


Then save the new file with an extension  *.c
Right click on source file in .mcw window ,Select add file and add the corresponding .c file that you saved. Here i am saved as sample.c that's why i am adding sample.c file as source file

Like this you can write your program. After writing the program you can check the program for error by using build button in toolbar.
If your program is correct you will get this winow


Thank you,