Electronic Projects, forums and more.

Go Back   Electronic Circuits Projects Diagrams Free > Electronics Categories > Micro Controllers


Micro Controllers Discuss all aspects of micro controllers - building them, coding them, etc. All controllers are welcome - PIC, BASIC, Z8 Encore!, etc.

Reply
 
Thread Tools Display Modes
Old 27th February 2008, 12:40 AM   (permalink)
Default So...I have my junebug....and Im totally lost

I got my junebug today (really fast shipping by the way ) and I downloaded MPLAB IDE, PICkit 2, swordfish and a ton of other stuff...When first plugged in it flashed the LED's from left to right forever but I somehow "programmed" it to stop doing that while tripping down the cavernous menus in MPLAB. Ive looked everywhere for tutorials like: Get a junebug, download this and that...now open this and put this here...do this to program the PIC...now you should see this happening.

I thought this type of info would be included with a tutor. I need to get it to do something from A to Z so I at least get the order and process down. Then I can worry about making changes and testing. Ive looked at tutorials and read a ton of info but never having programmed anything Im totally lost. If there are any sites specifically for the junebug (I've searched but nothing comes up). Maybe a good start would be to help me get the original LED flashing code back on the PIC.

I know all you old hats get tired of the new guys but I need some help. THANKS!
strokedmaro is offline   Reply With Quote
Old 27th February 2008, 12:44 AM   (permalink)
Default

Well the LED flashing demo is in the back of the manual. There is a large 88 page MPLAB manual, and for quick Swordfish BASIC SE might be a good place to start (free SE version works great on the Junebug) There are lots of examples here too, just search for Junebug.
Also the PICkit2 demo board manuals are a good start but you'll have to modify the programs for the 18F part.
PS the Inchworm quick project poster might help, it applies to the Junebug too.

I'd be happy to help.
__________________
Bill
Smart Kits build Smart People

http://www.blueroomelectronics.com
blueroomelectronics is offline   Reply With Quote
Old 27th February 2008, 01:44 AM   (permalink)
Default

Maybe I'm a little out of my league....I have the manuals and I know the demo is in the manual but I have no Idea with what program in what order it takes to get it back on the PIC. Before buying the junebug I read the student guide from Parallax called "whats a micro controller" and it was very informative. Thats the first time I started understand what was going on and it was broken down into easy steps with good explanations.

I guess I will keep reading but what would you suggest I start with? Tell me what to read first and I will start there.
strokedmaro is offline   Reply With Quote
Old 27th February 2008, 02:03 AM   (permalink)
Default Programming 001

If you are totally new to programming, you have jumped into the deep end of the ocean, complete with sharks.

So, if that is so, climb out of the ocean and start in the beginners pool. As Bill says, begin with Swordfish Basic and work on blinking LEDs. Everyone in PICland, etc kinda starts there. Basic kinda takes care of lots of things for you. Pic assembler is kinda strange because of "bank switching, etc".

1) Write / Copy a simple Swordfish Basic program that turns on an LED and waits around for a second or so. Turn it off. Wait for a second or so, go back to the top. The specs for the 18F1320 can be helpful (once you have stared at it for a long time and understand what Bill hooked up to what.

2) The Pickit 2 software (obtained from MicroChip's web site) will allow you to take the .hex file and write it into the 18F1320 onboard the Junebug using the other part of the Junebug (the programmer)

3) The check box on the programmer on the right that says Vdd Pickit On will power the pic and start it running.

4) Led should blink, but mileage may vary depending on you program.

5) Begin pulling hair out when it all isn't exactly like it is supposed to be.


Yes, I have been programming a LONG time. But have only been doing PICs about 6 months.

__________________
August Treubig
AG5AT
August Treubig is online now   Reply With Quote
Old 27th February 2008, 02:41 AM   (permalink)
Default

Quote:
Originally Posted by August Treubig
Pic assembler is kinda strange because of "bank switching, etc"
There's no bank switching to worry about with the 18F1320 on the Junebug tutor. 18F's are much less "strange" than the 16F's.
__________________
=========================
Futz's Microcontrollers & Robotics
=========================
futz is online now   Reply With Quote
Old 27th February 2008, 03:01 AM   (permalink)
Default

