Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

PIC C compilers

Status
Not open for further replies.
Sure, here's a sample from the code I'm currently working on. Note that I am too lazy to remove the STATUS_LED define, but you get the idea.

Configuration and peripheral setup can also be autogenerated, I believe HI-TECH saves it to init.h and then includes it upon build.

The target PIC is set via the GUI, but might be possible to set in code. Crystal frequency (for delay purposes) is set in the compiler options, but could probably be set via a #define. I haven't checked the manual for those two yet.

Code:
#include <htc.h>
#include "delay.h"

__CONFIG(1, FCMDIS & IESODIS & INTIO);
__CONFIG(2, BORDIS & PWRTEN & WDTDIS & WDTPS1);
__CONFIG(3, CCP2RB3 & LPT1DIS & MCLRDIS & 0xFDFF);
__CONFIG(4, DEBUGDIS & XINSTDIS & LVPDIS & STVRDIS);
__CONFIG(5, UNPROTECT);
__CONFIG(6, 0xFFFF);
__CONFIG(7, 0xFFFF);

#define STATUS_LED LATC3

void main()
{
	// Internal 8Mhz oscillator
	IRCF2 = 1;
	IRCF1 = 1;
	IRCF0 = 1;
	
	// Wait for clock to be stable
	while (!IOFS);
	
	// All digital IO, outputs
	TRISA = 0x00;
	TRISB = 0x00;
	TRISC = 0x00;
	
	// Disable ADC functions
	ADCON0 = 0;

	while (1) {
		STATUS_LED = 1;
		DelayMs(250);
		STATUS_LED = 0;
		DelayMs(250);
	}
}

AtomSoft: I notice from your blog that you are comparing a few other C compilers. If you want we could write some sample code and do a comparison between the popular compilers at their current versions (e.g. code size, compiler features). Would be a nice blog entry for both of us. PM me if you want to talk about it.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top