Programming With PIC
Programming With PIC
Introduction of PIC
Interfacing
3) GSM
4)I2C, RTC
PIC
CONTROLLER
www.researchdesignlab.com Page 1
Programming with PIC Microcontroller
Table of Contents
INTRODUCTION .......................................................................................................................... 3
EMBEDDED SYSTEMS ........................................................................................................... 3
PIC16F877A ............................................................................................................................... 3
Overview: .................................................................................................................................... 3
MPLAB IDE: .............................................................................................................................. 5
GETTING STARTED WITH EMBED C PROGRAMMING:.................................................... 24
Lab 1 . LED Blinking using PIC controller (16F877A) with MPLAB: .................................. 24
Lab2.To display a message on LCD using pic controller ........................................................ 26
Lab3.Interfacing ADC to display analog to digital conversion values on LCD. ..................... 30
Lab 6. Interfacing KEYPAD to display value on LCD when a key is pressed. ....................... 39
Lab7. Interfacing 7segment ..................................................................................................... 45
Lab 8. Interfacing GSM modem to send and receive the message ........................................... 48
Lab 9. Interfacing RELAY to turn the relays ON and OFF...................................................... 52
Lab 10. Display a message using I2c Protocol ........................................................................ 57
Lab 11. Working with RTC and controller ............................................................................... 65
www.researchdesignlab.com Page 2
Programming with PIC Microcontroller
INTRODUCTION
EMBEDDED SYSTEMS
PIC16F877A
Overview:
The PIC 16F877A PIC microcontroller is one of the most popular general purpose
microcontrollers. It is of 8-bit which means the most available operations are limited to 8-bits.It
is a 40-pin IC.
www.researchdesignlab.com Page 3
Programming with PIC Microcontroller
Ports:
There is one 6-bit ports: A , 3 8-bit ports: B ,C,D and one 3 bit port:E.
PORTA (Pin 2 to 7)and TRISA register :PORTA is a 6-bit wide, bidirectional port. The
corresponding data direction register is TRISA. Setting a TRISA bit ( = 1)
will make the corresponding. PORTA pin an input (i.e., put the corresponding output driver in a
High-Impedance mode).Clearing a TRISAbit (= 0) will make the corresponding PORTA pin an
output (i.e., put the contents of the output latch on the selected pin).Reading the PORTA regiter
reads the status of the pins,whereas writing to it will write to the port latch.All write operations
are read-modify write operations.Therefore, a write to a port implies that the port pins are read,
the value is modified and then written to the port data latch.
PORTB(Pin 33 to 40)and TRISB register: PORTB is an 8-bit wide, bidirectional port. The
corresponding data direction register is TRISB. Setting aTRISB bit (= 1)will make the
corresponding PORTB pin an input(i.e., put the corresponding output driver in a High-
Impedance mode). Clearing a TRISB bit (= 0)will make the corresponding PORTB pin an
output (i.e.,put the contents of the output latch on the selected pin).Three pins of PORTB are
multiplexed with the In-Circuit.Debugger and Low-Voltage Programming
function:RB3/PGM,RB6/PGC and RB7/PGD.
www.researchdesignlab.com Page 4
Programming with PIC Microcontroller
bit to make a pin an output, while other peripherals override the TRIS bit to make a pin an input.
Since the TRIS bit override is in effect while the peripheral is enabled, read-modify write
instructions (BSF, BCF, XORWF) with TRISC as the destination, should be avoided. The user
should refer to corresponding peripheral section for the correct TRIS bit settings.
PORTD(Pin 19to22 and pin 27to30)and TRISD register: PORTD is an 8-bit port
with Schmitt Trigger input buffers. Each pin is individually configurable as an input or output.
PORTD can be configured as an 8-bit wide microprocessor port (Parallel Slave Port) by setting
control bit, PSPMODE (TRISE<4>). In this mode, the input buffers are TTL.
MPLAB IDE:
MPLAB IDE is a free integrated toolset for the development of embedded application on
microchip IC and dsPIC microcontroller.
www.researchdesignlab.com Page 5
Programming with PIC Microcontroller
4) Click on next
www.researchdesignlab.com Page 6
Programming with PIC Microcontroller
www.researchdesignlab.com Page 7
Programming with PIC Microcontroller
7) Click on browse and select the folder you saved on the drive and write a filename ex: lcd12.
www.researchdesignlab.com Page 8
Programming with PIC Microcontroller
8) Click on save
www.researchdesignlab.com Page 9
Programming with PIC Microcontroller
9)Click on next->next->next->finish
www.researchdesignlab.com Page 10
Programming with PIC Microcontroller
www.researchdesignlab.com Page 11
Programming with PIC Microcontroller
12) Click on save->save it in the same folder with .c extension and click on save.
www.researchdesignlab.com Page 12
Programming with PIC Microcontroller
13) Right click on source file ->add files->select your .c file->click on open.
www.researchdesignlab.com Page 13
Programming with PIC Microcontroller
www.researchdesignlab.com Page 14
Programming with PIC Microcontroller
www.researchdesignlab.com Page 15
Programming with PIC Microcontroller
www.researchdesignlab.com Page 16
Programming with PIC Microcontroller
15) Click on configure ->configuration bits->unclick the configuration bits set in code->click ok-
select low voltage programming->then click the configuration set in code
www.researchdesignlab.com Page 17
Programming with PIC Microcontroller
www.researchdesignlab.com Page 18
Programming with PIC Microcontroller
www.researchdesignlab.com Page 19
Programming with PIC Microcontroller
www.researchdesignlab.com Page 20
Programming with PIC Microcontroller
16)Click on programmer->connect
www.researchdesignlab.com Page 21
Programming with PIC Microcontroller
www.researchdesignlab.com Page 22
Programming with PIC Microcontroller
www.researchdesignlab.com Page 23
Programming with PIC Microcontroller
www.researchdesignlab.com Page 24
Programming with PIC Microcontroller
I/O Connections :
PORT B4LED1
PORTB5LED2
PORTB6Switch1
PORTB7Switch2
#include <htc.h>
#define _XTAL_FREQ 20000000 //crystal frequency of 20MHZ
#define Input1 RB7 //set port RB7 as input port
#define Input2 RB1 //set port RB1 as input port
#define Output1 RB4 //set port RB4 as output port
#define Output2 RB5 //set port RB5 as output port
void main()
{
TRISB=0X82; //use portB register as input as well as output port
while(1) //infinite loop
{
if(Input1==0) //if switch1 is pressed ie connect port RB7 to sw1
{
}
else if(Input2==0) //If switch2 is pressed ie connect port RB1 to sw2
{
Output1=0; //both the LED’S are turned off
Output2=0;
}
}
}
www.researchdesignlab.com Page 25
Programming with PIC Microcontroller
www.researchdesignlab.com Page 26
Programming with PIC Microcontroller
I/O connection:
PORT B0 tO B7DO to D7 of LCD
ENABLED7
R/WGROUND
R/SD6
#include <htc.h>
#include<string.h>
#define _XTAL_FREQ 20000000 //crystal frequency of 20MHZ
#define EN RD7 //connect enable pin of LCD to port D7
#define RS RD6 //connect Register select pin of LCD
to port D6
void LCD_Delay() //delay routine
{
__delay_ms(1);
}
www.researchdesignlab.com Page 27
Programming with PIC Microcontroller
www.researchdesignlab.com Page 28
Programming with PIC Microcontroller
void main()
{
TRISB=0x00; //make the registerB as ouput
TRISD=0x00; //make the registerD as ouput
LCD_Init(); //Initialize the LCD
__delay_ms(1000);
while(1) //infinite loop
www.researchdesignlab.com Page 29
Programming with PIC Microcontroller
I/O connection:
#include <htc.h>
#include<string.h>
#define _XTAL_FREQ 20000000 //crystal frequency of 20MHZ
#define EN RD7 //connect enable pin of LCD to port D7
#define RS RD6 //connect Register select pin of LCD to port
D6
/*LCD code */
void LCD_Cmd(unsigned char cmd) //this function is to write command to the LCD
{
www.researchdesignlab.com Page 30
Programming with PIC Microcontroller
PORTB=cmd;
RS=0; //Set RS pin to low in order to send a
command to the LCD
EN=1; //set EN pin to high in order to send
high pulse
LCD_Delay(); //give a small delay
EN=0; //set EN pin to low in order to make
pulse low
LCD_Delay(); //give a small delay
}
void ADC_Init()
{
ADCON0 = 0x41; //set A/D control register0 to 0x41
ADCON1 = 0xC0; //set A/D control register1 0xc0
www.researchdesignlab.com Page 31
Programming with PIC Microcontroller
void main()
{
www.researchdesignlab.com Page 32
Programming with PIC Microcontroller
do
{
www.researchdesignlab.com Page 33
Programming with PIC Microcontroller
I/O connection:
#include<htc.h>
#define _XTAL_FREQ 20000000 //crystal frequency of 20MHZ
#include "uart.h" //header file
#include "string.h" //header file
char val;
void main()
{
__delay_ms(1000); //provide delay for 1s
UART_Init(9600); //calling initialization function with 9600 baud
rate
__delay_ms(1000); //provide delay for 1s
UART_Write_Text("RDL"); //Display RDL on hyper terminal
do
{
www.researchdesignlab.com Page 34
Programming with PIC Microcontroller
char UART_TX_Empty()
{
return TRMT; //Returns Transmit Shift Status bit
www.researchdesignlab.com Page 35
Programming with PIC Microcontroller
char UART_Data_Ready()
{
return RCIF; //Flag bit
}
www.researchdesignlab.com Page 36
Programming with PIC Microcontroller
I/O connection:
PORT C1LED1.
PORTC2LED2
#include<htc.h>
#define XTAL 20000 //20Mhz=20000Khz
#define PWM_Freq 1 //1Khz PWM frequency
#define TMR2_PRE 16 //Timer2 Prescale
#define PR2_Val ((char)((XTAL/(4*TMR2_PRE*PWM_Freq))-1))
//Calculation for Period register PR2 (2Khz)
#define Duty_Cyc PR2_Val*2
unsigned int i;
void PWM_init(void); // This function is to initialize the PWM
void PWM_change(unsigned int); //This function is to change theDuty cycle
routine
void DelayMs(unsigned int); //this function is to provide a delay
void main(void)
{
PWM_init();
while(1)
{
i=0;
PWM_change(i);
DelayMs(10);
while(i<PR2_Val)
{
i=i+1;
PWM_change(i);
www.researchdesignlab.com Page 37
Programming with PIC Microcontroller
DelayMs(200);
}
}
}
void PWM_init(void)
{
TRISC2=0; //PWM channel 1 and 2 configured as output
TRISC1=0;
PORTC = 0x00;
CCP1CON=0x0c; //CCP1 and CCP2 are configured for PWM
CCP2CON=0x0c;
PR2=PR2_Val; //Move the PR2 value
while(Ms>0)
www.researchdesignlab.com Page 38
Programming with PIC Microcontroller
{
Ms--;
for(delay_cnst = 0;delay_cnst <220;delay_cnst++); //delay constant for 1Ms @20Mhz
}
}
I/O connection:
#include <htc.h>
#include <stdio.h> // Define I/O functions
#define XTAL 20000000
#define BAUD_RATE 9.6 //9600 Baudrate
www.researchdesignlab.com Page 39
Programming with PIC Microcontroller
void main()
{
DelayMs(1000);
www.researchdesignlab.com Page 40
Programming with PIC Microcontroller
while(1)
{
TRISB=0X0f; // Enable the 4 LSB as I/P & 4 MSB as
O/P
PORTB=0X00;
while(PORTB==0x0f); // Get the ROW value
ScanRow();
TRISB=0Xf0; // Enable the 4 LSB as O/P & 4 MSB as
I/P
PORTB=0X00;
while(PORTB==0xf0); // Get the Column value
ScanCol();
switch(PORTB)
{
www.researchdesignlab.com Page 41
Programming with PIC Microcontroller
case 0x07:
Row=3; // 4th Row
break;
case 0x0b:
Row=2; // 3rd Row
break;
case 0x0d:
Row=1; // 2nd Row
break;
case 0x0e:
Row=0; // 1st Row
break;
}
}
switch(PORTB)
{
case 0x70:
Col=3; // 4th Column
break;
case 0xb0:
Col=2; // 3rd Column
break;
case 0xd0:
Col=1; // 2nd Column
break;
case 0xe0:
www.researchdesignlab.com Page 42
Programming with PIC Microcontroller
void LCD_Cmd(unsigned char cmd) //this function is to write command to the LCD
{
PORTB=cmd;
RS=0; //Set RS pin to low in order to send a
command to the LCD
EN=1; //set EN pin to high in order to send high pulse
LCD_Delay(); //give a small delay
EN=0; //set EN pin to low in order to make pulse low
LCD_Delay(); //give a small delay
}
www.researchdesignlab.com Page 43
Programming with PIC Microcontroller
//0x38 represents 5x7 matrix ,0x06 represent entry mode,0x0f represent display on cursor
blinking,0x01 represents clearing the LCD,0x80 represents 1st row
for(Count=0;Count<5;Count++)
LCD_Cmd(cmd[Count]);
}
www.researchdesignlab.com Page 44
Programming with PIC Microcontroller
#include<htc.h>
#define CNTRL_PORT PORTA
#define DATA_PORT PORTB
www.researchdesignlab.com Page 45
Programming with PIC Microcontroller
else if(n==2)
{
CNTRL_PORT=CA_CNTRL[1]; //Eanble Tenth place 7-Segment
DATA_PORT=CA[ten]; //Display Tenth Place Number
n=3;
DelayMs(5);
www.researchdesignlab.com Page 46
Programming with PIC Microcontroller
}
else if(n==3)
{
CNTRL_PORT=CA_CNTRL[2]; //Enable Hundredth place 7-Segment
DATA_PORT=CA[hun]; //Display Hundredth Place Number
n=4;
DelayMs(5);
}
else if(n==4)
{
CNTRL_PORT=CA_CNTRL[3]; //Eanble Thousandth place 7-Segment
DATA_PORT=CA[thou]; //Display Thousandth Place Number
n=1;
DelayMs(5);
}
}
void DelayMs(unsigned int Ms)
{
int delay_cnst;
while(Ms>0)
{
Ms--;
for(delay_cnst = 0;delay_cnst <220;delay_cnst++);
}
}
www.researchdesignlab.com Page 47
Programming with PIC Microcontroller
I/Oconnection:
Vin of GSM12v
Ground of GSMGround
D0,D1 of GSMTX,RX
#define <htc.h>
#define _XTAL_FREQ 20000000 //crystal frequency of 20MHZ
#include "uart.h" //header file
#include "string.h" //header file
www.researchdesignlab.com Page 48
Programming with PIC Microcontroller
char UART_TX_Empty()
{
return TRMT; //Returns Transmit Shift Status bit
}
char UART_Data_Ready()
{
return RCIF; //Flag bit
}
www.researchdesignlab.com Page 49
Programming with PIC Microcontroller
}
void UART_Read_Text(char *Output, unsigned int length)
//this function is used to read a text
{
int i;
for(int i=0;i<length;i++)
Output[i] = UART_Read();
}
www.researchdesignlab.com Page 50
Programming with PIC Microcontroller
UART_Write(13); //enter
UART_Write(10); //carriage return
__delay_ms(1000); //provide delay of 1s
UART_Write_Text("AT+CMGF=1"); //initialize the modem
UART_Write(13); //enter
UART_Write(10); //carriage return
__delay_ms(1000); //provide delay of 1s
UART_Write_Text("AT+CMGS=\"1234567890\""); //send a message
UART_Write(13); //enter
UART_Write(10); //carriage return
__delay_ms(1000); //provide delay of 1s
UART_Write_Text("GSM"); //display on hyper terminal
UART_Write(13); //enter
UART_Write(10); //carriage return
__delay_ms(1000); //provide delay of 1s
UART_Write(26); //Ctr +Z
}
}
www.researchdesignlab.com Page 51
Programming with PIC Microcontroller
I/O connection:
www.researchdesignlab.com Page 52
Programming with PIC Microcontroller
if(x>255)
{
x = (_XTAL_FREQ - baudrate*16)/(baudrate*16);
BRGH = 1; //High Baud Rate Select bit set to high
}
if(x<256)
{
SPBRG = x; //Writing SPBRG register
SYNC = 0; //Selecting Asynchronous Mode
SPEN = 1; //enables serial port
TRISC7 = 1;
TRISC6 = 1;
CREN = 1; //enables continuous reception
TXEN = 1; //enables continuous transmission
return 1;
}
return 0;
}
char UART_TX_Empty()
{
return TRMT; //Returns Transmit Shift Status bit
}
char UART_Data_Ready()
{
return RCIF; //Flag bit
}
www.researchdesignlab.com Page 53
Programming with PIC Microcontroller
{
while(!RCIF); //Waits for Reception to complete
return RCREG; //Returns the 8 bit data
}
void UART_Read_Text(char *Output, unsigned int length)//this function is used to read a text
{
int i;
for(int i=0;i<length;i++)
Output[i] = UART_Read();
}
void main()
{
unsigned char ReceivChar;
TRISB=0X00; //make register as the output
PORTB=0X00; //make the PORTB as the output port
www.researchdesignlab.com Page 54
Programming with PIC Microcontroller
while(1)
{
if(UART_Data_Ready()) //check if the data is ready
{
ReceivChar = UART_Read(); //store the data in a variable
UART_Write(ReceivChar); //display on hyperterminal
__delay_ms(1000); //provide delay of 1s
{
ReceivChar = UART_Read(); //store the data in a variable
UART_Write(ReceivChar); //display on hyperterminal
if(ReceivChar=='N') //if received character is N
relay2=1; //turn ON the 2nd relay
www.researchdesignlab.com Page 55
Programming with PIC Microcontroller
www.researchdesignlab.com Page 56
Programming with PIC Microcontroller
I/O connection:
SCL of EEPROMC3
SDA of EEPROMC4
#include<htc.h>
#include"string.h"
#include<stdio.h>
#define _XTAL_FREQ 20000000
#define I2C_FREQ 100 // 100khz at 4Mhz
#define FOSC 20000 // 20Mhz==>20000Khz
www.researchdesignlab.com Page 57
Programming with PIC Microcontroller
void main()
{
char a;
UART_Init(9600); //initialize the UART
DelayMs(1000); //Provide a delay of 1s
i2c_init(); //initialize the I2C
DelayMs(1000); //Provide a delay of 1s
while(1)
www.researchdesignlab.com Page 58
Programming with PIC Microcontroller
{
I2C_Start(); //start bit is set in this function
DelayMs(100); //Provide a delay
I2C_Write_Data(0xa0); //write the data on to the location 0xa0(device address)
DelayMs(100); //Provide a delay
I2C_Write_Data(0x20); //write the data on to location 0x20
DelayMs(100); //Provide a delay
I2C_Write_Data('a'); //send character ‘a’
DelayMs(100); //Provide a delay
I2C_Stop(); //stop bit is set in this function
DelayMs(100); //Provide a delay
I2C_Start(); //start bit is set in this function
DelayMs(100); //Provide a delay
I2C_Write_Data(0xa0); //write the data on to the location 0xa0(device address)
DelayMs(100); //Provide a delay
I2C_Write_Data(0x20); //write the data on to location 0x20
DelayMs(100); //Provide a delay
I2C_Reset(); //this function is used to reset
DelayMs(100); //Provide a delay
I2C_Write_Data(0xa1); //write the data on to the location 0xa0(device address)
DelayMs(100); //Provide a delay
a=I2C_Read_Data(); //this function reads the data stored in EEPROM
UART_Write(a); //display the character on hyper terminal
DelayMs(100); //Provide a delay
I2C_Stop(); //stop bit is set in this function
DelayMs(100); //Provide a delay
}
}
www.researchdesignlab.com Page 59
Programming with PIC Microcontroller
www.researchdesignlab.com Page 60
Programming with PIC Microcontroller
}
char I2C_Read_Data() //this function is used to read data from EEPROM
DelayMs(30);
www.researchdesignlab.com Page 61
Programming with PIC Microcontroller
TRISC4=1;
int delay_cnst;
while(Ms>0)
www.researchdesignlab.com Page 62
Programming with PIC Microcontroller
Ms--;
www.researchdesignlab.com Page 63
Programming with PIC Microcontroller
return 1;
}
return 0;
}
char UART_TX_Empty()
{
return TRMT; //Returns Transmit Shift Status bit
}
char UART_Data_Ready()
{
return RCIF; //Flag bit
}
www.researchdesignlab.com Page 64
Programming with PIC Microcontroller
Pinconnection:
SCL of RTCC3
SDA of RTCC4
www.researchdesignlab.com Page 65
Programming with PIC Microcontroller
#include<htc.h>
#include "string.h"
int i;
void WaitMSSP();
void i2c_init(void);
www.researchdesignlab.com Page 66
Programming with PIC Microcontroller
void ds1307_init(void);
void main()
int count=0;
for(i=0;i<7;i++)
DS1307Write(i,data[i]);
while(1)
www.researchdesignlab.com Page 67
Programming with PIC Microcontroller
WaitMSSP();
www.researchdesignlab.com Page 68
Programming with PIC Microcontroller
WaitMSSP();
WaitMSSP();
WaitMSSP();
WaitMSSP();
unsigned char x;
WaitMSSP ();
www.researchdesignlab.com Page 69
Programming with PIC Microcontroller
WaitMSSP ();
WaitMSSP ();
WaitMSSP ();
WaitMSSP ();
WaitMSSP ();
WaitMSSP ();
www.researchdesignlab.com Page 70
Programming with PIC Microcontroller
return (x);
void WaitMSSP()
SSPIF=0;
void ds1307_init()
TRISC4=1;
PORTC=0x18;
www.researchdesignlab.com Page 71
Programming with PIC Microcontroller
DS1307Write(0,0x00);
int delay_cnst;
while(Ms>0)
www.researchdesignlab.com Page 72
Programming with PIC Microcontroller
Ms--;
www.researchdesignlab.com Page 73
Pic Development Board
01010101010101010100101010101010101010101010101010101010101010101010101010101010101
01010101010101010100101010101010101010101010101010101010101010101010101010101010101
01010101010101010100101010101010101010101010101010101010101010101010101010101010101
01010101010101010100101010101010101010101010101010101010101010101010101010101010101
01010101010101010100101010101010101010101010101010101010101010101010101010101010101
01010101010101010100101010101010101010101010101010101010101010101010101010101010101
01010101010101010100101010101010101010101010101010101010101010101010101010101010101
01010101010101010100101010101010101010101010101010101010101010101010101010101010101
01010101010101010100101010101010101010101010101010101010101010101010101010101010101
01010101010101010100101010101010101010101010101010101010101010101010101010101010101
01010101010101010100101010101010101010101010101010101010101010101010101010101010101
Research
01010101010101010100101010101010101010101010101010101010101010101010101010101010101
01010101010101010100101010101010101010101010101010101010101010101010101010101010101
01010101010101010100101010101010101010101010101010101010101010101010101010101010101
01010101010101010100101010101010101010101010101010101010101010101010101010101010101
01010101010101010100101010101010101010101010101010101010101010101010101010101010101
01010101010101010100101010101010101010101010101010101010101010101010101010101010101
01010101010101010100101010101010101010101010101010101010101010101010101010101010101
01010101010101010100101010101010101010101010101010101010101010101010101010101010101
01010101010101010100101010101010101010101010101010101010101010101010101010101010101
01010101010101010100101010101010101010101010101010101010101010101010101010101010101
01010101010101010100101010101010101010101010101010101010101010101010101010101010101
01010101010101010100101010101010101010101010101010101010101010101010101010101010101
01010101010101010100101010101010101010101010101010101010101010101010101010101010101
01010101010101010100101010101010101010101010101010101010101010101010101010101010101
01010101010101010100101010101010101010101010101010101010101010101010101010101010101
01010101010101010100101010101010101010101010101010101010101010101010101010101010101
01010101010101010100101010101010101010101010101010101010101010101010101010101010101
01010101010101010100101010101010101010101010101010101010101010101010101010101010101
01010101010101010100101010101010101010101010101010101010101010101010101010101010101
Design Lab
01010101010101010100101010101010101010101010101010101010101010101010101010101010101
01010101010101010100101010101010101010101010101010101010101010101010101010101010101
01010101010101010100101010101010101010101010101010101010101010101010101010101010101
01010101010101010100101010101010101010101010101010101010101010101010101010101010101
01010101010101010100101010101010101010101010101010101010101010101010101010101010101
01010101010101010100101010101010101010101010101010101010101010101010101010101010101
01010101010101010100101010101010101010101010101010101010101010101010101010101010101
01010101010101010100101010101010101010101010101010101010101010101010101010101010101
01010101010101010100101010101010101010101010101010101010101010101010101010101010101
01010101010101010100101010101010101010101010101010101010101010101010101010101010101
01010101010101010100101010101010101010101010101010101010101010101010101010101010101
01010101010101010100101010101010101010101010101010101010101010101010101010101010101
01010101010101010100101010101010101010101010101010101010101010101010101010101010101
01010101010101010100101010101010101010101010101010101010101010101010101010101010101
01010101010101010100101010101010101010101010101010101010101010101010101010101010101
01010101010101010100101010101010101010101010101010101010101010101010101010101010101
01010101010101010100101010101010101010101010101010101010101010101010101010101010101
01010101010101010100101010101010101010101010101010101010101010101010101010101010101
01010101010101010100101010101010101010101010101010101010101010101010101010101010101
01010101010101010100101010101010101010101010101010101010101010101010101010101010101
01010101010101010100101010101010101010101010101010101010101010101010101010101010101
01010101010101010100101010101010101010101010101010101010101010101010101010101010101
01010101010101010100101010101010101010101010101010101010101010101010101010101010101
01010101010101010100101010101010101010101010101010101010101010101010101010101010101
01010101010101010100101010101010101010101010101010101010101010101010101010101010101
www.researchdesignlab.com
Email: sales@researchdesignlab.com I www.researchdesignlab.com
An ISO 9001- 2008 Certified Company
Power supply, 5V-12V
2) Put a message on the bus that says 'its mine' - I have STARTED to use the bus. All other ICs then
LISTEN to the bus data to see whether they might be the one who will be called up
(addressed).
3) Provide on the CLOCK (SCL) wire a clock signal. It will be used by all the ICs as the reference
time at which each bit of DATA on the data (SDA) wire will be correct (valid) and can be used.
The data on the data wire (SDA) must be valid at the time the clock wire (SCL) switches from
'low' to 'high' voltage.
4) Put out in serial form the unique binary 'address'(name) of the IC that it wants to
communicate with.
5) Put a message (one bit) on the bus telling whether it wants to SEND or RECEIVE data from the
other chip. (The read/write wire is gone!)
6) Ask the other IC to ACKNOWLEDGE (using one bit) that it recognized its address and is ready to
communicate.
8) The first IC sends or receives as many 8-bit words of data as it wants. After every 8-bit data
word the sending IC expects the receiving IC to acknowledge the transfer is going OK.
9) When all the data is finished the first chip must free up the bus and it does that by a special
message called 'STOP'. It is just one bit of information transferred by a special 'wiggling' of the
SDA/SCL wires of the bus.
The Serial Peripheral Interface or SPI-bus is a simple 4-wire serial communications interface used
by many microprocessor/microcontroller peripheral chips that enables the controllers and
peripheral devices to communicate each other. Even though it is developed primarily for the
communication between host processor and peripherals, a connection of two processors via SPI is
just as well possible.
The SPI bus, which operates at full duplex (means, signals carrying data can go in both directions
simultaneously), is a synchronous type data link setup with a Master / Slave interface and can
support up to 1 megabaud or 10Mbps of speed. Both single-master and multi-master protocols are
possible in SPI. But the multi-master bus is rarely used and look awkward, and are usually limited
to a single slave.
The SPI Bus is usually used only on the PCB. There are many facts, which prevent us from using it
outside the PCB area. The SPI Bus was designed to transfer data between various IC chips, at very
high speeds. Due to this high-speed aspect, the bus lines cannot be too long, because their
reactance increases too much, and the Bus becomes unusable. However, its possible to use the SPI
Bus outside the PCB at low speeds, but this is not quite practical.
The peripherals can be a Real Time Clocks, converters like ADC and DAC, memory modules like
EEPROM and FLASH, sensors like temperature sensors and pressure sensors, or some other devices
like signal-mixer, potentiometer, LCD controller, UART, CAN controller, USB controller and
amplifier.
To transmit using device addressing, only the destination address must be configured. The
destination address can be specified using either the destination device's 64-bit address or its NI-
string. The XBee modules also support coordinator and broadcast addressing modes. Device
addressing in the AT firmware is configured using the DL, DH, or DN commands. In the API
firmware, the ZigBee Transmit Request API frame (0x10) can be used to specify destination
addresses.
To address a node by its 64-bit address, the destination address must be set to match the 64-bit
address of the remote. In the AT firmware, the DH and DL commands set the destination 64-bit
address. In the API firmware, the destination 64-bit address is set in the ZigBee Transmit Request
frame. ZigBee end devices rely on a parent (router or coordinator) to remain awake and receive
any data packets destined for the end device. When the end device wakes from sleep, it sends a
transmission (poll request) to its parent asking if the parent has received any RF data destined for
the end device. The parent, upon receipt of the poll request, will send an RF response and the
buffered data (if present). If the parent has no data for the end device, the end device may
return to sleep, depending on its sleep mode configuration settings. The following figure
demonstrates how the end device uses polling to receive RF data through its parent.
Features:
1. 56 byte nonvolatile RAM for data storage
2. 2-wire serial interface
3. Programmable square wave output signal
4. Automatic power-fail detect and switch circuitry
5. Consumes less than 500 nA in battery backup mode with oscillator running
6. Optional industrial temperature range -40°C to +85°C
7. Available in 8-pin DIP or SOIC
8. Recognized by Underwriters Laboratory
PIN DESCRIPTION
1. VCC - Primary Power Supply
2. X1, X2 - 32.768 kHz Crystal Connection
3. VBAT - +3V Battery Input
4. GND - Ground
5. SDA - Serial Data
6. SCL - Serial Clock
7. SQW/OUT - Square wave/Output Driver
20. Potentiometer
The Potentiometer Option allows the user to adjust the frequency reference by rotating a
potentiometers dial. Turning the potentiometer changes the frequency reference making it
easier to adjust the motor speed and also to set the duty cycle for PWM values.
Consequently, each data is sent to LCD in two steps: four higher bits are sent first (that normally
would be sent through lines D4-D7), four lower bits are sent afterwards. With the help of
initialization, LCD will correctly connect and interpret each data received. Besides, with regards
to the fact that data are rarely read from LCD (data mainly are transferred from microcontroller
to LCD) one more I/O pin may be saved by simple connecting R/W pin to the Ground. Such saving
has its price. Even though message displaying will be normally performed, it will not be possible
to read from busy flag since it is not possible to read from display.
Features:
1. Can display 224 different symbols.
2. Low power consumption.
3. 5x7 dot matrix format.
4. Powerful command set and user produced characters.
10k
Working
This Application Note describes programming techniques implemented on the AT91 ARM-based
microcontroller for scanning a 4x4 Keyboard matrix usually found in both consumer and industrial
applications for numeric data entry.AT91 Keyboard interface In this application, a 4x4 matrix
keypad requiring eight Input/Output ports for interfacing is used as an example. Rows are
connected to Peripheral Input/Output (PIO) pins configured as output. Columns are connected to
PIO pins configured as input with interrupts. In this configuration, four pull-up resistors must be
added in order to apply a high level on the corresponding input pins as shown in Figure 1. The
corresponding hexadecimal value of the pressed key is sent on four LEDs.
FEATURES
1. Contact debouncing.
2. Easy to interface. PIN DETAILS
3. Interfaces to any microcontroller or microprocessor. pin 1-4: R0-R3:- Rows
4. Data valid output signal for interrupt activation. pin 5-8: C0-C3:- Columns