User Tools

Site Tools


project:usb:code:hello_world

Hello World!

For those having trouble getting started on their projects, here is a copy of a “Hello World!” program to test your RS232 serial link is working reliably. Then run, your PIC16F877 will blink an LED and print “Hello World!” once a second forever.

Connect the LED to pin B7, and make sure it lights when the PIC pulls it low.

Set your (virtual) terminal to:

Mode ANSI
Baudrate 9600
Bits 7
Parity Even
Stop bits 1

Download compiled HEX firmware

#include <16f877.h>
#include <ctype.h>
 
//--------------------------------------------------------
// Setup PIC and CCS compiler
#fuses XT, PUT, NOWDT, NOPROTECT
#use delay(clock = 4000000)
 
#use rs232(baud = 9600, xmit = PIN_C6, rcv = PIN_C7)
// By using C6 and C7, we will make use of the 877's hardware USART abilities
 
#use standard_io(b)
#byte port_d = 8
 
//--------------------------------------------------------
// Definitions
#define ON				1
#define OFF				0
 
#define LED_N PIN_B7
 
//--------------------------------------------------------
// Entry point
void main(void){
	short debug = ON;
 
	output_low(LED_N);	// Turn on the yellow LED
 
	while(debug)
	{
		printf("Hello World!\r\n");
		delay_ms(1000);
		output_toggle(LED_N);	// Yellow LED
	}
}
project/usb/code/hello_world.txt · Last modified: 2007/04/27 01:21 (external edit)