Beruflich Dokumente
Kultur Dokumente
REPORT ON
EMBEDED SYSTEM
USING PIC
MICROCONTROLLER 2012
IN THIS REPORT WE PROVIDE THAT WHAT SOFTWARE IS USE TO WRITE H.C.T.M.
THE PROGRAM AND ALSO PROVIDE HOW IT IS USE… AND SOME
PROGRAMS ALSO PROVIDE. THESE PROGRAMS ARE PRACTICALLY DONE COLLEGE
ON THE PIC MICROCONTROLLER. KAITHAL
E.C.E. DEPARTMENT
KUK
TRAINING REPORT
On
EMBEDED SYSTEM
WITH
PIC MICROCONTROLLER
Submitted in the partial fulfillment for the award of Degree of
Bachelor of Technology
In
Submitted by Submitted to
Rajat Aggarwal ER. Palvinder Singh
E.C.E. “A”
CONTENTS
Acknowledgement
Company Certificate
PIC microcontrollers
PIC 16F73 features
Pin diagram of PIC16F73
Pin description of PIC16F73
Core Architecture
Programming of PIC
Compiler Used-mikroC
Features
Projects
Functionality
ACKNOWLEDGEMENT
I am also grateful to Mr. Sanjeev Kumar training incharge for giving best
knowledge about my project. The way he instilled knowledge of the subject
was undoubtly praise worthy and valuable.
I am also thankful to NETMAX institute as a whole that is doing yeoman’s
service by teaching the learner abreast with the embeded system,
microcontrollers etc.. knowledge that is the need of the day.
We are also grateful to our H.O.D. sir Mr. Rajeev Chechi and our lect. ER.
Palvinder Singh and ER. Baljinder Kumar for his valuable guidance, constant
supervision and encouragement during our training.
We are also grateful to our parents and friends for their valuable
guidance and encouragement during our project.
Last but not the least; I thank all my classmates at NETMAX for extending kind
Co-operation.
Rajat Aggarwal
1710240
B.Tech (ECE)
3rd Year
COMPANY CERTIFICATE
SCAN OF CERTIFICATE
IS PLACE HERE
PIC
MICROCONTROLLER
PIC 16 Series-PIC16f73
Under 8 bit comes-PIC10 xxxx, PIC12 xxxx, PIC16 xxxx, PIC18 xxxx.(12 bit
instruction set)
PICs are popular with developers and hobbyists alike due to their low cost, wide
availability, large user base, extensive collection of application notes,
availability of low cost or free development tools, and serial programming (and
re-programming with flash memory) capability.
Peripheral Features:-
PICs are popular with developers and hobbyists alike due to their low cost, wide
availability, large user base, extensive collection of application notes,
availability of low cost or free development tools, and serial programming (and
re-programming with flash memory) capability.
Peripheral Features:-
CMOS Technology:-
• Low power, high speed CMOS FLASH technology.
• Fully static design.
• Wide operating voltage range: 2.0V to 5.5V.
• High Sink/Source Current: 25 Ma.
• Industrial temperature range.
• Low power consumption:
- < 2 mA typical @ 5V, 4 MHz
PIN DIAGRAM
PIN DESCRIPTION
MCLR-(pin 1):-
PIC16F7X devices have a noise filter in the MCLR Reset path. The filter will
detect and ignore small pulses. It should be noted that a WDT Reset does not
drive MCLR pin low. The behavior of the ESD protection on the MCLR pin has
been altered from previous devices of this family. Voltages applied to the pin
that exceed its specification can result in both MCLR Resets and excessive
current beyond the device specification during the ESD event. For this reason,
Microchip recommends that the MCLR pin no longer be tied directly to VDD.
RESET:-
Some registers are not affected in any RESET condition. Their status is
unknown on POR and unchanged n any other RESET. Most other registers are
reset to a RESET state” on Power-on Reset (POR), on the MCLR and WDT
Reset, on MCLR Reset during LEEP, and Brown-out Reset (BOR). They are
not affected by a WDT Wake-up, which is viewed as the resumption of normal
operation. The TO and PD bits are set or cleared differently in different RESET
situations, as indicated
Reading the PORTA register 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.
OSC1/CLKIN-(pin 9):-
OSC2/CLKOUT-(pin 10):-
OSCILLATOR TYPES
make the corresponding PORTC pin an output (i.e., put the contents of the
output latch on the selected pin).
Vss(pin 19):-
Vdd(pin 20):-
Each of the PORTB pins has a weak internal pull-up. A single control bit can
turn on all the pull-ups. The weak pull-up is automatically turned off when the
port pin is configured as an output. The pull-ups are disabled on a Power-on
Reset.
CORE ARCHITECTURE
Figure 2.1: Showing a typical microcontroller device and its different subunits
Unlike most other CPUs, there is no distinction between memory space and
register space because the RAM serves the job of both memory and registers,
and the RAM is usually just referred to as the register file or simply as the
registers
PROGRAMMING OF PIC
COMPILER USED:-
mikroC
Introduction to mikroC:-
mikroC IDE
PIC and C fit together well: PIC is the most popular 8-bit chip in the world,
used in a wide variety of applications, and C, prized for its efficiency, is the
natural choice for developing embedded systems. mikroC provides a successful
match featuring highly advanced IDE, ANSI compliant compiler, broad set of
hardware libraries, comprehensive documentation, and plenty of ready-to-run
examples.
Features:-
Write your C source code using the built-in Code Editor (Code and
Parameter Assistants, Syntax Highlighting, Auto Correct, Code
Templates, and more…)
Use the included mikroC libraries to dramatically speed up the
development: data acquisition, memory, displays, conversions,
communications… Practically all P12, P16, and P18 chips are supported.
Monitor your program structure, variables, and functions in the Code
Explorer.
Generate commented, human-readable assembly, and standard HEX
compatible with all programmers.
Inspect program flow and debug executable logic with the integrated
Debugger.
Get detailed reports and graphs: RAM and ROM map, code statistics,
assembly listing, calling tree, and more…
We have provided plenty of examples for you to expand, develop, and
use as building bricks in your projects. Copy them entirely if you deem fit
– that’s why we included them with the compiler.
Projects:-
New Project:-
The easiest way to create project is by means of New Project Wizard, drop-
down menu Project › New Project. Just fill the dialog with desired values
(project name and description, location, device, clock, config word) and mikroC
will create the appropriate project file . Also, an empty source file named after
the project will be created by default. mikroC does not require you to have
source file named same as the project, it’s just a matter of convenience.
Edit Project:-
Later, you can change project settings from the drop-down menu Project › Edit
Project. You can rename the project, modify its description, change chip, clock,
config word, etc.
Void delay_ms()
{int I;
While (i !=0)
i--;
Also PIC has a internal TRIS register which controls the flow of insructions
from the corresponding port.
PROJECT NO-1:-
(PORT PROGRAMMING)
the interfacing of LED is shown in the figure above.it is given Vcc through
resistors of 330E.
also a darlington pair IC is also used i.e. ULN 2803 which shift the dc level of
volage coming from port of pic microcontroller.
Now to glow the desired LED, proper hexadecimal code for its binary is
programmed in pic.eg.to glow alternative LED’s the binary code will
be10101010 and its corresponding hexadecimal code will be 0xAA.
Also PIC has a internal TRIS register which controls the flow of insructions
from the corresponding port i.ee PORT will behave as input(if =1) and as
output(if=0).
void main()
{
PORTC = 0; // Initialize PORTC
TRISC = 0; // Configure PORTC as output
while(1)
{
PORTC = OxAA; // gives code 10101010 to PORTC
Delay_ms(1000); // one second delay
}}
Thus LED Blinking practical is done sucessfully
PROJECT NO-2:-
Now also we can display more than one seven segment display simultaneously
but it will take a number of pins of controller. So we use two pins from
controller to control the display of seven segment one by one from same port
such that it appears to be displaying simultaneously. This is done by providing a
very small delay such that our eyes can’t even detect the change over from one
display to another.
void main()
TRISB=0X00;
while(1)
i++;
bcd(i);
//delay_ms(20);
}}
if(x<100)
for(a=0;a<100;a++)
y=(x/10)*6+x;
y=y>>4;
y=y|0xe0;
PORTB=y;
delay(250);
z=(x/10)*6+x;
z=z&0x0f;
z=z|0xd0;
PORTB=z;
delay(250);
}}}
while(k!=0)
k--;
}}
PROJECT NO-3:-
Stepper motor are those which rotates in steps.like all motors it is also based on
electromagnetic induction i.e. electric field produces a magnetic field whose
variation causes a torque which rotates the motor.
Fundamentals of Operation
Stepper motors operate much differently from normal DC motors, which rotate
when voltage is applied to their terminals. Stepper motors, on the other hand,
effectively have multiple "toothed" electromagnets (a.k.a. phases) arranged
around a central gear-shaped piece of iron. The electromagnets are energized by
an external control circuit, such as a microcontroller. To make the motor shaft
turn, first one electromagnet is
given power, which makes the gear's teeth magnetically attracted to the
electromagnet's teeth. When the gear's teeth are thus aligned to the first
electromagnet, they are slightly offset from the next electromagnet. So when the
next electromagnet is turned on and the first is turned off, the gear rotates
slightly to align with the next one, and from there the process is repeated. Each
of those slight rotations is called a "step." In that way, the motor can be turned a
precise angle.
Now to run the motor we have to feed the binary code to turn on the current of
that winding…
CODE IS:-
#define l1 PORTB.F0
#define l2 PORTB.F1
#define l3 PORTB.F2
#define l4 PORTB.F3
void forward();
void backward();
void main()
PORTC=0XFF;
TRISB=0X00;
while(1)
forward();
delay_ms(2000);
backward();
delay_ms(2000);
unsigned char a;
for(a=0;a<10;a++)
}}
void backward()
unsigned char b;
for(b=0;b<10;b++)
}}
The above code will rotate the motor first in forward direction and then in
reverse direction.
PROJECT NO-4:-
LCD stands for Liquid Crystal Display.to run it via PIC 16F73,we need
command signals and vcc to drive it.now the signal that is required to display
character is produced by an IC which is already embedded on it.its name is
HD44780.
CODING:-
void main()
Now also it is possible to scroll the characters on LCD. Its code is as follows:
void main()
Lcd_Out(2, 5,text1);
while(1)
Lcd_Cmd(LCD_SHIFT_LEFT);
delay_ms(1000);
It will shift the character to the left with a delay of 1 sec between it.
PROJECT NO-5
(TEMPERATURE MONITORING)
PIC16F73 consists of 5 internal ADC .
Now as PIC 16xxx has got the feature of inbuilt ADC.so,there is no need to
connect externally.PIC16XXX is featured with 8 bit ADC.
The 8-bit analog-to-digital (A/D) converter module has five inputs for the
PIC16F73/76 and eight for the PIC16F74/77.
The A/D allows conversion of an analog input signal to a corresponding 8-bit
digital number. The output of the sample and hold is the input into the
converter, which generates the result via successive approximation. The
analog reference voltage is software selectable to either the device’s positive
supply voltage (VDD), or the voltage level on the RA3/AN3/VREF pin.
The A/D converter has a unique feature of being able to operate while the
device is in SLEEP mode. To operate in SLEEP, the A/D conversion clock must
be derived from the A/D’s internal RC oscillator.
The A/D module has three registers. These registers
are:
• A/D Result Register (ADRES)
• A/D Control Register 0 (ADCON0)
• A/D Control Register 1 (ADCON1)
The ADCON0 register, shown in Register 11-1, controls the operation of the
A/D module. The ADCON1 register, shown in Register 11-2, configures the
functions of the port pins. The port pins can be configured as analog inputs
(RA3 can also be a voltage reference), or as digital I/O.
ADC HARDWARE CONNECTION
A = Analog input
D = Digital I/O
set.
void main()
Lcd_Init(&PORTB);
Lcd_Cmd(Lcd_Clear);
Lcd_Cmd(LCD_CURSOR_OFF);
ADCON1 = 0x01;
TRISB=0;
while(1)
ascii(e);
delay_ms(1000) ;
ascii(f) ;
temp=digit/10;
Lcd_Chr(1, 1, table[temp] );
temp=digit-temp*10;
Lcd_Chr(1, 2,table[temp] );
}}
PROJECT NO-6:-
Syntax:
PORT( NAME).F(0 to 7)
Internally,when pin is high its flip flop is sat.when external switch is closed ,it
forces no current or voltage to enter to pin and also lowers the pin from 1 to 0.
Thus when switch is pressed ,the pin becomes zero.so ,implementing this in
practical.
The swiches whose one end are connected to pins of nontroller are shown on
next page
#define s0 PORTC.F0
#define s1 PORTC.F1
#define s2 PORTC.F2
#define s3 PORTC.F3
#define s4 PORTC.F4
void main()
do
delay_ms(600);
delay_ms(600);
delay_ms(600);
delay_ms(600);
else
PORTB=0xff;
}}
while(1);
PROJECT NO-7:-
While if it is desired to have more options for a pin, a matrix is formed in which
row and column are made such that each pin can control more than one switch
or vice versa.
#define R1 PORTB.F0
#define R2 PORTB.F1
#define R3 PORTB.F2
#define R4 PORTB.F3
#define C1 PORTB.F4
#define C2 PORTB.F5
#define C3 PORTB.F6
#define C4 PORTB.F7
void main()
TRISB=0XFF;
TRISC=0X00;
PORTC=0X00;
PORTB=0XFF;
while(1)
PORTC=1;
PORTC=2;
PORTC=3;
PORTC=4;
PORTC=5;
PORTC=6;
PORTC=7;
PORTC=8;
PORTC=9;
PORTC=10;
PORTC=11;
PORTC=12;
PORTC=13;
PORTC=14;
PORTC=15;
PORTC=16;
PROJECT NO-8
To send data via single line through a bit stream is known as serial
communication.
PIC has two buffers and it allows full duplex communication.to change settings
we have to re configure TXSTA register
Now coding
void main()
usart_init(2400);
while(1)
usart_write('A');
usart_write('M');
usart_write('A');
usart_write('N');
delay_ms(600);
unsigned int i;
void main()
{
usart_init(2400);
while(1)
{
if(usart_data_ready() )
{
i= usart_read();
usart_write('i');
}
usart_write('A');
usart_write('M');
usart_write('A');
usart_write('N');
delay_ms(600);
}
BIBLIOGRAPHY
Wikipedia
MicroC Manuals
www.talkingelectronics.com
www.howstuffworks.com
The Art of Electronics (Book)