Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronic 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.

Register Log in

Initialiaze Port for PIC32MX7

Status
Not open for further replies.

iqbalhabibie

Junior Member level 2
Joined
Nov 19, 2012
Messages
23
Helped
4
Reputation
8
Reaction score
4
Trophy points
1,283
Activity points
1,416
Hi, I'm newbie and just bought Microchip MMB for PIC32MX7 and using MPLAB Real Ice downloader and MPLAB C32 for compiler and IDE program micro C to get hex file to compile to MPLAB downloader. I was wondering how to initialize the port and the pins. Can you help me? and where could i find this tutorial and easy example for Microchip PIC32MX7. I have tried to compare from example micro C and make myself it doesn't work.

Example micro C for led blinking:

Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
void main() {
  AD1PCFG = 0xFFFF;
  
  TRISB = 0;             // Initialize PORTB as output
  TRISC = 0;             // Initialize PORTC as output
  TRISD = 0;             // Initialize PORTD as output
  TRISE = 0;             // Initialize PORTE as output
 
  LATB = 0;              // Set PORTB to zero
  LATC = 0;              // Set PORTC to zero
  LATD = 0;              // Set PORTD to zero
  LATE = 0;              // Set PORTE to zero
 
  while(1) {
    LATB = ~LATB;        // Invert PORTB value
    LATC = ~LATC;        // Invert PORTC value
    LATD = ~LATD;        // Invert PORTD value
    LATE = ~LATE;        // Invert PORTE value
    Delay_ms(1000);
  }
}



My program:

Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
void main()
        {
        TRISB = 0 ;     // set PORTB as OUTPUT
 
        for(;;)         // forever
                {
                PORTB = 0xff ;          // turn all LEDs ON
                Delay_ms(500) ;         // wait 500 ms
                PORTB = 0 ;             // turn all LEDs OFF
                Delay_ms(500) ;         // wait 500 ms
                }
        }


Is there some kind different configuration?, i have my program but it doesn't blink my LED and also the Led don't turn ON also turn OFF.
 
Last edited by a moderator:

iqbalhabibie

Junior Member level 2
Joined
Nov 19, 2012
Messages
23
Helped
4
Reputation
8
Reaction score
4
Trophy points
1,283
Activity points
1,416
i have tried changing my program above from :

Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
void main()
{
TRISB = 0 ; // set PORTB as OUTPUT
 
for(;;) // forever
{
LATB = 0xff ; // turn all LEDs ON
Delay_ms(500) ; // wait 500 ms
LATB = 0 ; // turn all LEDs OFF
Delay_ms(500) ; // wait 500 ms
}
}



it doesn't work as you acquire.
 
Last edited by a moderator:

Joined
Jul 25, 2012
Messages
1,192
Helped
170
Reputation
340
Reaction score
161
Trophy points
1,343
Activity points
0
Which compiler are you using MPLAB C32? Have you included the include file for your mcu?
 

iqbalhabibie

Junior Member level 2
Joined
Nov 19, 2012
Messages
23
Helped
4
Reputation
8
Reaction score
4
Trophy points
1,283
Activity points
1,416
yes i am using MPLAB C32, this is my script :


Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
#include <p32xxxx.h>
 
void main()
        {
        TRISB = 0 ;     // set PORTB as OUTPUT
 
        for(;;)         // forever
                {
                LATB = 0xff ;          // turn all LEDs ON
                Delay_ms(500) ;         // wait 500 ms
                LATB = 0 ;             // turn all LEDs OFF
                Delay_ms(500) ;         // wait 500 ms
                }
        }




The problem :
Code:
Warning: Debugger-specific command-line options may be missing.
Executing: "C:\Program Files (x86)\Microchip\mplabc32\v2.01\bin\pic32-gcc.exe" -mprocessor=32MX795F512L "..\..\MultiMedia Board for PIC32MX7 Examples\Test\led_blinking.o" -o"C:\mini2440\Mikrochip\MultiMedia Board for PIC32MX7 Examples\Test\led blinking 2.elf" -Wl,-L"C:\Program Files (x86)\Microchip\mplabc32\v2.01\pic32mx\lib",--defsym=__MPLAB_BUILD=1,--defsym=__MPLAB_DEBUG=1,-Map="C:\mini2440\Mikrochip\MultiMedia Board for PIC32MX7 Examples\Test\led blinking 2.map"
..\..\MultiMedia Board for PIC32MX7 Examples\Test\led_blinking.o: In function `main':
C:\mini2440\Mikrochip\from example\led blinking 2/led_blinking.c:22: undefined reference to `Delay_ms'
C:\mini2440\Mikrochip\from example\led blinking 2/led_blinking.c:24: undefined reference to `Delay_ms'
collect2: ld returned 1 exit status
Link step failed.
----------------------------------------------------------------------
Debug build of project `C:\mini2440\Mikrochip\from example\led blinking 2\led blinking 2.mcp' failed.
Language tool versions: pic32-ar.exe v2.01, pic32-gcc.exe v2.01, pic32-ld.exe v2.01, pic32-ar.exe v2.01
Preprocessor symbol `__DEBUG' is defined.
Mon Nov 19 14:21:55 2012
----------------------------------------------------------------------
BUILD FAILED
Am i right using include <p32xxxx.h> because i have check in C:\Program Files (x86)\Microchip\MPLAB C32 Suite\pic32mx\include. there is include file for my mcu like this.
 
Last edited by a moderator:

Joined
Jul 25, 2012
Messages
1,192
Helped
170
Reputation
340
Reaction score
161
Trophy points
1,343
Activity points
0
You also have to include delay.h file. If including delay.h file doesn't work then you have to check if Delay_ms() function can be used or not. Delay_ms() is a mikroC function maybe in C32 it is different something like __delay_ms() like that. You check some PIC32 examples in the examples folder, see how delay function is used.

Where is you configuration settings like oscillator frequency, pll settings if you are using pll, WDT settings, etc.,?
 
Last edited:

iqbalhabibie

Junior Member level 2
Joined
Nov 19, 2012
Messages
23
Helped
4
Reputation
8
Reaction score
4
Trophy points
1,283
Activity points
1,416
well,i have check in directory include there is no delay. How do you make this delay. thanks.

- - - Updated - - -

or could you give some easy script to run in my microchip to run on my led or make led blinking, then i'll try to make new one. Thanks.
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Top