Académique Documents
Professionnel Documents
Culture Documents
1 INTRODUCTION
PIC16F877A is the heart of this system. It consists of clock circuit
and power on reset circuit. Clock circuit is build around crystal oscillator and
ceramic capacitor. Purpose of crystal oscillator is to stabilize the frequency and the
capacitor is to stabilize the amplitude if the clock. This circuit determines the
operating speed. Here we use 4MHz crystal oscillator, so the microcontroller will
work at the speed of 1uSec. Purpose of the microcontroller is to control the speed
of the DC shunt motor according to the load. It uses internal ADC and complete
one port for reading load and control the speed. That is it reads voltage output and
produces the digital output according to this input voltage. This microcontroller
will set the load limit and terminate the DC shunt motor to prevent from over load.
2.1.2 BOARD FEATURES
Includes 3 Zip Sockets to Program various series of PIC
Microcontrollers
PIC16F877A Microcontroller provided along with the chip
A Serial Port for In-System Programming
A Serial Port for RS232 Communication
Connector provided to connect LCD
4 , 7-Segment Displays with chip select facility using a Dip
Switch
LEDs Connected to all I/Os
Keys Connected to all I/Os
Pin outs for Port extension for users ease
2.1.3 CHIP FEATURES
functions of these pins are described in the Special Features Section. Each of the
PORTB pins has a weak internal pull-up. A single control bit can turn on all the
pull-ups. This is performed by clearing bit RBPU (OPTION_REG<7>). The weak
pull-up is automatically turned off when the port pin is configured as an output.
The pull-ups are disable don a Power-on Reset. Four of the PORTB pins,
RB7:RB4, have an interrupt on-change feature. Occur (anyRB7:RB4pinconfigured
as an output is excluded from the interruption.
2.1.7.3 PORT C & THE TRISC REGISTER
PORTC is an 8-bit wide, bi-directional port. The
corresponding data direction register is TRISC. Setting a TRISC bit (= 1) will
make the corresponding PORT C pin an input (i.e., put the corresponding output
driver in a Hi-Impedance mode). Clearing a TRISC bit (= 0) will make the
corresponding PORTC pin an output (i.e., put the contents of the output latch on
the selected pin).PORTC is multiplexed with several peripheral functions .PORTC
pins have Schmitt Trigger input buffers. When the I2C module is enabled, the
PORTC<4:3>pins can be configured with normal I2C levels, or with SMB us
levels by using the CKE bit (SSPSTAT<6>).When enabling peripheral functions,
care should be taken in defining TRIS bits for each PORTC pin. Some peripherals
override the TRIS 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, and XORWF)
with TRISC as destination, should be avoided. The user should refer to the
corresponding peripheral section for the correct TRIS bit settings.
2.1.7.4 PORT D & TRISD REGISTERS
PORTD and TRISD are not implemented on thePIC16F873
or PIC16F876.PORTD is an 8-bit port with Schmitt Trigger input buffers. Each pin
is individually configure able as an input or output .PORTD can be configured as
an 8-bit wide microprocessor port (parallel slave port) by setting control bit PSP
MODE (TRISE<4>). In this mode, the input buffers are TTL.
2.1.7.5 PORT E & TRISE REGISTER
PORTE and TRISE are not implemented on thePIC16F873
or PIC16F876.PORTE has three pins (RE0/RD/AN5, RE1/WR/AN6 ,and
RE2/CS/AN7) which are individually configure able as inputs or outputs. These
pins have Schmitt Trigger input buffers.
2.1.8 DATA EEPROM &FLASH PROGRAM MEMORY
The Data EEPROM and FLASH Program Memory are read
able and writable during normal operation over the entire VDD range. These
operations take place on a single byte for Data EEPROM memory and a single
word for Program memory. A write operation causes an erase-then-write operation
to take place on the specified byte or word. A bulk erase operation may not be
issued from user code (which includes removing code protection).Access to
program memory allows for checksum calculation .The values written to program
memory do not need to be valid instructions .Therefore, up to 14-bitnumbers can
be stored in memory for use as calibration parameters, serial numbers, packed 7-bit
ASCII, etc. The EEPROM Data memory is rated for high erase/write cycles
(specification D120). The FLASH program memory is rated much lower
(specification D130), because EEPROM data memory can be used to store
frequently updated values. An on-chip timer controls the write time and it will vary
with voltage and temperature, as well as from chip to chip. Please refer to the
specifications for exact limits (specifications D122 andD133).A byte or word write
automatically erases the location and writes the new value (erase before write).
Writing to EEPROM data memory does not impact the operation of the device.
Writing to program memory will cease the execution of instructions until the write
is complete. Read and write access to both memories take place indirectly through
a set of Special Function Registers (SFR).
The six SFRs used are:
EEDATA
EEDATH
EEADR
EEADRH
EECON1
EECON2
2.1.9 TIMER0 MODULE
The Timer0 module timer/counter has the following features:
8-bit timer/counter
Readable and writable
8-bit software programmable prescaler
Internal or external clock select
Interrupt on overflow from FFh to 00h
Edge select for external clock
2.1.9.1 TIMER1 MODULE
The Timer1 module is a 16-bit timer/counter consisting of two
8-bit registers (TMR1H and TMR1L), which are readable and writable. The TMR1
Register pair (TMR1H:TMR1L) The Special Function Registers can be classified
intotwo sets: core (CPU) and peripheral. increments from 0000h to FFFF hand
rolls over to 0000h. The TMR1 Interrupt, if enabled, is generated on overflow,
which is latched in interrupt flag bit TMR1IF (PIR1<0>). This interrupt
enabled/disabled by setting/clearing TMR1 interrupt enable bit TMR1IE
(PIE1<0>).Timer1 can operate in one of two modes:
As a timer
As a counter
The operating mode is determined by the clock select bit,
TMR1CS (T1CON<1>).In Timer mode, Timer1 increments every instruction
cycle. In Counter mode, it increments on every rising edge of the external clock
input.Timer1 can be enabled/disabled by setting/clearing control bit TMR1ON
(T1CON<0>). Timer1 also has an internal RESET input. This RESET can be
generated by either of the two CCP modules (Section 8.0). Register 6-1 shows the
Timer1control register.
2.1.9.2 TIMER2 MODULE
Timer2 is an 8-bit timer with a prescaler and a postscaler. It
can be used as the PWM time-base for the PWM mode of the CCP module(s). The
TMR2 register is readable and writable, and is cleared on any device RESET. The
input clock (FOSC/4) has a prescale option of 1:1,1:4, or 1:16, selected by control
bitsT2CKPS1:T2CKPS0 (T2CON<1:0>).The Special Function Registers can be
classified into two sets: core (CPU) and peripheral. The Timer2 module has an 8bit period register, PR2.Timer2 increments from 00h until it matches PR2 and then
resets to 00h on the next increment cycle. PR2 is a readable and writable register.
The PR2 register is initialized to FFh upon RESET. The match output of TMR2
goes through a 4-bitpostscaler (which gives a 1:1 to 1:16 scaling inclusive) to
generate a TMR2 interrupt (latched in flag bitTMR2IF, (PIR1<1>)).Timer2 can be
shut-off by clearing control bit TMR2ON (T2CON<2>), to minimize power
consumption.
2.1.10 MASTER SYNCHRONOUS SERIAL PORT (MSSP) MODULE
UNIVERSAL
SYNCHRONOUS
TRANSMITTER (USART)
ASYNCHRONOUS
RECEIVER
bits. It also has individual and global interrupt enable bits. A global interrupt enable
bit, GIE (INTCON<7>) enables (if set) all unmasked interrupts, or disables (if
cleared) all interrupts. When bit GIE is enabled, and an Interrupts flag bit and
mask bit are set, the interrupt will vector immediately. Individual interrupts can be
disabled through their corresponding enable bits in various registers. Individual
interrupt bits are set, regardless of the status of the GIE bit. The GIE bit is cleared
on RESET. The return from interrupt instruction, RETFIE, exits The interrupt
routine, as well as sets the GIE bit, which re-enables interrupts. The RB0/INT pin
interrupt, the RB port change interrupt, and the TMR0 overflow interrupt flags are
contained in the INTCON register .The peripheral interrupt flags are contained in
the special function registers, PIR1 and PIR2. The corresponding interrupt enable
bits are contained in special Function registers, PIE1 and PIE2, and the peripheral
interrupt enable bit is contained in special function register INTCON.When an
interrupt is responded to, the GIE bit is cleared to disable any further interrupt, the
return address is pushed onto the stack and the PC is loaded with 0004h. Once in
the Interrupt Service Routine, the source(s) of the interrupt can be determined by
polling the interrupt flag bits. The interrupt flag bit(s) must be cleared in software
before re-enabling interrupts to avoid recursive interrupts. For external interrupt
events, such as the INT pin or PORTB change interrupts, the interrupt latency will
be three or four instruction cycles. The exact latency depends when the interrupt
event occurs. The latency is the same for one or two-cycle instructions. Individual
interrupt flag bits are set, regardless of the status of their corresponding mask bit,
PEIE bit, or GIE bit.
2.1.14 WATCH DOG TIMER (WDT)
The Watchdog Timer is a free running on-chip RC oscillator which
does not require any external components. This RC oscillator is separate from the
RC oscillator of the OSC1/CLKIN pin. That means that the WDT will run, even if
the clock on the OSC1/CLKIN and OSC2/CLKOUT pins of the device has been
stopped, for example, by execution of a SLEEP instruction .During normal
operation, a WDT time-out generates a device RESET (Watchdog Timer Reset). If
the device is in SLEEP mode, a WDT time-out causes the device to wake-up and
continue with normal operation (Watchdog Timer Wake-up). The TO bit in the
STATUS register will be cleared upon a Watchdog Timer time-out.
2.1.15 POWER DOWN MODE
Power-down mode is entered by executing a SLEEP instruction. If
enabled, the Watchdog Timer will be cleared but keeps running, the PD bit
(STATUS<3>) is cleared, the TO (STATUS<4>) bit is set, and is turned off. The
I/O ports maintain the status they had before the SLEEP instruction was executed
(driving high, low, or hi-impedance).For lowest current consumption in this mode,
place all I/O pins at either VDD or VSS, ensure no external circuitry is drawing
current from the I/O pin, power-down the A/D and disable external clocks.
2.1.16 PIC 16F877A INSTRUCTION SET
PIC has a RISC based instruction set consisting of about 35
instructions. Almost all the data movements must be carried though the w
register. Instruction set can be categorized as
1. Data movement instructions
2. Data processing instructions
3. Execution change instructions
4. Processor control instructions
Microchips mid-range 8-bit microcontroller family uses a 14-bit wide instruction
set. This instruction set consists of 36 instructions, each a single14-bit wide word.
Most instructions operate on a file register, f, and the working register, W
(accumulator). The result can be directed either to the file Register or the W
register or to both in the case of some instructions. For byte-oriented instructions,
fr: one of the 80 memory ram positions implemented as 8 bit registers (File
Register Set or FRS) (0 =< fr <= 4f). The first 12 are special purpose
registers (SFR) and the other 68 are general purpose registers(GPR).
k: an 8 bit literal
b: 3 bit literal identifying one bit of a byte (0: least significant bit, 7: most
significant bit). Example: f(7)
add - addition
sub - subtraction
or - logical or