| ||
How to use our PIC Tutorials To get the most out of our PIC Tutorial, you should read this page first. Here i will explain the structure of the tutorial pages and the program files, so that you will not get confused. The Tutorial Structure Each tutorial consists of four basic parts: This is the very first part. The prologue and a quick description of the tutorial, as well as the purpose of it, are written within the first lines. At the top-right corner there is a photo of the circuit. A video is also attached that demonstrates the tutorial in operation. The next part is the circuit. This is where the schematic drawing is attached, and -if necessary- explained. The third part is the code. There is a code window with the code to be explained. Please note that in this window, there is ONLY THE IMPORTANT CODE for this tutorial. The rest of the code can be found to the attached files, at the fourth and last part of each tutorial. The reason that i chose to show only a part of the code is obvious. A complete PIC program consists of several initialization instructions, subroutines and other stuff. But the goal of each tutorial is not to explain the complete program structure each time. The goal is to explain a specific routine, function or instruction. The rest of the code shall be ignored for the moment and will not be discussed. As the level rises, more and more code will be explained. At the end, each and every line of a PIC program will be explained in details. Of course, the complete code is attached at the 4th part of the tutorial. This is the last part of the tutorials. Here you can find all the files of the program. You can extract the zip file into a directory and directly compile-upload the code to a PIC. The Files I have tried to keep a unified structure for all the tutorials within this book. All tutorials comes in .zip packages. Within the zip container, you will find the following files:
Call Wait10mSec If you are a beginner, i encourage you to use this file. You can make your own subroutines for your custom time-delays. There will be a complete lesson for calculating and generating custom delays, but until then, these subroutines will be used extensively. The asm Program After explaining the files that exist within the container, i will explain the parts that the main assembly listing file (.asm) has:
list F=inhx8m, P=16F88, R=hex, N=0 #include P16F88.inc; PIC definitions __config _config1,_INTRC_IO & _WDT_OFF & _LVP_OFF & _PWRTE_OFF & _MCLR_ON & _BODEN_ON & _LVP_OFF & _CPD_OFF & _WRT_PROTECT_OFF & _CCP1_RB0 & _CP_OFF __config _config2,_IESO_OFF & _FCMEN_OFF Errorlevel -302 ; switches off Message [302]: Register in operand not in bank 0. The above code should be used as-is. First, It contain information about the assembly listing. Then, the PIC16F88 header file is included into the code. The __config lines will set the configuration bits of the PIC (explained in later pages). Finally, the 302 annoying message is turned off from the compiles.
; Definitions ------------------------------------------------------------- #Define ButtonInput PORTA,0 Now i can refer to PORTA,0 pin by using its defined name 'ButtonInput'.
; RAM preserved ----------------------------------------------------------- cblock 0x20 WaitCounter,WaitCounter2 IntervalCounter endc Now i can refer to PORTA,0 pin by using its defined name 'ButtonInput'. The first two registers (WaitCounter and WaitCounter2) will be found in almost all tutorials. These two registers are used by the delay subroutines described above.
; Conastants -------------------------------------------------------------- GLDoubleClick_Interval = d'15' GLDoubleClick_MaxDelay = d'30' GLLongClick_Interval = d'80' Now, i can load the value d'15' by referring to it's name: movlw GLDoubleClick_Interval.
; Program Memory ---------------------------------------------------------- org 0 ; Main program offset goto Init ; Jump to initialization routine ; Interrupt Service Routine ----------------------------------------------- org 4 ; ISR beginning ; ------------------------------------------------------------------------- ; Microcontroller initialization Init include Init_normal.inc ;Include the PIC Initialization routine ;########################################################################## Now, everything is ready for the main programm!
;########################################################################## ; Main Program ------------------------------------------------------------ Start . . . [ HERE IS THE MAIN CODE ] . . . include mSecDelays4MHz.inc Fins end ; end of program Comments
No part of this publication may be reproduced, stored in a retrieval system or transmitted in any form or by any means, electronic, mechanical, photocopying, recording, scanning or otherwise without the prior written permission of the author. Read the Disclaimer
All trademarks used are properties of their respective owners.
Copyright © 2007-2009 Lazaridis Giorgos. All rights reserved. |
|
Contact
Forum
Projects
Experiments
Circuits
Theory
BLOG
PIC Tutorials
Time for Science
RSS
Site design: Giorgos Lazaridis © Copyright 2008 Please read the Terms of services and the Privacy policy |