Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

dsPIC30F4013 start

Status
Not open for further replies.

AtomSoft

Well-Known Member
Hey all i got a couple of these dsPIC30F4013 micros and would love some help here lol

I know so far that i need some type of startup.s file. But have no clue where to get them or how to make one. At least a link on how they work would rock!

I have that C30 from Microchip and will look closely at the help file but if anyone has a C30 "Flash/Blink LED" type of demo.

I have seen a demo for other chips from the dsPICDEM 2 examples but none fit in.

So any help would be awesome!
 
Hey all i got a couple of these dsPIC30F4013 micros and would love some help here lol

I know so far that i need some type of startup.s file. But have no clue where to get them or how to make one. At least a link on how they work would rock!

I have that C30 from Microchip and will look closely at the help file but if anyone has a C30 "Flash/Blink LED" type of demo.

I have seen a demo for other chips from the dsPICDEM 2 examples but none fit in.

So any help would be awesome!
When I programmed my 4013 in C30 I never even knew there was a startup.s. I'm pretty sure you don't need to worry about it. I think the compiler handles all that stuff for you automatically.

I'll dig around for some of my first little programs for it.
 
ok cool thanks. I have something that seems to be compiling now i need to set these config bits.
The configs are like 18F bits. There's tons of em! :p

Here's my first crappy blinky program for 30F4013. Don't laugh. Hadda start somewhere. I was just beginning C again after something like a 8 year break from it.
Code:
#include "p30f4013.h"
int delay(void);

_FOSC(FRC_PLL16)            //osc
_FWDT(WDT_OFF)
_FBORPOR(MCLR_EN & PWRT_OFF)//MCLR enable & power-up timers off
_FGS(CODE_PROT_OFF)         //Code Protection off

int main(void)
{
    TRISB = 0;          //PORTB all outputs
    while(1)
    {
        LATBbits.LATB0=1;
        delay();
        LATBbits.LATB0=0;
        delay();
        LATBbits.LATB5=1;
        delay();
        LATBbits.LATB5=0;
        delay();
        LATBbits.LATB1=1;
        delay();
        LATBbits.LATB1=0;
        delay();
        LATBbits.LATB4=1;
        delay();
        LATBbits.LATB4=0;
        delay();
        LATBbits.LATB2=1;
        delay();
        LATBbits.LATB2=0;
        delay();
        LATBbits.LATB3=1;
        delay();
        LATBbits.LATB3=0;
        delay();
    }
    return 0;
}

int delay(void)
{
    int var1,var2;
    for(var1=0;var1!=10;var1++)
        for(var2=0;var2!=10000;var2++);
    return 0;
}

And here's some fairly lame 4-bit LCD busy-check code. It has some dumb newb things and errors, but it works.
Code:
#include "p30f4013.h"

_FOSC(FRC)                      //osc
_FWDT(WDT_OFF)
_FBORPOR(MCLR_EN & PWRT_OFF)    //MCLR enable & power-up timers off
_FGS(CODE_PROT_OFF)             //Code Protection off

void lcd_line1(void);           //function prototypes
void lcd_line2(void);
void lcd_cmd(unsigned char);
void lcd_char(char);
void e_togg(void);
void lcd_init(void);
void lcd_string();
void lcd_busy(void);

char sentence[16] = "dsPIC 30F4013";
char *senpoint = sentence;

#define	E           LATDbits.LATD9
#define	RS          LATAbits.LATA11
#define RW          LATCbits.LATC14
#define	busyflag    PORTBbits.RB12
#define RW_TrisBit  TRISCbits.TRISC14
#define D7_TrisBit  TRISBbits.TRISB12

int main(void)
{
    ADPCFG = 0xffff;            //all digital
    TRISA = 0;                  //PORTs all outputs
    TRISB = 0;
    TRISC = 0;
    TRISD = 0;
    RW = 0;                     //set R/W low
    E = 0;                      //set E low
//  lcd_busy();                 //wait for LCD to settle
//  lcd_init();
    lcd_string();               //send string to LCD
    while(1);                   //spin forever
    return 0;
}

void lcd_string(void)
{
    while(*senpoint != '\0')
    {
        lcd_char(*senpoint);
        senpoint++;
    }
}	

