Getting Started

(lily) #1

Chapter 6: C Functions and Program Structures


Save this file as Demonstrator.c.


PC_Comm


The next two programs, PC_Comm.h and PC_Comm.c can be copied from the
CD to the CommDemo directory, or if you want a preview of coming attractions,
you can open a new C/C++ file in Programmer’s Notepad and write:


// PC_Comm.h
#include <avr/io.h>
#include <avr/interrupt.h>
#include <avr/delay.h>


#include <stdlib.h>


#include "Demonstrator.h"


void OSCCAL_calibration(void) ;
void USARTinit(void);
char isCharAvailable(void);
char receiveChar(void);
void sendChar(char ) ;
void sendString(char *);


Save this file as PC_Comm.h.


In Programmer’s Notepad open a new C/C++ file and write:


// PC_Comm.c


#include "PC_Comm.h"


int main(void)
{
char string[64];
unsigned char count = 0;


// run the initialization routine
initializer();


//Begin forever chatting with the PC
for(;;)
{
// Check to see if a character is waiting
if( isCharAvailable() == 1 )
{
// If a new character is received, get it
string[count++] = receiveChar();


// receive a packet up to 64 bytes long

Free download pdf