Professional Documents
Culture Documents
3 PIC-+Basic+Programming+in+Assembly
3 PIC-+Basic+Programming+in+Assembly
Address Content
Org 0x00
00 Goto Start ( address 05) Goto start
01
02
03
04
Start
05 CLRF sum CLRF sum
06 CLRF carry CLRF carry
Address 04 is interrupt vector- if the program is using interrupts this location should
point to ISR. In this case it is not using any interrupts so this could be used( next slide).
Another option- Program memory
GOTO 0x02
GOTO 0x01
Continuously count from 4 till 0
Example 3
High EQU 0x30 MOVWF N_high
Low EQU 0x40 Nu MOVLW Low
Cblock 0x25 MOVWF N_low
N_low Cu DECFSZ N_low,1
N_high Goto Cu
Endc DECFSZ N_high,1
Org 0x00 Goto Nu
MOVLW High Goto $
end
Delay generation using 16 bits
8 bit Multiplication
#include<p16f877a.inc> Movwf multiplicant
Cblock 0x20 Movf multiplier,0
Multiplier = 3
Count BTFSC STATUS,Z Multiplicant=4
Multiplier Goto terminate
Multiplicant Count =3
Movf multiplicant,0
Product_msb
BTFSC STATUS,Z 4 is added 3 times
Product_lsb
Goto terminate
Endc
Loop
Org 0x00
ADDWF product_lsb,1
CLRF product_msb
BTFSC STATUS,C
CLRF product_lsb
Movlw 0x03 INCF Product_msb,1
Movwf count DECFSZ count,1
Movwf multiplier Goto Loop
Movlw 0x04 Terminate
Goto terminate
End
Division Logic
Dividend = 5 , divisor =2, Q=0 , Rem=0
https://en.wikipedia.org/wiki/Watchdog_timer
Contd…
• The user program has to take care of WDT.
• The programmer should know when the WDT will
overflow( after how many instructions) and
CLRWDT instruction should be used. So that WDT is
cleared and reinitialized to 0.
• WDT as a feature could be enabled or disabled.
• In PIC16f877a WDT uses an internal RC oscillator
for reliable operation.
• WDT is independent of the Crystal oscillator.
Contd…
• If the program has infinite loops - the
controller will be executing the infinite loop,
but the WDT will still continue to increment
and overflow, resulting in a reset.
• Such cases you can disable WDT , as the
infinite loop is intentionally put by the
programmer.
SLEEP
• Dedicated instruction for SLEEP mode.
• Power saving.
• Microcontrollers goes to sleep mode
suspending all the activities.
• The external crystal oscillator is not used,
saving power.
• Few peripherals could be working, based on
internal RC oscillator.
Contd…
• Wake up from SLEEP could be initialized
through an external interrupt.
• WDT can wake up the device from SLEEP
mode. ( not as a reset, instead as wake up)
• Some peripherals can also wake the device.
– Eg. UART- serial communication module.
– If the peripheral receives a bit from another
device it wakes up PIC.
STATUS- register
After power up i.e the microcontroller has turned on this bit is set as 1,
CLRWDT and SLEEP instruction also sets this bit.