Mturk Jobs

Mturk Jobs
Mturk Jobs

Tank

Showing posts with label Proteus. Show all posts
Showing posts with label Proteus. Show all posts

Friday, January 2, 2009

Explaining PIC16F84A Flasher Program in Detail

You may have felt that the Flasher program is difficult. But this is not true.

Now, we 'll explain it step-by-step. Just remember, when I started learning Microcontroller programming, I started by understanding this program in detail and put on it my own comments to make me remember what each piece of code did.

list p=16f84
include "p16f84.inc"

; This part is necessary for the compiler to
; know the type of the PIC you are using.

org 0x00
goto start

; The word ORG tells the compiler to put the following code ( goto
; start label ) in the address 0x00 which is the reset vector of the PIC


org 0x20

start

; Again. Puts the label start at the address 0x20

bcf INTCON,7

; Clear the R7 bit in the register INTCON which disables the interrupts

movlw 0x00

; Put 0x00 in the W register

bsf STATUS,5


; Set the Bit 5 in the status register which selects Bank 1 in the RAM

movwf TRISB
; Copy the W register content into TRISB register
; [ makes PORTB output]

bcf STATUS,5
; Clear the Bit 5 in the status register which selects Bank 0 in the RAM

again


; This is a label for the repeating part of the program

movlw 0x80
movwf PORTB

; Copies 0x80 [binary 1000 0000 ] in the W register
; Copy the W register content into PORTB register

call delay

; This command calls the Delay routine.

movlw 0x00
movwf PORTB

; Copies 0x00 [binary 0000 0000 ] in the W register
; Copy the W register content into PORTB register


goto again

; This label is important to keep the program running forever

delay


; This is the label for the delay routine
; The delay consists of 3 nested loops

movlw 0x01
movwf 0x0e

; Put 0x01 in W register
; And copy it to the memory address 0x0e in RAM

loop3


; Label

movlw 0xfa

movwf 0x0d

; Put 0xfa in W register
; And copy it to the memory address 0x0d in RAM

loop2

; Label

movlw 0xfa
movwf 0x0c

; Put 0xfa in W register
; And copy it to the memory address 0x0c in RAM

loop1


; Label

decfsz 0x0c,1
; Decrease contents of memory address 0x0c by 1 ,
; then skip the next command if the result is zero


goto loop1


; goto the outer loop

decfsz 0x0d,1


; Decrease contents of memory address 0x0d by 1 ,
; then skip the next command if the result is zero

goto loop2

; goto the outer loop

decfsz 0x0e,1

; Decrease contents of memory address 0x0e by 1 ,
; then skip the next command if the result is zero

goto loop3

; goto the outer loop

return
; Retrun from the Delay routine

end

; must be put at the end of the program

;*********************************************************************

This is the end of the program. Now that you understand this basic program of LED flasher, you can understand more complex programs and tricks.






If you like this blog you can support us by many ways:
   
   1. Leave comments stating your point of view about this article.

   2. Buy our book on Amazon Learn By Making.

   3. Click on links of our sponsors without adding any extra cost on you if you make purchase from them. Actually, many of these offers are totally free.
  4. Visit our new website outatime.tech.

Thank you for visiting our blog.

Thursday, December 25, 2008

Run your first PIC16F84A program on simulator

You can start to test the PIC16F84A flasher program on the simulator.

The simulator is a program that simulates Microcontroller code execution and other electronic component behavior.

One good simulator I 've tried and I recommend is Labcenter Proteus 7.

You can install it and try the hardware components and software program and debug them for run-time errors and functioning errors. All this before building the real-world application on the board. This approach is very useful and can reduce developing time and frustration and eliminate situations such as you connect the circuit and get no action at all. You then wonder
what 's wrong. And you can get lost debugging hardware and software and don 't know where to
start from.

This introduction is to show the advantages of using the simulator before building your circuit board.

Let 's get started ..........

1- Install the simulator ( Labcenter Proteus 7 ).

2- Run the program ISIS.

3- Draw the components of the flasher application as in this screen-shot.




4- After you copy the code from the previous post into a file named Flasher.ASM, add the source

file as follows ;

- From the source menu , select Define Code Generation Tools ...

- Choose the MPASMWIN from the scroll menu as the screen-shot,





- Add the source form the source menu --- > Add/Remove Source files ...

and choose the code generation tools MPASMWIN and the source file Flasher.ASM




Now you have successfully configured the source file and code generation tools for code

compilation.

5- You can now compile the program by choosing the Source menu ---> Build All .

If every thing goes right, you should get the screen


6- You will notice that a Flaher.HEX file has been generated in the working folder.

7- Now double-click on the PIC16F84A component in your design , you get the window,




Choose the Flasher.HEX and set the Processor Clock Frequency to 4MHz.

8- Now press the play button to start debugging and running the program.



Now , you see the led flashing . Congratulations !!! The program is running.

We can start to build our first real-wold circuit....





If you like this blog you can support us by many ways:
   
   1. Leave comments stating your point of view about this article.

   2. Buy our book on Amazon Learn By Making.

   3. Click on links of our sponsors without adding any extra cost on you if you make purchase from them. Actually, many of these offers are totally free.
  4. Visit our new website outatime.tech.

Thank you for visiting our blog.

Tank