-->

ADC Interfacing with 8051

By
ADC Interfacing with 8051


Read the Introduction here for the ADC  tutorials .   For LCD tutorials Click here

Both the above two tutorials combined  and  tried to read the adc value and Displaying the value in 16x2 LCD only for the learning purpose . If you have any doubt ask me By emailing thnnara123@gmail.com ,or comment below .


 Circuit 



Program In written Keil  with C compiler 
**********************************************************************************
Main file // ADC File
***********************************************************************************
#include <REGX51.H>  
#include "lcd.h" 
#include"adc.h"
#define test_port P2
#include<stdio.h>

void main(){
unsigned char buffer[8];

int adc_value;
LCDPORT = 0x00;
adc_port = 0xFF;
test_port =0x00;
lcd_init();
string("adc ");
get_adc();
P2 = adc_port;
adc_value = 0x60;//adc_port;
LINE2
sprintf(buffer,"%d",adc_value);   // used to convert Binary value from ADC to ASCI value for Lcd

string(buffer);

while(1);

}

***********************************************************************************
    adc.h // ADC Header File
************************************************************************************
#define adc_port P3
sbit RD_adc = P1^0;
sbit WR_adc = P1^1;
sbit INTR = P1^2; 

 get_adc()
 { 
  
 WR_adc = 0;
 delay(1);
 WR_adc =1;
 while(INTR==1);
 RD_adc = 1;
 delay(1);
 RD_adc = 0;

  }
**********************************************************************************
LCD.h // LCD Header File
***********************************************************************************
 #include"delay.h"
 #define LCDPORT P0  // named the Port2 as LCDPORT
 sbit RS=LCDPORT^2;  // P2.2 named RS
 sbit E=LCDPORT^3;  // P2.3 named as E
 #define LINE2 lcd_cmd(0xc0);   // used to display the second line oxc0 is 
 
 
 void latch(void)  // used to a high to low pulse the pin E 
{
    E = 1;
    delay(1);
    E = 0;
}

void lcd_cmd(unsigned char c)   // used to send the command / Instruction to the lcd port 
{          
RS = 0;    // send a '0' value to select to send command
delay(1);     
LCDPORT = c & 0xf0;  //  send  the command c only 4 bit by masking the lower bit 
latch();
delay(1); 
LCDPORT =  (c << 4); // giving the lowerbit  by shifting the 4 bit to left 
latch(); 
}

 void lcd_data(unsigned char c)
 {
 RS =1;    // send 1 to send data 
 delay(1);
LCDPORT = c & 0xf0 | 0x4; //send  the data  only  4 bit by masking the lower bit and also making the RS pin high by giving 0x04 .
delay(1);
latch();

LCDPORT = (c << 4)| 0x4; ; // giving the lower bit  by shifting the 4 bit to left 
latch(); 
}
 
void lcd_init()
{
  delay(20);
    lcd_cmd(0x30);  //as per data sheet
  delay(20);
    lcd_cmd(0x30);    //as per data sheet
  delay(4);
    lcd_cmd(0x32);    //as per data sheet
 delay(4);
    lcd_cmd(0x28);            // Function set (4-bit interface, 2 lines, 5*7Pixels)
    lcd_cmd(0x28);            // Function set (4-bit interface, 2 lines, 5*7Pixels)
    lcd_cmd(0x0c);            // Make cursorinvisible
    lcd_cmd(0x6);            // Set entry Mode(auto increment of cursor)
}

 void string(const char *q)    // used to send single charcter to display the lcd 
{
    while (*q) {
        lcd_data(*q++);
    }
}
***********************************************************************************
To download the Whole Project Click here

LCD 4 Bit Interfacing with AVR

By
LCD 4 Bit Interfacing with AVR  -Atmega16

After interfacing with 8051 and PIC16f877  am providing AVR interfacing to LCD ,with a light changing in the previous code (ClikHere) .

I am taken Atmeg16 Controller . 




************* Please Comment If you have Doubt **********


/*
 * LCD4bit.c
 *
 * Created: 16-Sep-15 10:22:26 PM
 * Author: Krishna
 */

