Mturk Jobs

Mturk Jobs
Mturk Jobs

Tank

Thursday, January 15, 2009

Let 's speed up the rate !! Compile PIC16F84A Programs

Now that we learned to flash an LED using the PIC 16F84, we 'll increase the rate of information flow.

We 'll write the same program using C language. This will be very easy as it is a popular language and it also a high-level language. Most of us used it for computer programming.

That 's the flasher program:


//************************************************

#include"pic.h"


main()

{
unsigned char i;

TRISB = 0 ; // Make PORTB output

PORTB = 0 ; // Initialize PORTB
for(;;) // This is the infinite loop that keeps the PIC running
{
PORTB = 0x00;

// turn all LEDS off


for(i = 100 ; --i ;);


// Delay


PORTB = 0xFF;
// turn all LEDS on
for(i = 100 ; --i ;);

// Delay


}
}


//************************************************


I guess the program is self explaining.

Now again, we 'll try it in Proteus to see it working.

Here are the steps to add the C source code file and compile it.

1. Copy and paste the previous code into a file named flasher.c .

2. Install the program HiTec PIC C .

3. In ISIS 7 , open the flasher.DSN model you used before.

4. On the Source menu , choose Define Code Generation Tools.

5. Press New.

6. Brows to the folder of HiTec PIC C and to Bin folder , choose picl.exe.

7. To add the source , choose Source --> Add/Remove Source files , press New to add

flasher.c
choose PICC from the drop-down menu under Code Generation Tool , and on the

Flags text box , type --chip=16f84a to choose the microcontroller type.



8. Now press Source --> Build All.

9. Now choose the oscillator speed and the flasher.HEX file as you did in the Assembly

example.



10 . Press F12 to Run the program.



Here you can find the Proteus ISIS model and the source code






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.


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.

Wednesday, December 10, 2008

This is your first PIC16f84A program

HELLO WORLD

As in PC programming world, when you learn a new language , you start with the famous
"Hello World" program.

This program in Microcontroller is flashing a LED.

Here is the code:

;*************************************************
; Flasher.asm

list p=16f84 ; This is how you can comment
include "p16f84.inc"
org 0x00
goto start
org 0x20
start
bcf INTCON,7
movlw 0x00
bsf STATUS,5
movwf TRISB
bcf STATUS,5
again

movlw 0x80
movwf PORTB

call delay

movlw 0x00
movwf PORTB

call delay

goto again



delay
movlw 0x01
movwf 0x0e
loop3
movlw 0xfa
movwf 0x0d
loop2
movlw 0xfa
movwf 0x0c
loop1
decfsz 0x0c,1
goto loop1
decfsz 0x0d,1
goto loop2
decfsz 0x0e,1
goto loop3
return
end

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

1 - Copy the above text and paste it in an empty text file and save it as Flasher.asm

2 - Install the MPLab program and search for the file MPASMWIN.EXE in its path.

3- Run the program. It looks like this :



Uncheck the case-sensitive option.

4 - Browse for the Flasher.asm file and press Assemble.

If every thing goes write , you will have the window :

Congratiulations, the assemble process is complete !!
The Flasher.hex file will be generated in the same directory of Flasher.asm


Note : If you like this blog ( or don't ) , please give me feedback by commenting. Thanks ...






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.

Monday, December 8, 2008

Getting Started With PIC16F84 Microcontroller Programming

Resources needed for a Quick jump-start :

For the simplicity of the learning process for the beginner, I 'll start with the most famous Microchip PIC16F84 ( which was the first uC I learned )

You need to prepare these stuff before start programming :

1- The target IC (the uC PIC 16F84A) and its Datasheet .


2- Programming circuit ( JDM programmer ) - you need to build it your self - or buy a Microchip PIC programmer.



3 - Loader program ( ICProg ) - you 'll need it if you use JDM programmer - , but if you buy a ready-made programmer , you will have the software with it.


4 - MPLab program ( to assemble ) the programs you write in Assembley .




5 - HiTec PICC ( to compile programs in C ) .






6 - Proteus 7.0 Simulator

















You can get all these stuff for FREE from the Internet.






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.

Sunday, December 7, 2008

Microcontroller Tutorial : PIC16f84A

I decided to start a Microcontroller Tutorial for beginners. If you like to learn about Microcontroller programming and embedded systems , this blog may be helpful.

Prerequisites:

All you need to know before start programming your microcontroller is basic programming knowledge, basic electronics and Boolean Algebra ( AND , OR & NOT gates ... ) .

And the first thing to know is:

What is the Microcontroller?

It is a smart IC that can be programmed to do some task. Unlike a typical IC which does a certain function that cannot be changed, the Microcontroller function is defined by its software code written on it. you can change the code when you want and thus change its function. Smart means it can decide and take actions according to its code.

So what 's the difference between Microcontroller(uC) and Microprocessor(uP) ??

uP needs some other devices to be able to work ( BIOS, RAM, I/O Ports , ... ) all these devices are other IC 's.

Although the uP is more general purpose than than the uC , but the fact that the uC contains all the required devices in one package ( EEPROM, RAM, IO Ports , ADC , UART , etc ... ) overcomes the limited abilities and small instruction set of the uC.






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.

Saturday, December 6, 2008

It all started with the computer

It all started with the computer


I started with the old computer AQUARIUS at the 80 's. It had Microsoft Basic on it. I learned programming in Basic. I then got my Pentium 1 at 90's.









I learned Microsoft DOS and Windows. Then I learned C language.

I got AMD PC at year 2000 and I learned more about PC hardware.

I also knew about Microcontrollers ( Microchip PIC , Atmel , Renesas ) .

I programmed Microcontrollers in Assembly and C.

At 2006 I got Toshiba Satellite Notebook.

This year, I joined the Renesas HTS contest. I submitted my project " Multichannel Oscilloscope" and guess what , I had the forth honored mention.








http://www.renesasrulz.com/thread/2225;jsessionid=7AFAE50480BD5DF2D4D3F616A03277EA?decorator=print&displayFullThread=true




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