Electronic Projects, forums and more.

Go Back   Electronic Circuits Projects Diagrams Free > Electronics Categories > Micro Controllers


Micro Controllers Discuss all aspects of micro controllers - building them, coding them, etc. All controllers are welcome - PIC, BASIC, Z8 Encore!, etc.

Reply
 
LinkBack Thread Tools Display Modes
Old 11th January 2006, 12:04 AM   (permalink)
Default _config setting and blinking an LED

Hello All

Currently in the process of learning ASM and trying to use MPLAB to do so.
But I'm having trouble even getting an LED to blink using a 16F876.
No matter what I try nothing happens. Think its my config and "inc"
settings causing the issuse. Recieve errors when BUILDING.....



Error[113] C:\PIC\BLINK 16F876-B.ASM 8 : Symbol not previously defined (cmcon)
Error[113] C:\PIC\BLINK 16F876-B.ASM 15 : Symbol not previously defined (trisc)
Error[113] C:\PIC\BLINK 16F876-B.ASM 16 : Symbol not previously defined (status)
Error[113] C:\PIC\BLINK 16F876-B.ASM 17 : Symbol not previously defined (portc)
Error[113] C:\PIC\BLINK 16F876-B.ASM 20 : Symbol not previously defined (portc)
Skipping link step. Not all sources built successfully.
BUILD FAILED: Tue Jan 10 19:10:57 2006


Will someone show me the right way to set the _config and "inc" settings
for a 16F876 using 10Mhz. If possible maybe a small piece of code that
blinks an LED.

Thanks any help or ideas in advance
Gordon
GRC is offline  
Old 11th January 2006, 12:19 AM   (permalink)
Default

You are probably missing an include file. It has all the definitions you need (porta, trisa and so on). Make sure that you import the correct file, see example image.

PS: The Linker file is not necessary, but I find it very useful. Don't include it if it causes problems to you...
Attached Images
File Type: png basic_stuff.png (2.9 KB, 512 views)
__________________
"I share, thus I am"
Jay.slovak
Read this!
ICD2 Clone
Best PIC/DsPIC Bootloader

Read my Inchworm ICD2 review!
Jay.slovak is offline  
Old 11th January 2006, 12:29 AM   (permalink)
Default

In addition to Jay's suggestion, you can include the location of the "include_file", a PIC specific file with the file extension .inc (p16F876.inc in your case) into your ASM source file like one of the followings, so MPLAB IDE can find it during compiling:

Code:
 
Syntax 

Preferred: 
    #include include_file
    #include "include_file"
    #include <include_file>

Supported: 
    include include_file
    include "include_file"
    include <include_file>

Simple Example 
    #include p18f452.inc  ;standard include file
    #include "c:\Program Files\mydefs.inc"  ;user defines
The inc file has all the standard definitions like "PORTC", "TRISA".....so you do not have to define them again. Please also make sure that you are aware of the difference between lowercase and uppercase letters as they are considered different.

This is all clearly described in the hlpMpasmAsm.chm help file as part of the MPLAB IDE installation. Looks under the MPASM Assembler/Directives branch of the help file for details.
__________________
L.Chung
eblc1388 is offline  
Old 11th January 2006, 06:37 PM   (permalink)
Default

Hi Guys
Thanks for your help and tips.
Well I fianlly found the header files. Still no luck. Reciecving...

Clean: Deleting intermediary and output files.
Clean: Done.
Executing: "C:\Program Files\MPLAB IDE\MCHIP_Tools\mpasmwin.exe" /q /p16F876 "Test Header.asm" /l"Test Header.lst" /e"Test Header.err" /o"Test Header.o"
Warning[205] C:\PIC\TEST HEADER.ASM 1 : Found directive in column 1. (list)
Error[108] C:\PIC\TEST HEADER.ASM 3 : Illegal character (0)
Message[302] C:\PIC\TEST HEADER.ASM 12 : Register in operand not in bank 0. Ensure that bank bits are correct.
Message[302] C:\PIC\TEST HEADER.ASM 13 : Register in operand not in bank 0. Ensure that bank bits are correct.
Skipping link step. Not all sources built successfully.
BUILD FAILED: Wed Jan 11 13:40:31 2006

What am I doing wrong. This is getting real frustrating. I know its
something simple but what it is I don't know.
GRC is offline  
Old 11th January 2006, 08:01 PM   (permalink)
Default

Hello again

Heres my code, for some unknown reason my computer will not let
me post the code inside the code box. Sorry for that.


LIST P=PIC16F876
#include "P16F876.INC"
_config, _WDT_OFF, _LVP_OFF, _PWRTE_ON, _CP_OFF, BODEN_OFF, _DEBUG_OFF

org 0
nop
nop

bsf H'0003 ;"status" label gives error message
bcf trisb, 4
bcf H'0003
start bcf portb, 4
nop
nop ;short pause
nop
nop
nop

bsf portb, 4
goto start
END


After trying to BUILD this the following error is displayed

Error[129] C:\PIC\BLINK.ASM 1 : Expected (END)

Any thought about this? L.Chung, thanks for the hlpMpasmAsm.chm tip.
Took a while, but it was finally found.
GRC is offline  
Old 12th January 2006, 12:23 AM   (permalink)
Default

Quote:
Originally Posted by GRC
bsf H'0003 ;"status" label gives error message
Of course it gives error message. BSF, BCF instructions operate on a single bit so you must specify both a file location and a bit position, e.g. the RP0 in the following example. In the p16f876.inc file, RP0 is defined to some value.

To change bank, you use:
Code:
BSF status,RP0   ;bsf needs two arguments
Your code:
Code:
start bcf portb, 4
       nop
       nop ;short pause
       nop
       nop
       nop
 
       bsf portb, 4
       goto start
It will not work as you would expect it to work. All it does is to produce a very narrow pulse and not a square pulse. If you want a square pulse, you need to place delay routine after each port change instruction.

Quote:
Originally Posted by GRC
After trying to BUILD this the following error is displayed

Error[129] C:\PIC\BLINK.ASM 1 : Expected (END)
You must have placed the "end" directive in column 1 and confused the assembler to treat it as a label instead. Therefore assembler complains that there is no "END" to your source program.
__________________
L.Chung
eblc1388 is offline  
Old 12th January 2006, 11:19 PM   (permalink)
Default

Thank you for the reply.
After playing around with MPLAB for awhile, finally got my code working.
Do not recall the "END" directive being in the 1st column, but some how
got around this. Perhaps a double check will make more sense of this.

Thanks for tips and help
Gordon
GRC is offline  
Old 13th January 2006, 12:24 AM   (permalink)
Default hex notation

I use always for heaxadecimal values this notation: H'04'

Please note the apostrophe at the end.
__________________
Agustín Tomás
In theory, there is no difference between theory and practice. In practice, however, there is.
atferrari is offline  
Reply

Bookmarks

Thread Tools
Display Modes





All times are GMT. The time now is 05:18 AM.


Electronic Circuits  |  Learning Electronics
Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.

eXTReMe Tracker