Code:
/*******************************************************/
/*
/* EE400 - Interface Assignment 1 - Hello World
/* Group 27
/* November 13, 2007
/*
/********************************************************/
#include <p30f4011.h>
#include <p30fxxxx.h>
/**********************/
/* CONFIGURATION BITS
/**********************/
_FOSC(CSW_FSCM_OFF & FRC); //use internal fast RC oscillator
_FWDT(WDT_OFF); //disable WDT
_FBORPOR(PBOR_OFF); //disable brownout
_FGS(CODE_PROT_OFF); //disable code protection
int main()
{
/******************/
/* CONFIGURE UART
/******************/
U2MODE = 0b1000000000000000; //Enable UART2, 8-bit, no-parity, stop bit, everything else disabled
//U2BRG = 0x002F; //set baud rate to 9600bps at 7.37MHz (FRC oscillator)
U2BRG = 47; //set baud rate to 9600bps at 7.37MHz (FRC oscillator)
/*********************/
/* MAIN PROGRAM LOOP
/*********************/
char Message[] = " Hello World!"; //string to be sent over UART
int n;
do
{
for(n = 0; Message[n] != '!'; n++)
{
while(U2STAbits.UTXBF==1); //make sure TX buffer not full before loading in more data
U2TXREG=Message[n++]; //load next character into TX buffer and increment character counter
}
} while(1); //repeat sending "Hello World" over UART forever
return(0);
}
I got this simple little Hello World code for a dsPIC30F4011 that is supposed to be written in C which I've never done before so some of the definitions and defines in the header files seem a bit strange to me. It's also been 4 year since I've coded any C and I can't test it tonight, but it is due at the end of the lab tommorrow and it'd be nice if someone could see if they can't catch a glaring error in it.
THanks.
Last edited: