Friday, 20 July 2012

PIC16F887 Hitech C Basic

I thought i'd share this here, as might help someone starting to dive into the PIC architecture.
I always been afraid of PICs compared with AVR, as the learning curve is much higher.
But, thanks to a few friends in a forum ( http://lusorobotica.com ). i lost the fear and even dug deep into Assembler... hmmm, you say !! YES !!
When trying to compile a basic example, i realized that wouldnt allow me to compile unless _XTAL_FREQ 4000000 is #defined.
Chip is PIC16F887 (
44-Pin Demo Board from Microchip, DM164120-2 ), compiler Hitech C Basic in MPLab IDE with a PickIt2 programmer ( i said it all...in one breath ! You know what i mean with PICs being scary, right ?!
, 


#include<htc.h>
#include<pic.h>
#define _XTAL_FREQ 4000000 

//__CONFIG(FOSC_HS|WDTE_OFF|PWRTE_ON|LVP_OFF|DEBUG_OFF);
__CONFIG(FOSC_HS|WDTE_OFF|PWRTE_ON|BOREN_OFF|LVP_OFF|CPD_OFF|WRT_OFF|DEBUG_OFF|CP_OFF);

void main(void)
{
 TRISD=0;

while(1)
 { 
  PORTD=0x01;   //turn on LED at RD0. 
             __delay_ms(100);
             PORTD=0x00;   //turn off LED at RD.
  PORTD=0x02;   //turn on LED at RD1.  
             __delay_ms(100);
  PORTD=0x00;   //turn off LED at RD.
  PORTD=0x04;   //turn on LED at RD2. 
  __delay_ms(100);
 } 
} 

No comments:

Post a Comment

Feel free to contact me with any suggestions, doubts or requests.

Bless