.

#include <pic.h> //Always include pic.h (defines IO pins, etc.)
#include <float.h> //Floating point numbers
#include <math.h> //Math functions

void init_hw(void) //Always initialize hardware for IO directions
{
RP0   = 1;  //set bank 1 for access
TRISB = 0x83;  //Program IO pins for Port B
RBPU  = 0;  //Enable pull up resisters
TRISA = 0xF0;  //Program IO pins for Port A
RP0   = 0;  //re-select bank 0
}

void delay(float x) //Delay function, specify in seconds
{
float i;
float a = 6400;  //scale factor for 1 second delay
for (i=0; i<a*x; i++); //loop to use up time
}

main(void)
{
init_hw(); //initialize the LAB 3X board
RB4 = 1; //Set Port B bit 4 on (LED 1 on)
if (RB7 != 1)  //if port b (bit 7) is logic zero (Switch 1  pushed)
  {  //then alternate the flashing of LED 1 & 2
    RB4 = 0; //LED 1 off 
    RB5 = 1; //LED 2 on
    delay(0.1); //Delay for 0.1 seconds
    RB4 = 1; //LED 1 on
    RB5 = 0; //LED 2 off
    delay(0.1); //Delay for 0.1 seconds
  }
}

Advertisements
This entry was posted in Computers and Internet. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s