void lcd_busy(void)
{
    RW_TrisBit = 1;         //make R/W input (read)
    D7_TrisBit = 1;         //make D7 input
    RS = 0;                 //set RS low
    RW = 1;                 //set R/W high
    E = 1;                  //set E high
    while(busyflag);        //wait for busy flag to go low
    E = 0;                  //set E low
    RW = 0;                 //set R/W low
    TRISB = 0;              //make D7 output
    RW_TrisBit = 0;         //make R/W output (write)
}	
	
void lcd_line1(void)
{
    lcd_cmd(0x80);
}

void lcd_line2(void)
{
    lcd_cmd(0xc0);
}		

void lcd_cmd(unsigned char letter)
{
    LATB = letter;          //put char in PORTB
    lcd_busy();
    PORTB = PORTB << 5;     //shift over to output high 4 bits on RB9,10,11,12
    RS = 0;                 //RS low
    e_togg();               //latch the data
    PORTB = PORTB << 4;     //shift over to output low 4 bits
    RS = 0;                 //RS low
    e_togg();               //latch it
}

void lcd_char(char letter)
{
    LATB = letter;          //put char in PORTB
    lcd_busy();
    PORTB = PORTB << 5;     //shift over to output high 4 bits on RB9,10,11,12
    RS = 1;                 //RS high
    e_togg();               //latch the data
    PORTB = PORTB << 4;     //shift over to output low 4 bits
    RS = 1;                 //RS high
    e_togg();               //latch it
}

void lcd_init(void)
{
    LATB = 0x0600;          //send 3
    e_togg();
    lcd_busy();
    LATB = 0x0600;
    e_togg();
    lcd_busy();
    LATB = 0x0600;
    e_togg();
    lcd_busy();
    LATB = 0x0400;          //send 2 - set 4-bit mode
    e_togg();
    lcd_busy();
    lcd_cmd(0x28);          //set 4-bit mode and 2 lines
    lcd_busy();
    lcd_cmd(0x10);          //cursor move & shift left
    lcd_busy();
    lcd_cmd(0x06);          //entry mode = increment
    lcd_busy();
    lcd_cmd(0x0d);          //display on - cursor blink on
    lcd_busy();
    lcd_cmd(0x01);          //clear display
    lcd_busy();
}

void e_togg(void)
{
    E=1;
    E=0;
}
 
Last edited:
THanks!

OK the only issue im having now (or so it seems) is the FOSC setting im using 20Mhz since its all i have. How would i set it?

I tried:
Code:
_FOSC(CSW_FSCM_OFF & HS);
_FWDT(WDT_OFF)
_FBORPOR(MCLR_EN & PWRT_OFF)  
_FGS(CODE_PROT_OFF)

If this is correct then its something else.
 
OK the only issue im having now (or so it seems) is the FOSC setting im using 20Mhz since its all i have. How would i set it?
You're using a 20MHz crystal? I think you'd use
Code:
_FOSC(HS)
to use it with no PLL.

But why? You can use the 7.37MHz internal with PLL to get 118MHz out of it. Easier by far unless you need precision.
 
