PIC Microcontroller Theory QB
PIC Microcontroller Theory QB
PIC Microcontroller Theory QB
Questions
All these ports are bi-directional. The direction of the port is controlled by using TRIS(X) registers (TRIS A
used to set the direction of PORT-A, TRIS B used to set the direction for PORT-B, etc.). Setting a TRIS(X) bit
‘1’ will set the corresponding PORT(X) bit as input. Clearing a TRIS(X) bit ‘0’ will set the corresponding
PORT(X) bit as output.
(If we want to set PORT A as an input, just set TRIS(A) bit to logical ‘1’ and want to set PORT B as an output,
just set the PORT B bits to logical ‘0’.)
Analog input port (AN0 TO AN7) : these ports are used for interfacing analog inputs.
TX and RX: These are the USART transmission and reception ports.
SCK: these pins are used for giving synchronous serial clock input.
SCL: these pins act as an output for both SPI and I2C modes.
DT: these are synchronous data terminals.
INTCON Register
The INTCON register is a readable and writable register, which contains various enable and flag bits for the
TMR0 register overflow, RB port change and external RB0/INT pin interrupts.
READ-MODIFY-WRITE OPERATIONS
Any instruction that specifies a file register as part of the instruction performs a Read-Modify-Write (R-
M-W) operation. The register is read, the data is modified, and the result is stored according to either the
instruction or the destination designator ‘d’. A read operation is performed on a register even if the instruction
writes to that register. For example, a “CLRF PORTB” instruction will read PORTB, clear all the data bits, then
write the result back to PORTB. This example would have the unintended result that the condition that sets the
RBIF flag would be cleared
OPCODE FIELD DESCRIPTIONS
(For details of instructions with their respective example with description (total no is 35) please refer to the
datasheet of PIC 16F877A)
-------------------------------------------------------------------------------------------------------------------------------------
7. Write a note on Timers used in PIC.
Ans: PIC16F877A has following Timer modules:
Timer0
Timer1
Timer2
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
Timer mode is selected by clearing bit T0CS (OPTION_REG<5>). In Timer mode, the Timer0 module will
increment every instruction cycle (without prescaler). If the TMR0 register is written, the increment is inhibited
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) increments from 0000h to FFFFh
and 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 can be 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 When the Timer1 oscillator is enabled (T1OSCEN is set), the RC1/T1OSI/CCP2 and
RC0/T1OSO/T1CKI pins become inputs. That is, the TRISC<1:0> value is ignored and these pins read as ‘0’.
T1CON: TIMER1 CONTROL REGISTER (ADDRESS 10h)