Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

_config setting and blinking an LED

Status
Not open for further replies.

GRC

New Member
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
 
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...
 

Attachments

  • basic_stuff.png
    basic_stuff.png
    2.9 KB · Views: 954
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.
 
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.
 
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 said:
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.

GRC said:
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.
 
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
 
hex notation

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

Please note the apostrophe at the end.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top