![]() | ![]() | ![]() |
| |||||||
| Micro Controllers Discuss all aspects of micro controllers - building them, coding them, etc. All controllers are welcome - PIC, BASIC, Z8 Encore!, etc. |
![]() |
| | Tools |
| | #1 |
|
Hi all! I think I'm going in the wrong way.I love PIC Microcontrollers and for the Language I'm using Assembley.I have a fair knowledge of programing experience.When I see a program I can understand 50%.So I want to develop my knowledge upto a standard level.I'm a self study beginner.We dont have Programing courses.No body knows about PICs in my area.I have only lectro-tech-online to ask question's I like to ask what are the techniques you guys following when programing PIC microcontrollers? Ex:-placing the header files,variables,subroutines,placing the interupts in the correct places,page boundaries and the text format simple letters or capital letters etc.... It's shy to tell but I must tell the truth.If I'm going to write a programI just open a note pad & just write the program. I never write the program in the MPLAB.I use MPLAB only to convert the ASM file to HEX file.(with the quick build option) What is the correct technique,what libraries do I have to import? How to simulate a program?(with the DELAY Loops can I use the simulator?) Is the Assembley language ok?Do I have to shift to another language?In future is this language will be available? Any comments will accepted having any links,Tutorials,Articles will be a great help Thank a lot Suraj | |
| |
| | #2 |
|
I would suggest that you stick with assembler for now and try some high level languages later. Use MPLAB and the simulator. Use the templates supplied by Microchip - there is C:\Program Files\Microchip\MPASM Suite\Template\Code. Use the include file so you can do btfss STATUS,Z rather that btfss 3,2 - it is much more readable and less prone to errors. This is what the template file looks like. Code: ; This file is a basic code template for assembly code generation * ; on the PICmicro PIC16F628A. This file contains the basic code * ; building blocks to build upon. * ; * ; If interrupts are not used all code presented between the ORG * ; 0x004 directive and the label main can be removed. In addition * ; the variable assignments for 'w_temp' and 'status_temp' can * ; be removed. * ; * ; Refer to the MPASM User's Guide for additional information on * ; features of the assembler (Document DS33014). * ; * ; Refer to the respective PICmicro data sheet for additional * ; information on the instruction set. * ; * ;********************************************************************** ; * ; Filename: xxx.asm * ; Date: * ; File Version: * ; * ; Author: * ; Company: * ; * ; * ;********************************************************************** ; * ; Files required: * ; * ; * ; * ;********************************************************************** ; * ; Notes: * ; * ; * ; * ; * ;********************************************************************** list p=16f628A ; list directive to define processor #include <p16F628A.inc> ; processor specific variable definitions errorlevel -302 ; suppress message 302 from list file __CONFIG _CP_OFF & _DATA_CP_OFF & _LVP_OFF & _BOREN_OFF & _MCLRE_OFF & _WDT_OFF & _PWRTE_ON & _INTOSC_OSC_NOCLKOUT ; '__CONFIG' directive is used to embed configuration word within .asm file. ; The lables following the directive are located in the respective .inc file. ; See data sheet for additional information on configuration word settings. ;***** VARIABLE DEFINITIONS w_temp EQU 0x71 ; variable used for context saving status_temp EQU 0x72 ; variable used for context saving ;********************************************************************** ORG 0x000 ; processor reset vector goto main ; go to beginning of program ORG 0x004 ; interrupt vector location movwf w_temp ; save off current W register contents movf STATUS,w ; move status register into W register movwf status_temp ; save off contents of STATUS register ; isr code can go here or be located as a call subroutine elsewhere movf status_temp,w ; retrieve copy of STATUS register movwf STATUS ; restore pre-isr STATUS register contents swapf w_temp,f swapf w_temp,w ; restore pre-isr W register contents retfie ; return from interrupt main ; remaining code goes here goto main ;loop forever, remove this instruction, for test only ; initialize eeprom locations ORG 0x2100 DE 0x00, 0x01, 0x02, 0x03 END ; directive 'end of program' Mike. | |
| |
| | #3 |
|
Use the editor in MPLAB
| |
| |
| | #4 |
|
Hi thanks for the suggestions. Really a nice method template file. I tried some experiments doing with MPLAB. But it’s giving me several error messages. I went through the project wizard. These two files I add to my project - f628Atemp.asm & P16F628A.inc I wrote a small program in the f628Atemp.asm file. After building this error message prompt. Code: Clean: Deleting intermediary and output files. Clean Warning: File "f628Atemp.err" doesn't exist. Clean Warning: File "C:\Documents and Settings\Suraj\Desktop\run\f628Atemp.hex" doesn't exist. Clean Warning: File "f628Atemp.lst" doesn't exist. Clean: Done. Executing: "C:\Program Files\Microchip\MPASM Suite\MPASM.exe" /q /p16F628A "f628Atemp.asm" /l"f628Atemp.lst" /e"f628Atemp.err" BUILD FAILED: Fri Apr 27 09:46:09 2007 I got this error message. Error - no input object files specified. Code: Clean: Deleting intermediary and output files. Clean Warning: File "f628Atemp.err" doesn't exist. Clean Warning: File "C:\Documents and Settings\Suraj\Desktop\run\f628Atemp.hex" doesn't exist. Clean Warning: File "f628Atemp.lst" doesn't exist. Clean: Done. Executing: "C:\Program Files\Microchip\MPASM Suite\MPASM.exe" /q /p16F628A "f628Atemp.asm" /l"f628Atemp.lst" /e"f628Atemp.err" /o"f628Atemp.o" Executing: "C:\Program Files\Microchip\MPASM Suite\MPLink.exe" "C:\Program Files\Microchip\MPASM Suite\LKR\16f628a.lkr" /o"LED.cof" /M"LED.map" MPLINK 3.94, Linker Copyright (c) 2005 Microchip Technology Inc. Error - no input object files specified. Errors : 1 BUILD FAILED: Fri Apr 27 09:49:28 2007 Here is my project tree. And another question in the .INC file I see all the SFR and the bits which relevant to that registers. But the INC file won’t do anything. If I forgot any bit I just look from INC file. Is this the purpose of that file? (From the datasheet also I can see this bits so why I need this file) Actually what is the purpose of this INC file? I have included this line in the .ASM file. #include <p16F628A.inc> Last edited by Suraj143; 27th April 2007 at 08:24 AM. | |
| |
| | #5 |
|
Let’s see if we can get you up and running with a blank asm file. Open MPLAB. Open the project wizard. (Next) Select 16F628A (Next) Select “Microchip MPASM Toolsuite” (Next) Enter “First” for Project Name Browse to My Documents and make a new folder called “FirstProject” (Next) At the add files stage click Next and then Finish. You should now have a blank project. Do File/New to get a blank window. Cut and paste the template file I posted earlier in this thread into the blank window. Do File/SaveAs and save the file in the FirstProject folder and call it First.asm. In the project window, right click on “Source Files” and add file First.asm Press F10 and it should compile without any errors. Enter some code after the main label and have fun. The purpose of the include file is so you don’t have to declare all the SFR values. You no longer need to know that bit 2 of location 3 is the zero flag – you just do btfsc STATUS,Z. You can also do things like bsf T1CON,TMR1ON to turn timer 1 on etc. Mike. | |
| |
| | #6 |
|
Thanks Mike for your suggestion I'll try to do like that.
| |
| |
|
| Tags |
| good, programing, techniques |
| Thread Tools | |
| Display Modes | |
| |
Similar | ||||
| Title | Starter | Forum | Replies | Latest |
| Is $20 a good price for a P16PRO40 Programmer? | Mike, K8LH | Micro Controllers | 11 | 5th July 2005 02:19 PM |
| Where to get Good Power Supplies? | Megamox | General Electronics Chat | 10 | 26th May 2005 12:06 AM |
| Good intro to PICs... | pwollner | Micro Controllers | 1 | 18th February 2004 03:37 AM |
| Need a Good and easy project of Cotrol !!! | gravityforu | Electronic Projects Design/Ideas/Reviews | 1 | 12th December 2002 03:43 PM |
| Good source for learning the 68hc11 and 27c256 | NcNghtStkr | General Electronics Chat | 3 | 1st November 2002 04:01 PM |