Last edited:
I took out the 20mhz and am trying the below blinking but no luck :(
Code:
#include "p30F4013.h"

_FOSC(FRC_PLL4);
_FWDT(WDT_OFF)
_FBORPOR(MCLR_EN & PWRT_OFF)  
_FGS(CODE_PROT_OFF)    
int main(void)
{
	int x;
	int y;
	y = 5000000;  //[b]I tried anywhere from 500-500000[/b]

    TRISB = 0x00;
    LATB = 0x00;

    while(1)
    {
        LATBbits.LATB0 = 1;

		for(x=0;x<y;x++)
			TRISA = 0;

        LATBbits.LATB0 = 0;
    }
}
 
MPLAB Sim registers this at 1.15sec
Code:
#include "p30F4013.h"

_FOSC(FRC_PLL4);
_FWDT(WDT_OFF)
_FBORPOR(MCLR_EN & PWRT_OFF)  
_FGS(CODE_PROT_OFF)    
int main(void)
{
	int x;
	int y;
	int z;
	y = 999999;  //[b]I tried anywhere from 500-500000[/b]

	ADPCFG = 0xffff;		//all digital
    TRISB = 0;
    LATB = 0;

    while(1)
    {
        LATBbits.LATB0 = 1;

		for(z=0;z<50;z++)
			for(x=0;x<y;x++)
				TRISA = 0;

        LATBbits.LATB0 = 0;
    }
}

Since its a 7.37Mhz * 4 would i set the MHZ in the stopwatch to: 29.48 (this is what i did) is it correct?
 
Last edited:
I see your problem. You're only delaying after setting the pin high, but not after setting it low. You probably have your LED wired with cathode to the pin, right? The LED will appear to be off all the time. If you wired it the other way it would appear to be on all the time.

Try this (your code modified a bit - and working).
Code:
#include "p30F4013.h"
void delay(void);

_FOSC(FRC_PLL4)
_FWDT(WDT_OFF)
_FBORPOR(MCLR_EN & PWRT_OFF)  
_FGS(CODE_PROT_OFF)

int main(void)
{
    TRISB = 0;

    while(1)
    {
        LATBbits.LATB0 = 1;
        delay();
        LATBbits.LATB0 = 0;
        delay();
    }
}

void delay(void)
{
    int x,y;
    for(x=0;x<10;x++)
        for(y=0;y<10000;y++);
    return 0;
}
 
Last edited:
YAY!!!!!!!!!!!!! Blinking... it had to be something as small as delaying more lol
Both mines and your code works fine now!

Thanks buddy. Im playing with these higher end pics for fun till i get my LPC Olimex board. Should be soon. Im going to wait till the tiny gets in stock which is very soon i think.
 
Last edited:
what do you mean bootload my code?
All the LPC2000 line have a bootloader built-in. You connect UART0 to your computer with a serial cable. To enable the bootloader, switch a dip-switch or move a jumper, hit reset and program with Flash Magic (or other program). Then put the switch/jumper back, hit reset and your program runs. Easy.

These pics look like they can reach a nice speed....
The 30F4013 is rated to 120MHz.
 
awesome. I doubt ill use the bootloader untill i learn it some more. And i wont ever use it on a demo board except for practice/learning i will definitely use it tho :D. It will make updating my board simple if i release like firmware updates. but then if its something that others use alot it might get hacked easy. :D like i hear alot of people hacking alot of things from modems to PSPs to zunes to do what they want and thats mainly because of the bootloader i would argue. Since they can get your update they can alter it and upload it. Now if it was a reprogramming then they couldnt but then again to have a huge amount of people come into a store to update a psp or zune would suck!!
 
but then if its something that others use alot it might get hacked easy. :D like i hear alot of people hacking a lot of things from modems to PSPs to zunes to do what they want and thats mainly because of the bootloader i would argue. Since they can get your update they can alter it and upload it. Now if it was a reprogramming then they couldnt but then again to have a huge amount of people come into a store to update a psp or zune would suck!!
What's wrong with hacking stuff? I would argue that hackable electronics are a very good thing. 99% of people don't have the chops or the inclination to do it, but that 1% gets great entertainment out of tinkering with things. The more hackable the better. :p

You think PSPs and Zunes run LPCs? They don't. PSP uses a MIPS R4000, and Zune has a Freescale **broken link removed**. No bootloaders mentioned in either datasheet.
 
for those 2 i was actually reffering to Firmware. They both are hackable due to firmware upgrades. The Modem i was refering to is the SurfBoard by motorola. The SB5100 and some others use a JTAG. They have bootloaders.

You have to remember just becuase a bootloader is not in the datasheet doesnt mean it doesnt have one.

There is no bootloader on most PICs but people tend to create software bootloaders. As long as your PIC has that self programming feature.

From the ZUNE (iMX31L) data sheet: (PAGE 5)
"There is also a 32-KB ROM for bootstrap code and other frequently-used
code and data.

A ROM patch module provides the ability to patch the internal ROM. It can
also initiate and external boot by overriding the boot reset sequence
by a jump to a configurable address."

To me thats kinda a bootloader. But it doesnt matter because im sure someone can most likely just hack it anyway whether it had a bootloader or not :D
 
Last edited:
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top