#define F_CPU 12000000UL
#include <avr/io.h>
#include<util/delay.h>
#define LCDPORT PORTD // Renaming the PORTD to LCDPORT
#define RS PD2 // Renaming the RS pin to 2
#define E PD3 // Renaming the E to number 3
#define LINE2 lcd_cmd(0xc0);
void latch(void) // used to a high to low pulse the pin E
{
PORTD |= ~(1<<E); // here we give a high to PORTD.3
_delay_ms(1);
PORTD |= (1<<E); // Here we give a LOW to PORTD.#
}




void lcd_cmd(unsigned char c) // used to send the command / Instruction to the lcd port
{
PORTD |= ~(1<<RS); // send a '0' value to select to send command
_delay_ms(1);
LCDPORT = c & 0xf0; // send the command c only 4 bit by masking the lower bit
latch();
_delay_ms(1);
LCDPORT = (c << 4); // giving the lowerbit by shifting the 4 bit to left
latch();
}

 void gotoxy(unsigned char  x,unsigned char y)  
{
if(x<40)
{
if(y) x|=0b01000000;
x|=0b10000000;
lcd_cmd(x);
}

void lcd_data(unsigned char c)
{
PORTD |= (1<<RS); // send 1 to send data
_delay_ms(1);
LCDPORT = c & 0xf0| 0x4; //send the data only 4 bit by masking the lower bit and also making the RS pin high by giving 0x04 .
_delay_ms(1);
latch();

LCDPORT = (c << 4)| 0x4; ; // giving the lower bit by shifting the 4 bit to left
latch();
}

void lcd_init()
{
_delay_ms(20);
lcd_cmd(0x30); //as per data sheet
_delay_ms(20);
lcd_cmd(0x30); //as per data sheet
_delay_ms(4);
lcd_cmd(0x32); //as per data sheet
_delay_ms(4);
lcd_cmd(0x28); // Function set (4-bit interface, 2 lines, 5*7Pixels)
lcd_cmd(0x28); // Function set (4-bit interface, 2 lines, 5*7Pixels)
lcd_cmd(0x0c); // Make cursorinvisible
lcd_cmd(0x6); // Set entry Mode(auto increment of cursor)
}

void string(const char *q) // used to send single charcter to display the lcd
{
while (*q) {
lcd_data(*q++);
}
}


void main(){

DDRD = 0xFF;
lcd_init();
string("Lcd Testing ");
LINE2
string("its displaying ");
while(1);
}



Circuit Diagram 
Downloa here the Full project including Proteus Click here

LCD 4 Bit Interfacing with AVR

By
LCD 4 Bit Interfacing with AVR  -Atmega16

After interfacing with 8051 and PIC16f877  am providing AVR interfacing to LCD ,with a light changing in the previous code (ClikHere) .

I am taken Atmeg16 Controller . 




************* Please Comment If you have Doubt **********


/*
 * LCD4bit.c
 *
 * Created: 16-Sep-15 10:22:26 PM
 *  Author: Krishna
 */ 

#define F_CPU 12000000UL
#include <avr/io.h>
#include<util/delay.h>
#define LCDPORT PORTD   // Renaming the PORTD to LCDPORT
#define RS PD2          // Renaming the RS pin to 2 
#define E PD3            // Renaming the E to number 3
#define LINE2 lcd_cmd(0xc0);  
 void latch(void)  // used to a high to low pulse the pin E
 {
  PORTD |= ~(1<<E);  // here we give a high to PORTD.3
 _delay_ms(1);
  PORTD |= (1<<E);   // Here we give a LOW to PORTD.#
 }
 
 
 
 
 void lcd_cmd(unsigned char c)   // used to send the command / Instruction to the lcd port
 {
  PORTD |= ~(1<<RS);    // send a '0' value to select to send command
  _delay_ms(1);
  LCDPORT = c & 0xf0;  //  send  the command c only 4 bit by masking the lower bit
  latch();
  _delay_ms(1);
  LCDPORT =  (c << 4); // giving the lowerbit  by shifting the 4 bit to left
  latch();
 }

 void gotoxy(unsigned char  x,unsigned char y)  
{
 if(x<40)
 {
  if(y) x|=0b01000000;
  x|=0b10000000;
  lcd_cmd(x);
  }
 
 void lcd_data(unsigned char c)
 {
  PORTD |= (1<<RS);    // send 1 to send data
  _delay_ms(1);
  LCDPORT = c & 0xf0| 0x4; //send  the data  only  4 bit by masking the lower bit and also making the RS pin high by giving 0x04 .
  _delay_ms(1);
  latch();
  
  LCDPORT = (c << 4)| 0x4; ; // giving the lower bit  by shifting the 4 bit to left
  latch();
 }
 
  void lcd_init()
  {
   _delay_ms(20);
   lcd_cmd(0x30);  //as per data sheet
   _delay_ms(20);
   lcd_cmd(0x30);    //as per data sheet
   _delay_ms(4);
   lcd_cmd(0x32);    //as per data sheet
   _delay_ms(4);
   lcd_cmd(0x28);            // Function set (4-bit interface, 2 lines, 5*7Pixels)
   lcd_cmd(0x28);            // Function set (4-bit interface, 2 lines, 5*7Pixels)
   lcd_cmd(0x0c);            // Make cursorinvisible
   lcd_cmd(0x6);            // Set entry Mode(auto increment of cursor)
  }
 
  void string(const char *q)    // used to send single charcter to display the lcd
  {
   while (*q) {
    lcd_data(*q++);
   }
  }
 
 
void main(){
 
  DDRD = 0xFF;
 lcd_init();
  string("Lcd Testing ");
 LINE2
 string("its displaying ");
 while(1);
}


Circuit Diagram 
Downloa here the Full project including Proteus Click here

4-Bit LCD Interfacing with PIC 16f877 -MPLABX

By
4-Bit LCD Interfacing with PIC 16f877 -MPLABX :-

The Previous Post click Here talked about How to interface LCD in 4 bit mode with 8051 . with a little changes of the previous  code, we can use it in PIC16F877a with MPLABx ..




#include 
// CONFIG
#pragma config FOSC = HS // Oscillator Selection bits (HS oscillator)
#pragma config WDTE = ON // Watchdog Timer Enable bit (WDT enabled)
#pragma config PWRTE = OFF // Power-up Timer Enable bit (PWRT disabled)
#pragma config BOREN = OFF // Brown-out Reset Enable bit (BOR disabled)
#pragma config LVP = ON // Low-Voltage (Single-Supply) In-Circuit Serial Programming Enable bit (RB3/PGM pin has PGM function; low-voltage programming enabled)
#pragma config CPD = OFF // Data EEPROM Memory Code Protection bit (Data EEPROM code protection off)
#pragma config WRT = OFF // Flash Program Memory Write Enable bits (Write protection off; all program memory may be written to by EECON control)
#pragma config CP = OFF // Flash Program Memory Code Protection bit (Code protection off)


#define _XTAL_FREQ 8000000
#define LCDPORT PORTB
#define RS RB2
#define E RB3
//#define LIINE2 lcd_cmd(0xc0)

void latch(void)
{
E = 1;
__delay_ms(1);
E = 0;

}
void lcd_cmd(unsigned char c) // used to send the command / Instruction to the lcd port
{
RS = 0; // send a '0' value to select to send command
__delay_ms(1);
LCDPORT = c & 0xf0; // send the command c only 4 bit by masking the lower bit
latch();
__delay_ms(1);
LCDPORT = (c << 4); // giving the lowerbit by shifting the 4 bit to left
latch();
}
void lcd_data(unsigned char c)
{
RS =1; // send 1 to send data
__delay_ms(1);
LCDPORT = c & 0xf0 | 0x4; //send the data only 4 bit by masking the lower bit and also making the RS pin high by giving 0x04 .
__delay_ms(1);
latch();

LCDPORT = (c << 4)| 0x4; ; // giving the lower bit by shifting the 4 bit to left
latch();
}

void lcd_init()
{
__delay_ms(20);
lcd_cmd(0x30); //as per data sheet
__delay_ms(20);
lcd_cmd(0x30); //as per data sheet
__delay_ms(4);
lcd_cmd(0x32); //as per data sheet
__delay_ms(4);
lcd_cmd(0x28); // Function set (4-bit interface, 2 lines, 5*7Pixels)
lcd_cmd(0x28); // Function set (4-bit interface, 2 lines, 5*7Pixels)
lcd_cmd(0x0c); // Make cursorinvisible
lcd_cmd(0x6); // Set entry Mode(auto increment of cursor)
}

void string(const char *q) // used to send single charcter to display the lcd
{
while (*q) {
lcd_data(*q++);
}
}


void main()
{
TRISB = 0x00;

lcd_init();
string("Lcd working ");
lcd_cmd(0xc0);
string("its displaying ");
while(1);
}


Download the full project including Proteus File Clik here

4-Bit LCD Interfacing with PIC 16f877 -MPLABX

By
4-Bit LCD Interfacing with PIC 16f877 -MPLABX :-

The Previous Post click Here talked about How to interface LCD in 4 bit mode with 8051 . with a little changes of the previous  code, we can use it in PIC16F877a with MPLABx ..




#include 
// CONFIG
#pragma config FOSC = HS        // Oscillator Selection bits (HS oscillator)
#pragma config WDTE = ON        // Watchdog Timer Enable bit (WDT enabled)
#pragma config PWRTE = OFF      // Power-up Timer Enable bit (PWRT disabled)
#pragma config BOREN = OFF      // Brown-out Reset Enable bit (BOR disabled)
#pragma config LVP = ON         // Low-Voltage (Single-Supply) In-Circuit Serial Programming Enable bit (RB3/PGM pin has PGM function; low-voltage programming enabled)
#pragma config CPD = OFF        // Data EEPROM Memory Code Protection bit (Data EEPROM code protection off)
#pragma config WRT = OFF        // Flash Program Memory Write Enable bits (Write protection off; all program memory may be written to by EECON control)
#pragma config CP = OFF         // Flash Program Memory Code Protection bit (Code protection off)


#define _XTAL_FREQ 8000000
#define LCDPORT PORTB
#define RS RB2
#define E RB3
//#define LIINE2 lcd_cmd(0xc0)

void latch(void)
{
    E = 1;
    __delay_ms(1);
    E = 0;

}
void lcd_cmd(unsigned char c)   // used to send the command / Instruction to the lcd port
{
RS = 0;    // send a '0' value to select to send command
__delay_ms(1);
LCDPORT = c & 0xf0;  //  send  the command c only 4 bit by masking the lower bit
latch();
__delay_ms(1);
LCDPORT =  (c << 4); // giving the lowerbit  by shifting the 4 bit to left
latch();
}
 void lcd_data(unsigned char c)
 {
 RS =1;    // send 1 to send data
 __delay_ms(1);
LCDPORT = c & 0xf0 | 0x4; //send  the data  only  4 bit by masking the lower bit and also making the RS pin high by giving 0x04 .
__delay_ms(1);
latch();

LCDPORT = (c << 4)| 0x4; ; // giving the lower bit  by shifting the 4 bit to left
latch();
}

 void lcd_init()
{
 __delay_ms(20);
    lcd_cmd(0x30);  //as per data sheet
  __delay_ms(20);
    lcd_cmd(0x30);    //as per data sheet
  __delay_ms(4);
    lcd_cmd(0x32);    //as per data sheet
 __delay_ms(4);
    lcd_cmd(0x28);            // Function set (4-bit interface, 2 lines, 5*7Pixels)
    lcd_cmd(0x28);            // Function set (4-bit interface, 2 lines, 5*7Pixels)
    lcd_cmd(0x0c);            // Make cursorinvisible
    lcd_cmd(0x6);            // Set entry Mode(auto increment of cursor)
}

 void string(const char *q)    // used to send single charcter to display the lcd
{
    while (*q) {
        lcd_data(*q++);
    }
}


void main()
{
    TRISB = 0x00;

lcd_init();
string("Lcd working ");
lcd_cmd(0xc0);
string("its displaying ");
while(1);
}


Download the full project including Proteus File Clik here

MPLAB XC8 Compiler – LED Blinking - Basic Start-up Tutorials

By
A sample program to blink an LED  by using MPLBX - C Compilers  in  PIC16F877A as our previous post  PIC Microcontroller Tutorial gives the basic Details of PIC16f877A.

           In MPLABX  at first we need to configure the bit first.  That means ,


  •  How or what type Oscillator will use  ?
  •  Is there needed Watch Dog timer ?
  •  Program Memory Code Protection bit ie, no one can be read the HEX code from  the Controller.

      For more learn from Here.

#include<xc.h> 
// CONFIG
#pragma config FOSC = HS // Oscillator Selection bits (HS oscillator)
#pragma config WDTE = ON // Watchdog Timer Enable bit (WDT enabled)
#pragma config PWRTE = OFF // Power-up Timer Enable bit (PWRT disabled)
#pragma config BOREN = OFF // Brown-out Reset Enable bit (BOR disabled)
#pragma config LVP = ON // Low-Voltage (Single-Supply) In-Circuit Serial Programming Enable bit (RB3/PGM pin has PGM function; low-voltage programming enabled)
#pragma config CPD = OFF // Data EEPROM Memory Code Protection bit (Data EEPROM code protection off)
#pragma config WRT = OFF // Flash Program Memory Write Enable bits (Write protection off; all program memory may be written to by EECON control)
#pragma config CP = OFF // Flash Program Memory Code Protection bit (Code protection off)


#define _XTAL_FREQ 8000000 // taking as crystal frequency as 8Mhz
#define LED_Port PORTD // defining PORTD as LED_Port
int main()
{
TRISD = 0x00; // Making PORTD as output
while(1)
{
LED_Port =0Xff; // giving High values to Port to lightup LED
__delay_ms(500); // giving a half second delay
LED_Port = 0x00; // Giving a low to port to turn off the LEDs
__delay_ms(500);
}

}

MPLAB XC8 Compiler – LED Blinking - Basic Start-up Tutorials

By
A sample program to blink an LED  by using MPLBX - C Compilers  in  PIC16F877A as our previous post  PIC Microcontroller Tutorial gives the basic Details of PIC16f877A.

           In MPLABX  at first we need to configure the bit first.  That means ,


  •  How or what type Oscillator will use  ?
  •  Is there needed Watch Dog timer ?
  •  Program Memory Code Protection bit ie, no one can be read the HEX code from  the Controller.

      For more learn from Here.

#include<xc.h> 
// CONFIG
#pragma config FOSC = HS        // Oscillator Selection bits (HS oscillator)
#pragma config WDTE = ON        // Watchdog Timer Enable bit (WDT enabled)
#pragma config PWRTE = OFF      // Power-up Timer Enable bit (PWRT disabled)
#pragma config BOREN = OFF      // Brown-out Reset Enable bit (BOR disabled)
#pragma config LVP = ON         // Low-Voltage (Single-Supply) In-Circuit Serial Programming Enable bit (RB3/PGM pin has PGM function; low-voltage programming enabled)
#pragma config CPD = OFF        // Data EEPROM Memory Code Protection bit (Data EEPROM code protection off)
#pragma config WRT = OFF        // Flash Program Memory Write Enable bits (Write protection off; all program memory may be written to by EECON control)
#pragma config CP = OFF         // Flash Program Memory Code Protection bit (Code protection off)


#define _XTAL_FREQ 8000000 // taking as crystal frequency as 8Mhz
#define LED_Port PORTD     // defining PORTD as LED_Port
int main()
{
    TRISD = 0x00;          // Making PORTD as output
    while(1)
    {
        LED_Port =0Xff;    // giving High values to Port to lightup LED
        __delay_ms(500);   // giving a half second delay
        LED_Port = 0x00;   // Giving a low to port to turn off the LEDs
        __delay_ms(500);
    }

}

Configuration Bits setting in MPLABX

By
Set Configuration Bits -PIC16f877.


How Configuration Bits are set

Each PIC MCU has it's own set of configuration bits. The Special Features section of the individual datasheets contains the definition for each of the bits.
The setting for each configuration bit is determined by directives written in the application software. The syntax for the configuration bit settings is available from the compiler manual. This tutorial will show how to generate proper configuration code without consulting the compiler manual for the proper syntax.

How to display the Configuration Bits window

                                                 From the main menu select Window ▶ PIC Memory Views ▶ Configuration Bits

ConfigBitsMenu.pngConfigBitsWindow.png

The Configuration Bits window will open in a tab in the Output area under the editor.

How to set configuration bits and generate initialization code



ConfigBits.png
In the configuration bits window, click on any value in the Option column and it will turn into a combo box that will allow you to select the value you desire.

The example on the left shows the WatchDog timer being changed from "enabled" to "disabled"

GenerateConfigBits.png




Click on the Generate Source Code to Outputbutton:

ConfigBitsSaveAs.png

The IDE will automatically generate the code necessary to initialize all the configuration bits to the settings you specified in the window. This code may now be copied and pasted into one of your source files, or you may save it to its own file and add it to your project. To save the file, right click anywhere in the output window and select Save Asfrom the popup menu as shown in the screenshot at left.

Configuration Bits setting in MPLABX

By
Set Configuration Bits -PIC16f877.


How Configuration Bits are set

Each PIC MCU has it's own set of configuration bits. The Special Features section of the individual datasheets contains the definition for each of the bits.
The setting for each configuration bit is determined by directives written in the application software. The syntax for the configuration bit settings is available from the compiler manual. This tutorial will show how to generate proper configuration code without consulting the compiler manual for the proper syntax.

How to display the Configuration Bits window

                                                 From the main menu select Window ▶ PIC Memory Views ▶ Configuration Bits

ConfigBitsMenu.pngConfigBitsWindow.png

The Configuration Bits window will open in a tab in the Output area under the editor.

How to set configuration bits and generate initialization code



ConfigBits.png
In the configuration bits window, click on any value in the Option column and it will turn into a combo box that will allow you to select the value you desire.

The example on the left shows the WatchDog timer being changed from "enabled" to "disabled"

GenerateConfigBits.png




Click on the Generate Source Code to Outputbutton:

ConfigBitsSaveAs.png

The IDE will automatically generate the code necessary to initialize all the configuration bits to the settings you specified in the window. This code may now be copied and pasted into one of your source files, or you may save it to its own file and add it to your project. To save the file, right click anywhere in the output window and select Save Asfrom the popup menu as shown in the screenshot at left.

PIC microcontroller tutorial

By
PIC Microcontroller Tutorial

Every Microcontroller (also MCU) consists of several major units:
  • Input / Output Ports
  • Control Pins: reset, power, clock
  • Processor (CPU)
  • Memory (RAM, ROM, EEPROM)
  • Serial and parallel ports
  • Timers
  • Analog-to-digital (A/D) and digital-to-analog (D/A) converters
Microcontrollers PICmicro MCU from Microchip Company divided into 4 large families. Each family has a variety of components that provide built-in special features:
1. The first family, PIC10 (10FXXX) - is called Low End.
The PIC10FXXX devices from Microchip Technology are low-cost, high-performance, 8-bit, fully static, Flash-based CMOS microcontrollers. They employ a RISC architecture with only 33 single-word/ single-cycle instructions. The 12-bit wide instructions are highly symmetrical. The easy-to-use and easy to remember instruction set reduces development time significantly. The PIC10FXXX devices contain an 8-bit ALU and working register.

2. The second family, PIC12 (PIC12FXXX)– is called Mid-Range.
The PIC12FXXX most popular among these starter their way in this field. Mid-Range devices feature 14-bit program word architecture and are available in 8 to 64-pin packages that offer an operating voltage range of 1.8-5.5V, small package footprints, interrupt handling, an 8-level hardware stack, multiple A/D channels and EEPROM data memory. Mid-range devices offer a wide range of package options and a wide range of peripheral integration. These devices feature various serial analog and digital peripherals, such as: SPI, I2C™, USART, LCD and A/D converters.
3. The third family is PIC16(16FXXX).
With six variants ranging from 3.5K-14 Kbytes of Flash memory, up to 256 bytes of RAM and a mix of peripherals including EUSART, CCP and onboard analog comparators. These devices are well suited for designers with applications that need more code space or I/O than 14-pin variants supply, and are looking to increase system performance and code efficiency by employing hardware motor control and communications capability.
4. The fourth family is PIC 17/18(18FXXX).
The PIC18 family utilizes a 16-bit program word architecture and incorporates an advanced RISC architecture with 32 level-deep stack, 8x8 hardware multiplier, and multiple internal and external interrupts. With the highest performance in Microchip’s 8-bit portfolio, the PIC18 family provides up to 16 MIPS and linear memory. PIC18 is the most popular architecture for new 8-bit designs where customers want to program in C language

Here we are trying t the thord family exceptionally PIC16F877a

The PIC microcontroller PIC16f877a is one of the most renowned microcontrollers in the industry. This controller is very convenient to use, the coding or programming of this controller is also easier. One of the main advantages is that it can be write-erase as many times as possible because it use FLASH memory technology. It has a total number of 40 pins and there are 33 pins for input and output.

An EEPROM is also featured in it which makes it possible to store some of the information permanently like transmitter codes and receiver frequencies and some other related data. The cost of this controller is low and its handling is also easy. Its flexible and can be used in areas where microcontrollers have never been used before as in coprocessor applications and timer functions etc.


PIN CONFIGURATION AND DESCRIPTION OF PIC16F877A

As it has been mentioned before, there are 40 pins of this microcontroller IC. It consists of two 8 bit and one 16 bit timer. Capture and compare modules, serial ports, parallel ports and five input/output ports are also present in it.


PIN 1: MCLR
The first pin is the master clear pin of this IC. It resets the microcontroller and is active low, meaning that it should constantly be given a voltage of 5V and if 0 V are given then the controller is reset. Resetting the controller will bring it back to the first line of the program that has been burned into the IC.
A push button and a resistor is connected to the pin. The pin is already being supplied by constant 5V. When we want to reset the IC we just have to push the button which will bring the MCLR pin to 0 potential thereby resetting the controller.
PIN 2: RA0/AN0
PORTA consists of 6 pins, from pin 2 to pin 7, all of these are bidirectional input/output pins. Pin 2 is the first pin of this port. This pin can also be used as an analog pin AN0. It is built in analog to digital converter.
PIN 3: RA1/AN1
This can be the analog input 1.
PIN 4: RA2/AN2/Vref-
It can also act as the analog input2. Or negative analog reference voltage can be given to it.
PIN 5: RA3/AN3/Vref+
It can act as the analog input 3. Or can act as the analog positive reference voltage.
PIN 6: RA0/T0CKI
To timer0 this pin can act as the clock input pin, the type of output is open drain.
PIN 7: RA5/SS/AN4
This can be the analog input 4. There is synchronous serial port in the controller also and this pin can be used as the slave select for that port.
PIN 8: RE0/RD/AN5
PORTE starts from pin 8 to pin 10 and this is also a bidirectional input output port. It can be the analog input 5 or for parallel slave port it can act as a ‘read control’ pin which will be active low.
PIN 9: RE1/WR/AN6
It can be the analog input 6. And for the parallel slave port it can act as the ‘write control’ which will be active low.
PIN 10: RE2/CS/A7
It can be the analog input 7, or for the parallel slave port it can act as the ‘control select’ which will also be active low just like read and write control pins.
PIN 11 and 32: VDD
These two pins are the positive supply for the input/output and logic pins. Both of them should be connected to 5V.
PIN 12 and 31: VSS
These pins are the ground reference for input/output and logic pins. They should be connected to 0 potential.
PIN 13: OSC1/CLKIN
This is the oscillator input or the external clock input pin.
PIN 14: OSC2/CLKOUT
This is the oscillator output pin. A crystal resonator is connected between pin 13 and 14 to provide external clock to the microcontroller. ¼ of the frequency of OSC1 is outputted by OSC2 in case of RC mode. This indicates the instruction cycle rate.
PIN 15: RC0/T1OCO/T1CKI
PORTC consists of 8 pins. It is also a bidirectional input output port. Of them, pin 15 is the first. It can be the clock input of timer 1 or the oscillator output of timer 2.
PIN 16: RC1/T1OSI/CCP2
It can be the oscillator input of timer 1 or the capture 2 input/compare 2 output/ PWM 2 output.
PIN 17: RC2/CCP1
It can be the capture 1 input/ compare 1 output/ PWM 1 output.
PIN 18: RC3/SCK/SCL
It can be the output for SPI or I2C modes and can be the input/output for synchronous serial clock.
PIN 23: RC4/SDI/SDA
It can be the SPI data in pin. Or in I2C mode it can be data input/output pin.
PIN 24: RC5/SDO
It can be the data out of SPI in the SPI mode.
PIN 25: RC6/TX/CK
It can be the synchronous clock or USART Asynchronous transmit pin.
PIN 26: RC7/RX/DT
It can be the synchronous data pin or the USART receive pin.
PIN 19,20,21,22,27,28,29,30:
All of these pins belong to PORTD which is again a bidirectional input and output port. When the microprocessor bus is to be interfaced, it can act as the parallel slave port.
PIN 33-40: PORT B
All these pins belong to PORTB. Out of which RB0 can be used as the external interrupt pin and RB6 and RB7 can be used as in-circuit debugger pins.

HOW TO PROGRAM THE INPUT AND OUTPUT PORTS OF PIC16F877A


As we have studied 5 input and output ports namely PORTA, PORTB, PORTC, PORTD and PORTE which can be digital as well as analog. We will configure them according to our requirements. But in case of analog mode, the pins or the ports can only act as inputs. There is a built in A to D converter which is used in such cases. Multiplexer circuits are also used.

But in digital mode, there is no restriction. We can configure the ports as output or as input. This is done through programming. For PIC the preferable compiler is mikro C pro which can be downloaded from their website.

There is a register named as ‘TRIS’ which controls the direction of ports. For different ports there are different registers such as TRISA, TRISB etc.

  • If we set a bit of the TRIS register to 0, the corresponding port bit will act as the digital output.
  • If we set a bit of the TRIS register to 1, the corresponding port bit will act as the digital input.

For example to set the whole portb to output we can write the program statement as:

TRISB=0;

Now the port will act as the output port and we can send any value on the output such as

PORTB=0XFF;

FF represents all 1’s in binary i.e. FF=11111111, now all the pins of port b are high. If we connect LEDs at all the pins then they will all start glowing in this condition.

If we want to negate the values of the port b we can use the statement:

PORTB=~PORTB;

Now all the pins of the port b will be low.

CODE TO LIGHT UP A SINGLE LED/ FLASHING LED

void main()
{
TRISB.F0 = 0 // the direction of RB0 is set as output
//or TRISB = 0xFE (0xFE = 11111110)
do // setting the infinite loop
{
PORTB.F0 = 1; // setting the RB0 pin to high
Delay_ms(500); // delay of 500 milli seconds
PORTB.F0 = 0; // setting the RB0 pin to low
Delay_ms(500); // again a delay of 500 milli seconds
}while(1);
}

More Posts

gElectron. Powered by Blogger.

Contributors

16x2 LCD Interfacing with STM32,STM32F103C6

 16x2 LCD  Interfacing with STM32,STM32F103C6 lcd_init(); LCD_LINE1; lcd_String(" GeElectron"); LCD_LINE2; lc...

Contact Form

Name

Email *

Message *

Contact us

Name

Email *

Message *

Follow Us

https://www.facebook.com/gElectron-393939667321867/ FBbox/https://www.facebook.com/IVYthemes

Comments

[blogger]

MKRdezign

Test

Latest

[recent][newsticker]

Technology

Top Ads

RECENT COMMENTS

Subscribe Via Email

Subscribe to our newsletter to get the latest updates to your inbox. ;-)


Your email address is safe with us!

RECENT COMMENTS