PIC SDK

From ElectroDragon
Revision as of 12:29, 17 December 2019 by Chao (talk | contribs) (Created page with " == Quick start guide == * You will need PICKIT3, and dvelopment board PIC16F72, install the pin headers for programming * Find MPLAB 8.x version in our github page, and use...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search


Quick start guide

  • You will need PICKIT3, and dvelopment board PIC16F72, install the pin headers for programming
  • Find MPLAB 8.x version in our github page, and use the code below, or download here of the workspace zip file - File:Led pic.zip
#include<htc.h>

// Config word ?? no need
//__CONFIG(FOSC_HS & WDTE_OFF & PWRTE_ON & CP_OFF);

// Define LED pin
#define LED  RA0

// Define CPU Frequency
// This must be defined, if __delay_ms() or 
// __delay_us() functions are used in the code
#define _XTAL_FREQ   8000000    


// Main function
void main()
{	
	TRISA0 = 0;				   // Make RA0 pin output
	LED    = 0;				   // Make RA0 low
	
	while(1)
	{
		__delay_ms(500);       // Half sec delay
		LED = 0;               // LED off
		__delay_ms(500);       // Half sec delay
		LED = 1;               // LED on
	}
}

Toolchain

Hardware

  • PICkit3 programmer
  • K150 (old)

Compiler

  • HI-TECH universal toolsuite (compiler)
  • C18

Hex programmer

  • Pickit standalone programmer - > upgraded to X IPE

IDE

  • MPLAB X IDE

PIC18 USB IAP Tool

  • HIDbootloader.exe (in CD disk)

Build Guide MPlab IDE

toolchain setup animation
  • Updated with animation tutorial
  • Install MPLAB, HI-TECH PICC9.83
  • select MCU -> pic16f72
  • programmer -> pickit3
  • project wizard -> use compiler hi-tech universal toolsuite -> ANSIS
  • click to compile the default project, blink RA0 LED

build first demo and flash

Upload code
  • Must select proper configuration bit, check crystal, LP - low power, RC internal, XT external, HS high speed crystal, for 8M crystal should use this one, read more on datasheet
  • Demo use pickit standalone programmer, configuration bit set to 3FF2
  • Crystal - HS crystal
  • WDT - disable -> 0
  • Power-on timer - enable -> 0
  • BOR - enable -> 1
  • LP - code protection off -> 1

Application

Reference

Registers

  • TRISx Used to configure the respective PORT as output/input
 /* Configure all the ports as Output */
   TRISA = 0x00;
   TRISB = 0x00;
   TRISC = 0x00;
   TRISD = 0x00; 
  • PORTx Used to Read/Write the data from/to the Port pins
PORTA = 0xff; /* Turn ON all the leds connected to Ports */
  • ANSEL – ANALOG SELECT REGISTER

Datasheet

Demo code

Toolchain and compiler

Flash by MPLAB IPE

Old - not used

  • Build and program, follow the guide below
  • Use PICkit programmer

PIC programmer.jpg


Official Resource

Note

  • RA3 is input only