PIC Microcontroller Tritorials (PIC16F877A)
Thursday, 26 March 2015
Wednesday, 11 March 2015
Programming PIC16F877A in Assembly (Continued)
Bit Oriented Operations:
BCF:
Santax: BCF f,b
f => address of file register
b => Bit number which is to be clear
Function: Use to clear bit of file register.
BSF:
Santax: BCF f,b
f => address of file register
b => Bit number which is to be clear
Function: Use to clear bit of file register.
Santax: BSF f,b
f => address of file register
b => Bit number which is to be set
Function: Use to set bit of file register.
Santax: BSF f,b
f => address of file register
b => Bit number which is to be set
Function: Use to set bit of file register.
BTFSC:
Santax: BTFSC f,b
f => address of file register
b => Bit number which is to be test
Function: Use to test bit of file register and skip next instruction if bit is clear.
Santax: BTFSC f,b
f => address of file register
b => Bit number which is to be test
Function: Use to test bit of file register and skip next instruction if bit is clear.
BTFSS:
Santax: BTFSS f,b
f => address of file register
b => Bit number which is to be test
Function: Use to test bit of file register and skip next instruction if bit is set.
Santax: BTFSS f,b
f => address of file register
b => Bit number which is to be test
Function: Use to test bit of file register and skip next instruction if bit is set.
Literal and Control Operations:
ADDLW:
Santax: ADDLW k
k => Literal Value
Function: Use to add literal value and data in working register.Result will store in WREG.
Santax: ADDLW k
k => Literal Value
Function: Use to add literal value and data in working register.Result will store in WREG.
SUBLW:
Santax: SUBLW k
k => Literal Value
Function: Use to subtract value in working register from literal value.Result will store in WREG.
Santax: SUBLW k
k => Literal Value
Function: Use to subtract value in working register from literal value.Result will store in WREG.
ANDLW:
Santax: ANDLW k
k => Literal Value
Function: Use to Perform AND operation on literal value and data in working register. commonly use for masking.Result will store in WREG
Santax: ANDLW k
k => Literal Value
Function: Use to Perform AND operation on literal value and data in working register. commonly use for masking.Result will store in WREG
IORLW:
Santax: IORLW k
k => Literal Value
Function: Use to Perform OR operation on literal value and data in working register. commonly use for masking.Result will store in WREG
Santax: IORLW k
k => Literal Value
Function: Use to Perform OR operation on literal value and data in working register. commonly use for masking.Result will store in WREG
XORLW:
Santax: XORLW k
k => Literal Value
Function: Use to Perform XOR operation on literal value and data in working register. commonly use for masking.Result will store in WREG
Santax: XORLW k
k => Literal Value
Function: Use to Perform XOR operation on literal value and data in working register. commonly use for masking.Result will store in WREG
MOVLW:
Santax: MOVLW k
k => Literal Value
Function: Use to move literal value into working register.
Santax: MOVLW k
k => Literal Value
Function: Use to move literal value into working register.
CALL:
Santax: CALL t
t => Tag of subroutine which is to be call.
Function: Use to Call subroutine.
Santax: CALL t
t => Tag of subroutine which is to be call.
Function: Use to Call subroutine.
CLRWDT:
Santax: CLRWDT
Function: Use to clear watchdog timer.
Santax: CLRWDT
Function: Use to clear watchdog timer.
GOTO:
Santax: GOTO t
t => Tag of subroutine.
Santax: GOTO t
t => Tag of subroutine.
Function: Use to go to address/tag.
Function: Use to go to address/tag.
RETFIE:
Santax: RETFIE
Function: Use to return from interrupt service routine.
Santax: RETFIE
Function: Use to return from interrupt service routine.
RETURN:
Santax: RETURN
Function: Use to return from subroutine routine. which is call by CALL command.
Santax: RETURN
Function: Use to return from subroutine routine. which is call by CALL command.
SLEEP
Function: Use to go into standby mode.
Programming PIC16F877A in Assembly
WREG (Working Register):
Working register is very important in PIC microcontroller all literal values used to perform arithmetic operation or to move into any port or file register first move into WREG than other function will perform. Similarly in PIC16F877A when we want to move a data from one port/register to another Port/register we have to move that data into WREG first and then move it into any other port/register.
Instruction set use in PIC16F877A:
The instruction set of PIC16F877A is split into 3 categories:
- Byte Oriented
- Bit Oriented
- Literal value and control operations
Byte Oriented Operations:
ADDWF:
Santax: ADDWF f,d
f => address of file register
d => use to save result in either working register or file register
Function: Use to add data in working register and file register, destination of result of addition is control by 'd'
if d = W then result of addition is stored in Working register.
if d = F then result of addition is stored in File register.
ANDWF:
Santax: ANDWF f,d
f => address of file register
d => use to save result in either working register or file register
Function: Use to perform AND operation on data in working register and file register, destination of result is control by 'd'.
if d = W then result of addition is stored in Working register.
if d = F then result of addition is stored in File register.
CLRF:
Santax: CLRF f
f => address of file register
Function: Use to clear file register.
CLRW:
Santax: CLRW
Function: Use to clear Working register.
COMF:
Santax: COMF f,d
f => address of file register
d => use to save result in either working register or file register
Function: Use to take complement of file register, destination of result is control by 'd'.
if d = W then result of addition is stored in Working register.
if d = F then result of addition is stored in File register.
DECF:
Santax: DECF f,d
f => address of file register
d => use to save result in either working register or file register
Function: Use to decrease one number from file register, destination of result is control by 'd'.
if d = W then result of addition is stored in Working register.
if d = F then result of addition is stored in File register.
DECFSZ:
Santax: DECFSZ f,d
f => address of file register
d => use to save result in either working register or file register
Function: Use to decrease one number from file register, and skip next instruction if result is equal to zero. Destination of result is control by 'd'.
if d = W then result of addition is stored in Working register.
if d = F then result of addition is stored in File register.
INCF:
Santax: INCF f,d
f => address of file register
d => use to save result in either working register or file register
Function: Use to increase one number from file register, destination of result is control by 'd'.
if d = W then result of addition is stored in Working register.
if d = F then result of addition is stored in File register.
INCFSZ:
Santax: INCFSZ f,d
f => address of file register
d => use to save result in either working register or file register
Function: Use to increase one number from file register, and skip next instruction if result is equal to zero. Destination of result is control by 'd'.
if d = W then result of addition is stored in Working register.
if d = F then result of addition is stored in File register.
IORWF:
Santax: IORWF f,d
f => address of file register
d => use to save result in either working register or file register
Function: Use to perform OR operation on data in working register and file register, destination of result is control by 'd'.
if d = W then result of addition is stored in Working register.
if d = F then result of addition is stored in File register.
MOVF:
Santax: MOVF f,d
f => address of file register
d => use to save result in either working register or file register
Function: Use to move data in file register to working register,
commonly d = W to move data in working register.
MOVWF:
Santax: MOVWF f
f => address of file register.
Function: Use to move data from working register to file register.
NOP:
Santax: NOP
Function: perform no operation used to waste one instruction cycle.
RLF:
Santax: RLF f,d
f => address of file register
d => use to save result in either working register or file register
Function: Use to move data in file register from right to left, destination of result is control by 'd'.
if d = W then result of addition is stored in Working register.
if d = F then result of addition is stored in File register.
RRF:
Santax: RRF f,d
f => address of file register
d => use to save result in either working register or file register
Function: Use to move data in file register from left to right, destination of result is control by 'd'.
if d = W then result of addition is stored in Working register.
if d = F then result of addition is stored in File register.
SUBWF:
Santax: SUBWF f,d
f => address of file register
d => use to save result in either working register or file register
Function: Use to subtract data in working register from file register, destination of result is control by 'd'.
if d = W then result of addition is stored in Working register.
if d = F then result of addition is stored in File register.
SWAPF:
Santax: SWAPF f,d
f => address of file register
d => use to save result in either working register or file register
Function: Use to swap nibbles in file register, destination of result is control by 'd'.
if d = W then result of addition is stored in Working register.
if d = F then result of addition is stored in File register.
XORWF:
Santax: XORWF f,d
f => address of file register
d => use to save result in either working register or file register
Function: Use to perform XOR operation on data in working register and file register, destination of result is control by 'd'.
if d = W then result of addition is stored in Working register.
if d = F then result of addition is stored in File register.
Sunday, 8 March 2015
PIC16F877A Basics (Continued)
Data Memory Organization:
In PIC16F877A the data memory is partitioned into four banks which contain the General Purpose Registers and the Special Function Registers. Number of banks may vary depending on the microcontroller.
Each bank extends up to 7Fh (128 bytes). The Above locations are for SFR and lower locations of each bank are reserved for the General Purpose Registers, implemented as static RAM. While program is being executed, it is working with the particular bank. The default bank is BANK0. Some frequently used Special Function Registers from one bank may be mirrored in another bank for code reduction and quicker access.
To access a register that is located in another bank, one should access it inside the program. There are special registers which can be accessed from any bank, such as STATUS register.
Status Register:
The Status register contains the arithmetic status of the ALU, the Reset status and the bank select bits for data memory.
Setting for RP0, RP1 for bank switching
PIC16F877A Basics
Architecture / Internal Block diagram:
PIC microcontroller has Reduced instruction set computing (RISC) Architecture, that means it has small number of instruction and large number of Special function registers (SFR). Because of RISC architecture data execution of PIC is fast because in RISC architecture there are two separate buses one for data memory and other for Program memory.
Program Memory Organization:
PIC16F877A has 14.3 KB of program memory from which only 8 KB is used to store program, and remaining is used for program counter (PC), Stack, Reset vector and interrupt vector.
PIC16F877A has 13-bit Program Counter, in order to access 8 KB program memory we divided program memory into four pages.
Saturday, 7 March 2015
Introduction
INTRODUCTION
Microcontroller vs Microprocessor:
Microcontroller differs from a microprocessor. The first and most important difference is its functionality. Microprocessor is just a brain or processing element without any peripheral attached to it. In order to activate microprocessor, other components such as Program & Data memory, A/D converter, RAM, Oscillator crystal must be added to it.
Simply, In order to communicate with peripheral environment, the microprocessor must use specialized circuits added as external chips. In short microprocessors are the pure heart of the computers. This is how it was in the beginning and remains the same today.
PIC Microcontroller Families:
In this Blog I am using PIC16F877A which is an 40 Pin 8-bit microcontroller having
- Program memory : 14.3KB
- Data memory(SRAM) : 368 Bytes
- EEPROM : 256 Bytes
- Intrupts : 15
- Instruction Set : 35
- Input / Output Pins : 33
- 10 bit ADC Channel : 8 Channels (5 on PortA and 3 on PortE)
- Timer : 3 (2-> 8bit and 1-> 16bit)
- Analog Comparators : 2
- Communication Protocols : SPI, I2C, USART
Pin Configuration:
Subscribe to:
Posts (Atom)