PIC32MX795F512L >> C/C++

LED


main.c

#include <stdio.h>
#include <stdlib.h>

#define TRISECLR *((volatile unsigned long*)0xBF886104)
#define PORTECLR *((volatile unsigned long*)0xBF886114)
#define PORTESET *((volatile unsigned long*)0xBF886118)

void sdelay(void)
{
  unsigned int cnt=5000;
  while(cnt--);
}

int main(int argc, char** argv)
{
  TRISECLR = 0x0f;
  PORTESET = 0xff;
  while(1){
    PORTECLR = 0x01;
    PORTESET = 0x06;
    sdelay();

    PORTECLR = 0x02;
    PORTESET = 0x05;
    sdelay();
    
    PORTECLR = 0x04;
    PORTESET = 0x03;
    sdelay();
  }
  return 0;
}

Makefile

all:
  xc32-gcc main.c -o main.elf
  xc32-bin2hex main.elf main.hex

clean:
  rm -rf main.hex main.elf

編譯

$ export PATH=$PATH:/opt/microchip/xc32/v2.05/bin/
$ make clean
$ make

P.S. 接著使用MPLAB IPE燒錄main.hex檔案就可以

完成


返回上一頁