Welcome to ...

Electric Chili is all about electronics, personal finance, life, hybrid vehicles, and of course chili. Why is your blog about so many things? Well, I used to have several blogs and I found I couldn't keep up with all of them. The maintenance began to take the fun out of it. So now I'm putting everything right here!

Archives for the PIC Stuff category

December 8, 2007

PWM for the PIC18F1330

Here’s a little example code for the PIC18F1330 that generates 3 different PWM signals.  It’s done with MPLAB and HI-Tech’s PICC-Lite compliler.  It’s probably a little over done in that I wanted to be able to just enter a decimal value for each of the duty cycles.  That resulted in some code that is a little memory intensive.

Logic Trace of PWM’s

I just picked up the CCS compiler and my understanding is that the CCS libraries will allow me to do a little more with less.  I plan on writing some code for comparison.  I’ll post it when I’m finished.

First, here’s the configuration …put this in a separate file called configuration-word.h.

configuration-word.h

Here’s the Main loop…

main.c

You’ll see wnen you examine it that I should have put some of the code into functions.  That would have helped it’s size conserably.  Oh well, maybe another time.

Rich Dennison

Hello World for the PIC16F690

If you’ve purchased a PICkit 2 from Microchip you’re probably anxious to get started.  I believe the kit comes with the assembly code to blink the LED’s on the board.  Well, that’s great for assembly programmers but what about those of us who prefer C.  Below is a few lines of code that works with the PICkit 2 using the free Hi-Tech PICC-Lite compiler and the PIC16F690.

PICKit 2

 __CONFIG(FCMEN & IESODIS & BORDIS & UNPROTECT & MCLRDIS & PWRTEN & WDTDIS & INTIO & INTCLK);
int i;
int j;
main()
{
    PORTC = 0;
    TRISC0 = 0;
    TRISC1 = 0;
    TRISC2 = 0;
 TRISC3 = 0;
 OSCCON = 0b01100111;
 
  while (j<3)
    {
        for (i = 0; i < 5500; i++);
        RC0 = 0;
        for (i = 0; i < 5500; i++);
        RC0 = 1;
        for (i = 0; i < 5500; i++);
        RC1 = 0;
        for (i = 0; i < 5500; i++);
        RC1 = 1;
        for (i = 0; i < 5500; i++);
        RC2 = 0;
        for (i = 0; i < 5500; i++);
        RC2 = 1;
  for (i = 0; i < 5500; i++);
        RC3 = 0;
  for (i = 0; i < 5500; i++);
        RC3 = 1;
     for (i = 0; i < 5500; i++);
        RC2 = 0;
        for (i = 0; i < 5500; i++);
        RC2 = 1;
        for (i = 0; i < 5500; i++);
        RC1 = 0;
        for (i = 0; i < 5500; i++);
        RC1 = 1;
       j=j+1;
 }

 j=0;
 while (j<5)
    {
        for (i = 0; i < 8500; i++);
        PORTC=0b001001;
  for (i = 0; i < 8500; i++);
        PORTC=0b000110;
  for (i = 0; i < 8500; i++);
        PORTC=0b001001;
  for (i = 0; i < 8500; i++);
        PORTC=0b000110;
  j=j+1;
    }

Powered by WordPress and Giveaway of the Day.