Monday, June 8, 2009

Some Starter C18 Code for the PIC18

I haven’t posted anything in a while, so here is some C18 code for a starting off a project.

#include 
#include 
#include 
#include 

#pragma config OSC = INTIO67	//Internal oscillator
#pragma config FCMEN = OFF
#pragma config IESO = OFF
#pragma config PWRT = ON
#pragma config BOREN = OFF
#pragma config WDT = OFF
#pragma config MCLRE = OFF		//MCLR is disabled
#pragma config PBADEN = OFF
#pragma config LVP = OFF
#pragma config XINST = ON		//extended mode enabled

long int i = 0;

void delay1s() {
	Delay10KTCYx(200);
	Delay10KTCYx(200);
	Delay10KTCYx(200);
	Delay10KTCYx(200);
}

void main() {
	OSCCON = 0b01110000; 	//8 MHz
	OSCTUNE = 0b01011111;	//enable PLL
	TRISC = 0x00;			//PORTC is all output
	stdout = _H_USART; 		//Set to user-defined output stream via _user_putc
	
	OpenUSART(USART_TX_INT_OFF & USART_RX_INT_OFF & USART_ASYNCH_MODE & USART_EIGHT_BIT & USART_CONT_RX & USART_BRGH_LOW, 51);


	while(1) {
		delay1s();
		printf("ping! %li\n", i);
		i++;
	}	
}

Here’s the project itself: Click to Download

5 comments:

  1. Fun stuff, but you lost your #include statements. Nice blog, BTW. I added you to my blogroll. http://mchpjasonk.blogspot.com/

    ReplyDelete
  2. The full source (including valid include statements) is in the download link.

    Thanks!

    Added your blog as well!

    ReplyDelete
  3. Just replace all "<" in your code by "<", they will appear as "<".

    ReplyDelete
  4. OK, I will try again: Just replace all "<" by "&lt;", they will appear as "<".

    ReplyDelete
  5. Thanks. I'll not forget that next time.

    ReplyDelete