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.

what all the difficulties in writing first c program in mplab ide for 16f877a ?

Status
Not open for further replies.

rangerskm

Full Member level 4
Full Member level 4
Joined
Jan 23, 2013
Messages
199
Helped
0
Reputation
2
Reaction score
0
Trophy points
1,296
Visit site
Activity points
2,663
i am new to mplab and pickit2 programmer .i have pic 16f877a ic .i worked embedded c coding in keil ide for 8051.i want to know some of the initilization and coding guidelines in mplab .
1)what all the compilers available for mplab ide??
2)whats the benefit of using hi tech c compilers??
3)what is debuggers in mplab??
4)how to add header files and how can we know about header files??
5)what is configuration bits in mplab .whats the purpose of it??
can any of one suggest simple c program to glow led for pic 16f877a in mplab??
 

Rangerskm,
maybe is better for you to start with CCS C for PIC or MikroC,
better support, better explanations, super quality forums, many finished projects...
I wish you good lack...
regards
 

1)what all the compilers available for mplab ide??
2)whats the benefit of using hi tech c compilers??
if you are writing your code in C language, it can be compiled using hitech compiler... note that, this compiler doest come embeded along with the MPLAB (as far as i know).. you have to download it separately!! you can see other compilers under the "project" menu in language toolsuite option!!! The main advantage of hitech compiler is that you can just include <htc.h> at the beginning of your source code and can work for 16f877a pic.!! no need to embed other library fuction!!
4)how to add header files and how can we know about header files??
when you install hitech compiler separately, check the option to run it with microchip MPLAB!! you can find various header files in the "include" folder . explore the directory where u have installed your hitech compiler.... find htc.h and copy it to the folder where your code is located... for further clear information..... please read help of the MPLAB!!
regards...
 
led program not working with pic 16f877a.

HTML:
#include <htc.h>
 
void delay_ms ( int delay );
 
void delay_ms ( int delay )
{
	int ms, i;
 
	for ( ms = 0; ms < delay; ms ++ )
		for ( i = 0; i < 5; i ++ );
}
 
void main()
{
	while ( 1 )
	{ TRISB = 0x00;				// Set PORTB as output PORT
	  PORTB = 0xFF;			    // Set PORTB high initially (All LEDs on)
 	  	   	 // Toggle the value of PORTB
      	delay_ms ( 1000 );
		PORTB=0X00;   // Delay of 1 sec
	}
}

this is code i compiled in mplab ide .hi tech c compiler used.hex file generated but unable to work with hardware .for led connection with pic 16f877a
 

Use the program from my previous post above.

Follow the instructions step by step.

Code:
#include <htc.h>
#define _XTAL_FREQ 8000000
void main()
{
  TRISB=0X00;
  PORTB=0X00;
  while(1)
  { 
    PORTB=0XFF;
    _delay_ms(100);
    PORTB=0X00;
    _delay_ms(100);
  }
}

BigDog
 

why we are writing the xtal freq command ?i am using 12 mhz oscillator .so hows the code .how the working differs from different oscillator frequencies??
 

The HiTech compiler provides a set of accurate delay routines, _delay_ms() and _delay_us().

However, the compiler must have the current system clock frequency (Fosc) before it can generate the required code to implement the delay.

Which is the purpose of the following statement:

Code:
#define _XTAL_FREQ 8000000

If you current design is using a 12MHz crystal, simple make the following changes:

Code:
#define _XTAL_FREQ 12000000

Using these types of delay routines is definitely preferred over the for and while loop delays utilized in your previous code.

The source of this code, the link I previously posted, covers these and other issues in great detail.


BigDog
 

Code:
#include <pic.h>
 
void delay_ms ( int delay );
 
void delay_ms ( int delay )
{
	int ms, i;
 
	for ( ms = 0; ms < delay; ms ++ )
		for ( i = 0; i < 5; i ++ );
}
 