Then try Swordfish BASIC SE, it has everything you need to get your feet wet. I've got a small LED module written for the Junebugs tutor.
The very simple blink program
Code:
{
*****************************************************************************
*  Name    : BLINK_1.BAS                                                   *
*  Author  : William Richardson                                             *
*  Notice  : Copyright (c) 2008 blueroomelectronics                         *
*          : All Rights Reserved                                            *
*  Date    : 1/7/2008                                                       *
*  Version : 1.0                                                            *
*  Notes   :                                                                *
*          :                                                                *
*****************************************************************************
}
Device = 18F1320
Clock = 4               // 4MHz clock
Include "junebug.bas"
Dim Count As Byte
While True
    For Count = 0 To 6
        LED(Count)
    DelayMS(300)        // delay in 1000s of a second
    Next
Wend        // repeat forever
End
And the Junebug module
Code:
{
*****************************************************************************
*  Name    : JUNEBUG.BAS                                                    *
*  Author  : William Richardson                                             *
*  Notice  : Copyright (c) 2008 blueroomelectronics                         *
*          : All Rights Reserved                                            *
*  Date    : 2/1/2008                                                       *
*  Version : 0.92beta                                                            *
*  Notes   :                                                                *
*          :                                                                *
*****************************************************************************
}

Module Junebug
Device  = 18F1320
Public Sub LED(x As Byte)
  Select x
    Case 1      // LED 1
    TRISA.7 = 1
    High(PORTA.0)
    Low (PORTA.6) 
    Case 2      // LED 2
    TRISA.7 = 1
    Low (PORTA.0)
    High(PORTA.6)      
    Case 3      // LED 3
    TRISA.0 = 1
    High(PORTA.6)
    Low (PORTA.7)      
    Case 4      // LED 4
    TRISA.0 = 1
    Low (PORTA.6)
    High(PORTA.7)      
    Case 5      // LED 5
    TRISA.6 = 1
    Low (PORTA.0)
    High(PORTA.7)      
    Case 6      // LED 6
    TRISA.6 = 1
    High(PORTA.0)
    Low (PORTA.7)      
  Else          // All LEDs Off 
    TRISA.0 = 1
    TRISA.6 = 1
    TRISA.7 = 1
  End Select
End Sub
Config OSC = INTIO2, WDT = OFF, LVP = OFF
ADCON1  = %11110101

OSCCON = $62            // 4 MHz clock
__________________
Bill
Smart Kits build Smart People

http://www.blueroomelectronics.com
blueroomelectronics is offline   Reply With Quote
Old 27th February 2008, 03:09 AM   (permalink)
Cool Upon some review

It appears that with a bit of work, you can get Swordfish integrated into MPLAB. This can make the writting of the program into the pic a bit simpler. (One stop shopping).

