Wednesday, March 17, 2010

dsPIC30F3012 hello world program

The next program flashes a LED connected in the PB0 (pin 2) of a dsPIC30F3012. The chip is running at 80MHz using a crystal of 20MHz. The PLL multiplies the half of the crystal frequency by 8.
In other words:

(20MHz)/2*8=80MHz.
Using the PLL (With a 20MHz xtal, the maximum PLL factor is 8) we are able to use also the UART at 115.2kbps that will be used in the next post when we make a interface with a PC using bluetooth.
The code: As you know, is written in the CCS compiler PCDWH. ver. 4.102.
//Program to flashing a LED connected in the PB0. 
//Xtal speed 20MHz in pin (6-7).
#include <30F3012.h>
#FUSES HS2_PLL8//The xtal freq is divided by 2 and multiplied by 8 (maximum using 20MHz xtal)
#FUSES NOWDT // NO Watch Dog Timer
#FUSES PR_PLL //Primary Oscillator
#FUSES NOCKSFSM //Clock Switching is disabled, fail Safe clock monitor is disabled
#FUSES NOPROTECT //Code not protected from reading
#FUSES NOWRT //Program memory not write protected
void main() {
while (TRUE) {
output_high(PIN_B0);
delay_ms(500);
output_high(PIN_B0);
delay_ms(500);
}
}
NOTE: I've noticed that the directive NOWDT is NOT working when I load the firmware in the dsPIC and then I
LEDdsPIC30F3012
have to disable the FWDTEN bit manually every time I load the firmware in the chip. Otherwise, the chip is reinitialized every few seconds. I already ask to the CCS compiler technical support and I’m waiting for an answer.
The circuit and PCB is below, at the left is a 3D view of the circuit.
Circuit made in eaglever. 5.7.0 ligth


circuito

2 comments:

Anonymous said...

Hello there, I was just looking at the code and was wondering if you managed to fix the problem you were encountering. I am also working on an LED project- but I'm using MPLAB and the 30f2011 compiler.- I am having issues with the header file as i am new to using pic microcontrollers and was just wondering what content I need to have in my header file.

Rigo said...

Hi!
Well, the problem was not in my program, it was in the programmer. But the code as I wrote here is correct.
I understand you are using the MPLAB but the compiler you say is the name of a microcontroller, it is not?

Related Posts Plugin for WordPress, Blogger...