This is a simulation project that shows how to write program in assembly language for PIC16F84A microcontroller that turns on a single LED and use it in Proteus VSM to stimulate the working of the microcontroller controlled LED.
To do this start by creating a new project in Proteus, give some name and save it to some folder.
Click Next. We require a schematic so select Create a schematic from the selected template and choose default or any size you want.
Click Next. We do not require a PCB so select Do not create a PCB layout and click next again.
We do require a Firmware so select Create a Firmware Project and select PIC16 as Family, PIC16F84A as Controller, MPASM(MPLAB) as the Compiler.
Clicking next will bring up the source code editor window and the schematic window. Go to the Schematic and add the following components-
- 9C04021A3300FLHF3 (330ohm resistor)
- 9C08052A1002JLHFT (10K ohm resistor)
- CRYSTAL
- LED-GREEN
The PIC16F84A micro-controller is already added so no need to add that part.
Draw the schematic as shown-
Click on the VCC power and change it toΒ +5V
Now switch over to the Source Code by clicking on the Source Code tab. The Source code editor shows a default template. Delete the template code and Copy the following code below into it.
processor 16f84A
includeΒ Β Β Β <p16f84A.inc>
__configΒ _XT_OSC & _WDT_OFF & _PWRTE_ON & _CP_OFF
orgΒ Β Β 0Β Β Β Β ; start at address 0
gotoΒ Β Β main
;=============================
; space for interrupt handler
;=============================
orgΒ Β Β Β Β Β 0x04
;=============================
;Β Β Β Β Β Β main program
;=============================
main:
; Initialize all line in port B for output
movlwΒ Β Β Bβ00000000β²Β Β Β ; w = 00000000 binary
trisΒ Β Β PORTBΒ Β Β Β Β Β ; Set up port B for output
; Turn on line 0 in port B. All others remain off
movlwΒ Β Β Bβ00000001β²
movwfΒ Β Β PORTB
; Endless loop intentionally hangs up program
wait:
gotoΒ Β Β wait
Code Explanation
The part βprocessor 16f84Aβ tells which microcontroller is being used. The βincludeΒ <p16f84A.inc>β part is a directive that tell to use the p16f84A microcontroller include file. The __config directive specifies various configuration aspect of the microcontroller such as the type of the oscillator, whether watch dog timer is on or off, whether the Power-Up timer is on or off and code protection is on/off. Then Org 0 tells the assembler to assemble all subsequent code starting at address 0. The next instruction it reads is the main so the program control goes to main. The instruction movlwΒ Β Β Bβ00000000β² tells to load working register with 000000000. The instruction trisΒ Β Β PORTB tells to make the Port B direction as output. Then the sequence of instruction movlwΒ Β Β Bβ00000001β² and movwf PORTB directs to turn on the line 0 of the Port B.
For more detail: Microcontroller with single LED Project in Proteus