Futz, everything about PIC assembler is weird. But then all my assembler (and there's tons of it is mostly on BIG iron). RISC stuff is better done in a "higher" language.

__________________
August Treubig
AG5AT
August Treubig is online now   Reply With Quote
Old 27th February 2008, 03:15 AM   (permalink)
Default

Since Swordfish does not support the debugger and it has an excellent IDE...

Here's what you need.
The PK2CMD.EXE from Microchip
(Swordfish programmer executeable)
then enter
/PPIC$target-device$ /F$long-hex-filename$ /M /R /H2
in the parameter window
__________________
Bill
Smart Kits build Smart People

http://www.blueroomelectronics.com

Last edited by blueroomelectronics; 27th February 2008 at 03:18 AM.
blueroomelectronics is offline   Reply With Quote
Old 27th February 2008, 04:00 AM   (permalink)
Default

Quote:
Originally Posted by August Treubig
Futz, everything about PIC assembler is weird.
I have to somewhat agree. Their asm is a bit funky. But it's not SO terribly different from other assembly languages that I wasn't able to pick it up pretty quickly (coming from mostly Motorola assembly language background).

Quote:
RISC stuff is better done in a "higher" language.
Not for me. I love assembler.
__________________
=========================
Futz's Microcontrollers & Robotics
=========================
futz is online now   Reply With Quote
Old 27th February 2008, 04:56 AM   (permalink)
3v0
Default

This a C18 Junebug program written by one of the students I tutor. I am not saying she started from scratch or wrote it without guidance. She does however understand what each line does. Not bad for 12.

Create a procject with the the MCC18 compiler (free from microchip). This code will be your main.c, add the linker and header file then build, program and run. Also works with the debugger
Code:
// *** C18 Junebug 18F1320 LED 
// 
// THIS PROGRAM MAKE TWO LEDs WALK ACROSS THE JUNEBUG AND BACK
// NOTE: Project requires a linker scrpt.
// Add either 18f1320i.lkr (for debug) or 18f1320.lkr (no debug) to your project.
//
// BY RHIANNON 

#pragma	config OSC = INTIO2, WDT = OFF, LVP = OFF, DEBUG = ON
#include <p18f1320.h>

#define byte unsigned short
#define LED_ON_FOR 50    


const byte valA[] = {0b00000001,0b01000000,0b01000000,0b10000000,0b10000000,0b00000001}; 
const byte dirA[] = {0b10111110,0b10111110,0b00111111,0b00111111,0b01111110,0b01111110};

void lightTwo(int first)
{
  int onCount,blinky;
  
  for(onCount=0; onCount<LED_ON_FOR; onCount++)
  {
    for(blinky=first; blinky<(first+2); blinky++)
    {
      LATA=valA[blinky];
      TRISA=dirA[blinky];
    }
  } 
}  
               
void main(void)
{
  int idx;

  for(idx=0;idx<5;idx++)   
  {
    lightTwo(idx);  
  }  
  
  for(idx=3;idx>0;idx--)
  {
    lightTwo(idx);
  }  
}
EDIT: To understand the program you need to study the charlie plexed leds on the junebug schematic.
3v0 is offline   Reply With Quote
Old 27th February 2008, 06:20 AM   (permalink)
Default

Quote:
Originally Posted by strokedmaro
Maybe I'm a little out of my league....I have the manuals and I know the demo is in the manual but I have no Idea with what program in what order it takes to get it back on the PIC. Before buying the junebug I read the student guide from Parallax called "whats a micro controller" and it was very informative. Thats the first time I started understand what was going on and it was broken down into easy steps with good explanations.

I guess I will keep reading but what would you suggest I start with? Tell me what to read first and I will start there.
You are perfect in your starting by owning JUNEBUG. As you know, there is no shortcut to success. It is by hard work and practice and continued writing, you learn. hope to see your programs posted at the earliest.All the best and start earnestly and don't stop halfway round.
__________________
Regards,
Sarma.
mvs sarma is offline   Reply With Quote
Old 27th February 2008, 02:07 PM   (permalink)
Default

Quote:
Originally Posted by 3v0
This a C18 Junebug program written by one of the students I tutor. I am not saying she started from scratch or wrote it without guidance. She does however understand what each line does. Not bad for 12.
Tell her well done, I'm several times that age and I'm just starting out with C18. I may take a peek at C30 as I can't figure out MPASM30...
__________________
Bill
Smart Kits build Smart People

http://www.blueroomelectronics.com
blueroomelectronics is offline   Reply With Quote
Old 27th February 2008, 03:13 PM   (permalink)
3v0
Default

Quote:
Originally Posted by blueroomelectronics
Tell her well done, I'm several times that age and I'm just starting out with C18. I may take a peek at C30 as I can't figure out MPASM30...
WIll do that. She is great to work with. I showed her how to figure out the constants to light the first two LEDs and she figured out the other 4. It is amazing to me how much kids can absorb it you start with concepts they understand.

The teaching thing limits the time I have to mess with other things I want to do. Playing with the 24 and 30 fall into that basket. that and doing SMD boards Maybe this summer.

C30 may be easier to use then MCC18.
3v0 is offline   Reply With Quote
Old 28th February 2008, 12:10 AM   (permalink)
Talking Yay!

Quote:
Originally Posted by blueroomelectronics
Then try Swordfish BASIC SE, it has everything you need to get your feet wet. I've got a small LED module written for the Junebugs tutor.
The very simple blink program
Code:
{
*****************************************************************************
*  Name    : BLINK_1.BAS                                                   *
*  Author  : William Richardson                                             *
*  Notice  : Copyright (c) 2008 blueroomelectronics                         *
*          : All Rights Reserved                                            *
*  Date    : 1/7/2008                                                       *
*  Version : 1.0                                                            *
*  Notes   :                                                                *
*          :                                                                *
*****************************************************************************
}
Device = 18F1320
Clock = 4               // 4MHz clock
Include "junebug.bas"
Dim Count As Byte
While True
    For Count = 0 To 6
        LED(Count)
    DelayMS(300)        // delay in 1000s of a second
    Next
Wend        // repeat forever
End
And the Junebug module
Code:
{
*****************************************************************************
*  Name    : JUNEBUG.BAS                                                    *
*  Author  : William Richardson                                             *
*  Notice  : Copyright (c) 2008 blueroomelectronics                         *
*          : All Rights Reserved                                            *
*  Date    : 2/1/2008                                                       *
*  Version : 0.92beta                                                            *
*  Notes   :                                                                *
*          :                                                                *
*****************************************************************************
}

Module Junebug
Device  = 18F1320
Public Sub LED(x As Byte)
  Select x
    Case 1      // LED 1
    TRISA.7 = 1
    High(PORTA.0)
    Low (PORTA.6) 
    Case 2      // LED 2
    TRISA.7 = 1
    Low (PORTA.0)
    High(PORTA.6)      
    Case 3      // LED 3
    TRISA.0 = 1
    High(PORTA.6)
    Low (PORTA.7)      
    Case 4      // LED 4
    TRISA.0 = 1
    Low (PORTA.6)
    High(PORTA.7)      
    Case 5      // LED 5
    TRISA.6 = 1
    Low (PORTA.0)
    High(PORTA.7)      
    Case 6      // LED 6
    TRISA.6 = 1
    High(PORTA.0)
    Low (PORTA.7)      
  Else          // All LEDs Off 
    TRISA.0 = 1
    TRISA.6 = 1
    TRISA.7 = 1
  End Select
End Sub
Config OSC = INTIO2, WDT = OFF, LVP = OFF
ADCON1  = %11110101

OSCCON = $62            // 4 MHz clock
I don't know how it works yet, but I was able to get it blinking the way it did before by copying and pasting what you've listed here! I guess you could say that this is my first success at programming a PIC! At least I know the order of things now. Thanks for re-sparking my interest!!!

EDIT: a little copying and pasting in swordfish and Ive been able to get the LED's to flash in any order! Now I'm having a little fun! I still don't understand the software behind it but I at least am able to get something working which helps tremendously!

blueroomelectronics: thank you...now to find/figure out how to incorporate the buttons! Than should help me understand a little more!

Last edited by strokedmaro; 28th February 2008 at 12:50 AM.
strokedmaro is offline   Reply With Quote
Old 28th February 2008, 02:22 AM   (permalink)
Talking Avoiding the Sharks

Well,

You have avoided the sharks and the deep dark holes on the first go round. Now you have a success and have a project saved that works. So you were able to:

1) get something to compile without errors. (copying it or not, sometimes that is a milestone).

2) Successfully program the PIC (Bill makes that fairly easy with the onboard 18F1320). But sometimes simple things can be challenging..

3) Ran the sample and watched the pretty blinking lights. (Nothing like being a success).

You have the idea behind the process down. Things like LCDs, and others can also make for fun.

Drive on, and ask as many questions as required.

__________________
August Treubig
AG5AT
August Treubig is online now   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes




All times are GMT. The time now is 02:40 PM.


Electronic Circuits  |  Electronics Wiki
Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.