17.02.2015 Views

CCS C Compiler Manual PCB / PCM / PCH

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

#include <br />

#endif<br />

#use delay(clock=20000000)<br />

#use rs232(baud=9600, xmit=PIN_A3, rcv=PIN_A2)<br />

main() {<br />

printf("Press any key to begin\n\r");<br />

getc();<br />

printf("1 khz signal activated\n\r");<br />

while (TRUE) {<br />

output_high (PIN_B0);<br />

delay_us(500);<br />

output_low(PIN_B0);<br />

delay_us(500);<br />

}<br />

}<br />

/////////////////////////////////////////////////////////////////<br />

/// EX_STWT.C ///<br />

/// This program uses the RTCC (timer0) and interrupts ///<br />

/// to keep a real time seconds counter. A simple stop ///<br />

/// watch function is then implemented. Configure the ///<br />

/// <strong>CCS</strong> prototype card as follows, insert jumpers from: ///<br />

/// 11 to 17 and 12 to 18. ///<br />

/////////////////////////////////////////////////////////////////<br />

#include <br />

#use delay (clock=20000000)<br />

#use rs232(baud=9600, xmit=PIN_A3, rcv=PIN_A2_<br />

#define INTS_PER_SECOND 76 //(20000000/(4*256*256))<br />

byte seconds;<br />

//Number of interrupts left<br />

//before a second has elapsed<br />

#int_rtcc<br />

clock_isr() {<br />

//This function is called<br />

//every time the RTCC (timer0)<br />

//overflows (255->0)<br />

//For this program this is apx<br />

//76 times per second.<br />

if(--int_count==0) {<br />

++seconds;<br />

int_count=INTS_PER_SECOND;<br />

}<br />

}<br />

main() {<br />

byte start;<br />

int_count=INTS_PER_SECOND;<br />

set_rtcc(0);<br />

setup_counters (RTCC_INTERNAL, RTCC_DIV_256);<br />

enable_interrupts (INT_RTCC);<br />

enable_interrupts(GLOBAL)<br />

do {<br />

printf ("Press any key to begin. \n\r");<br />

getc();<br />

start=seconds;<br />

printf("Press any key to stop. \n\r");<br />

getc();<br />

printf ("%u seconds. \n\r", seconds-start);<br />

} while (TRUE);<br />

}<br />

/////////////////////////////////////////////////////////////////<br />

/// EX_INTEE.C ///<br />

/// This program will read and write to the ’83 or ’84 ///<br />

/// internal EEPROM. Configure the <strong>CCS</strong> prototype card as ///<br />

/// follows: insert jumpers from 11 to 17 and 12 to 18. ///<br />

382

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!