A C Program
Links Mentioned
N/A

Links
Home
AWC

 


Home
PIC C Programming
A C Program
Compiling


Here is a simple SDCC program for the APP-II:

#include "app2.h"
#include "app2lib.h"
void main()
{
  unsigned int i;
  unsigned int j=0;
  TRISC=0xF7;
  serialSetup();
  serialSend('\012');  // clear the screen (Hyperterminal)
  serialSend('?');     // Get the starting point
  j=serialRcv();
  while (1) 
    {
      serialSend(++j);
      APP2_LED=1;
      // delay about 1/2 second
      for (i=0;i<10000;i++) delay(255);
      APP2_LED=0;
      for (i=0;i<10000;i++) delay(255);
      if (j>='z') j='A'-1;  // cycle letters from 'z' to 'A'
    }
}

The header files tell the complier about your hardware. The first part of the program sets up the serial port and prompts you to enter a single character (this assumes you have Hyperterminal or something similar connected). Then the program enters a loop. It blinks the LED on the APP-II board at about a half second rate. In addition, it emits characters to the terminal starting with the next letter (so if you entered F, the next letter would be G, then H, and so on). When the character reaches z, the program resets it so that it goes back to A.

Although this program won't win any prizes, it does exercises all of the major APP-II functions. Now, how do you compile this program to a HEX file? That's the subject of the next frame.

Back Home Next