void main()
{
	TRISB = 0x00;				// Set PORTB as output PORT
	PORTB = 0XFF;//nitially (All LEDs on)
 
	while ( 1 )
	{
 			PORTB=0XFF;//oggle the value of PORTB
        	delay_ms ( 1000 );
        	PORTB=0X00;   // Delay of 1 sec
	}
}
actually i compiled the code and hex file also generated .but led is not glowing connected to port b.dont know whats the problem .
tried the MPLAB SIM and generate the output as


Code ASM - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
Address     SFR Name    Hex
 
            WREG         0x00
     000    INDF           --
     001    TMR0         0x00
     002    PCL          0xEB
     003    STATUS       0x1F
     004    FSR          0x00
     005    PORTA        0x00
     006    PORTB        0xFF
     007    PORTC        0x00
     008    PORTD        0x00
     009    PORTE        0x00
     00A    PCLATH       0x00
     00B    INTCON       0x00
     00C    PIR1         0x00
     00D    PIR2         0x00
     00E    TMR1         0x0000
     00E    TMR1L        0x00
     00F    TMR1H        0x00
     010    T1CON        0x00
     011    TMR2         0x00
     012    T2CON        0x00
     013    SSPBUF       0x00
     014    SSPCON       0x00
     015    CCPR1        0x0000
     015    CCPR1L       0x00
     016    CCPR1H       0x00
     017    CCP1CON      0x00
     018    RCSTA        0x00
     019    TXREG        0x00
     01A    RCREG        0x00
     01B    CCPR2        0x0000
     01B    CCPR2L       0x00
     01C    CCPR2H       0x00
     01D    CCP2CON      0x00
     01E    ADRESH       0x00
     01F    ADCON0       0x00
     081    OPTION_REG   0xFF
     085    TRISA        0x3F
     086    TRISB        0x00
     087    TRISC        0xFF
     088    TRISD        0xFF
     089    TRISE        0x07
     08C    PIE1         0x00
     08D    PIE2         0x00
     08E    PCON         0x00
     091    SSPCON2      0x00
     092    PR2          0xFF
     093    SSPADD       0x00
     094    SSPSTAT      0x00
     098    TXSTA        0x02
     099    SPBRG        0x00
     09C    CMCON        0x07
     09D    CVRCON       0x00
     09E    ADRESL       0x00
     09F    ADCON1       0x00
     10C    EEDATA       0x00
     10D    EEADR        0x00
     10E    EEDATH       0x00
     10F    EEADRH       0x00
     18C    EECON1       0x00
     18D    EECON2       0x00



what this defines and how it relates to hardware interfaces??
 

how to set the mplab ide 8.40 ?

i am new to mplab .i had worked out basic led program .it generated cof file .what it means??
hows cof file differs from hex file?.
compiler used hi tech c compiler.
then what all the menus and options has to be checked for correct working of mplab ide.

please help me..
 

i am new to mplab and pickit2 programmer .i have pic 16f877a ic .i worked embedded c coding in keil ide for 8051.i want to know some of the initilization and coding guidelines in mplab .
1)what all the compilers available for mplab ide??
2)whats the benefit of using hi tech c compilers??
3)what is debuggers in mplab??
4)how to add header files and how can we know about header files??
5)what is configuration bits in mplab .whats the purpose of it??
can any of one suggest simple c program to glow led for pic 16f877a in mplab??


You always have great support form microchip for PIC.
In the link you find the basics of using MPLAB.(your questions 1,3,4,5)
**broken link removed**

hitech and MPlab are just tow different type of compilers using C language.

There are many more examples and questions raised regarding MPLab programming
http://www.microchip.com/forums/

i am new to mplab .i had worked out basic led program .it generated cof file .what it means??
hows cof file differs from hex file?.
compiler used hi tech c compiler.
then what all the menus and options has to be checked for correct working of mplab ide.

please help me..

COF is the object file
HEX is the file which will be used to store in the microprocessor.

In mentioned link of my previous post study the PDF , you get cleared of your questions about MPLAB.
 

I tried this example and it did not compile without errors.

Changed _delay_ms(100) -----> __delay_ms(100) two (2) underscores in __delay_ms(100)
 
Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top