Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Learning First project with PIC Microcontroller

Status
Not open for further replies.

Fan174

Member level 2
Member level 2
Joined
Mar 27, 2018
Messages
51
Helped
0
Reputation
0
Reaction score
0
Trophy points
6
Activity points
413
Hello everyone

I have just started to learn about PIC. I would like to simply light a led with a microchip "PIC16F877A" I have installed MPLABX IDE

My code

Code:
#include <[I]stdio.h[/I]>
#include <[I]stdlib.h[/I]>
int main(int argc, char** argv) {
TRISA=0x00;		//Configure PORT A as Output
TRISB=0x00;		//Configure PORT B as Output	
TRISC=0x00;		//Configure PORT C as Output
TRISD=0x00;		//Configure PORT D as Output
TRISE=0x00;		//Configure PORT E as Output

PORTA=0; 
PORTB=0;
PORTC=0;
PORTD=0;
PORTE=0;

while(1)
	{
	PORTA=~PORTA;	
	PORTB=~PORTB;	
	PORTC=~PORTC;	//Toggle the All PORTS
	PORTD=~PORTD;	
	PORTE=~PORTE;	
	__delay_ms(500);//Delay 500 milliseconds
	}
    return (EXIT_SUCCESS);
}


PIC project.jpg


Code:
make -f nbproject/Makefile-default.mk SUBPROJECTS= .build-conf
make[1]: Entering directory 'F:/Software/PiC Development/PIC DEVELOPMENT BOARD/Example Programs FOR 16F877A/2. LCD/LCD 8 Bit/LED.X'
make  -f nbproject/Makefile-default.mk dist/default/production/LED.X.production.hex
make[2]: Entering directory 'F:/Software/PiC Development/PIC DEVELOPMENT BOARD/Example Programs FOR 16F877A/2. LCD/LCD 8 Bit/LED.X'
"C:\Program Files (x86)\Microchip\xc8\v1.45\bin\xc8.exe" --pass1  --chip=16F877A -Q -G  --double=24 --float=24 --opt=+asm,+asmfile,-speed,+space,-debug,-local --addrqual=ignore --mode=free -P -N255 --warn=-3 --asmlist -DXPRJ_default=default  --summary=default,-psect,-class,+mem,-hex,-file --output=default,-inhx032 --runtime=default,+clear,+init,-keep,-no_startup,-osccal,-resetbits,-download,-stackcall,+clib   --output=-mcof,+elf:multilocs --stack=compiled:auto:auto "--errformat=%f:%l: error: (%n) %s" "--warnformat=%f:%l: warning: (%n) %s" "--msgformat=%f:%l: advisory: (%n) %s"    -obuild/default/production/newmain.p1  newmain.c 
make[2]: *** [build/default/production/newmain.p1] Error 1
make[1]: *** [.build-conf] Error 2
make: *** [.build-impl] Error 2
newmain.c:4: error: (192) undefined identifier "TRISA"
newmain.c:5: error: (192) undefined identifier "TRISB"
newmain.c:6: error: (192) undefined identifier "TRISC"
newmain.c:7: error: (192) undefined identifier "TRISD"
newmain.c:8: error: (192) undefined identifier "TRISE"
newmain.c:10: error: (192) undefined identifier "PORTA"
newmain.c:11: error: (192) undefined identifier "PORTB"
newmain.c:12: error: (192) undefined identifier "PORTC"
newmain.c:13: error: (192) undefined identifier "PORTD"
newmain.c:14: error: (192) undefined identifier "PORTE"
newmain.c:23: warning: (361) function declared implicit int
(908) exit status = 1
nbproject/Makefile-default.mk:106: recipe for target 'build/default/production/newmain.p1' failed
make[2]: Leaving directory 'F:/Software/PiC Development/PIC DEVELOPMENT BOARD/Example Programs FOR 16F877A/2. LCD/LCD 8 Bit/LED.X'
nbproject/Makefile-default.mk:90: recipe for target '.build-conf' failed
make[1]: Leaving directory 'F:/Software/PiC Development/PIC DEVELOPMENT BOARD/Example Programs FOR 16F877A/2. LCD/LCD 8 Bit/LED.X'
nbproject/Makefile-impl.mk:39: recipe for target '.build-impl' failed

BUILD FAILED (exit value 2, total time: 2s)

I am struggling with first project I don't understand what's the problem Please guide me in right way
 
Last edited by a moderator:

There are two problems:

1. the reason for the errors is it doesn't know which processor to use and can't tell which ports and bit names are applicable to it. You probably want to add
"#include <xc.h>" at the top and make sure you have the 16F877A selected as the target processor in the IDE.

2. more generally, the style of code is applicable to a console program rather than a microcontroller. Consider that the "int main(int argc, char** argv)" says "count the number of command parameters passed to the program in 'argc' and list them in array 'argv'. In a console program (on a PC for example) you might start the program with a list of parameters but in a self contained microcontroller there is no way to do that. Similarly, "return (EXIT_SUCCESS);" would go back to the command prompt on a console program but there is nowhere to return to when there is no operating system.

Brian.
 

I was following this link **broken link removed**
 

That's quite an old tutorial, based on a much older version of MPLABX.

Try adding "#include <xc.h>XC.h" to the top of your program and see if that fixes it. The problem is that the register names and bit names are different from one processor to another so to be able to use the right one when it compiles the program, it has to 'include' the appropriate header file. The header file contains the cross reference between register names and their addresses as only the addresses are used during compilation. Adding XC.h should tell the compiler to use the header associated with the processor you selected in the configuration menu.

Brian.</xc.h>
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top