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.

So...I have my junebug....and Im totally lost

Status
Not open for further replies.
Charliplexing LEDs is a great way to run many LEDs with only a few I/O pins. It's a little tricker than directly driving an LED but since it's a tutor you're bound to learn something. One catch is only ONE LED can be lit at a time, so the trick is called refreshing. Your eyes have persistence of vision and anything flickering faster than about 20ms (50Hz) will not appear to be flickering.
https://en.wikipedia.org/wiki/Charlieplexing
https://www.instructables.com/id/Charlieplexing-LEDs--The-theory/


As wonderful as Swordfish BASIC is (and it makes programming VERY easy) it's not going to give you the insight or release the real power of a PIC. Understanding some PIC assembly code will prove very helpful, and serious users will want C (like the free C18 SE compiler from Microchip)
That said Swordfish BASIC is simply the best PIC BASIC I've ever used by a long shot.
Code:
     Case 1      // LED 1
    TRISA.7 = 1     // This makes the pin an input / high impedance (open)
    High(PORTA.0)  // automatically sets the pin to output and logical high (1)
    Low (PORTA.6)  // automatically sets the pin to output and logical low (0)
The Swordfish forums have lots of code examples.
https://www.sfcompiler.co.uk/forum/
 
sorry lol totally forgot about charliplexing leds. No wounder i couldn't figure it out . Thnx will look at the circuit diagram of the Junebug to make sure i understand more. I have a few 7 Seg displays. 1 single 1 double and 1 quad so charliplexing will have to be learned :D
 
Your code looks fine, I've just added a couple of lines the 18F1320 PIC requires (Config, ADCON1 & OSCCON)

I ran it through the OshonSoft 18F simulator and its 8xLED Board, works great :)

Code:
Device = 18F1320
Clock = 4  // Tells the compiler the PIC speed
Config OSC = INTIO2, WDT = OFF  // Sets the fuses

// alias to port pin...

Dim LEDA as PORTA.0
Dim LEDB as PORTA.1
// main program...
OSCCON = $62  // Set the PIC Osc to 4MHz
ADCON1  = %11111111  // Set all I/O to digital
Low(LEDA)
Low(LEDB)

Repeat
   Toggle (LEDA)
   DelayMS (500)
   Low(LEDA)
   
   Toggle (LEDB)
   DelayMS (500)
   Low(LEDB)   
Until false
End
 
just learning about this stuff is crazy. I know a little of everything lol

i know some Basic, C and ASM.

ASM would be the best i presume (small size wise)

Um.. Got any good links to learning C18 ? I installed and its with the MPLAB IDE now. But need to learn how to code with it some basic samples would do.

Asm is not too hard as it is confusing a bit. Moving to and from the W register without comments would suck. Its tought basically.

Basic is so simple its complex if you understand.
C is almost the same but less complex.
Asm is simple yet fustrating.

So i would like to try more the middle of the 3. So any links would rock!

If all else fails ASM will be my choice
 
Last edited:
for some reason i get:

Code:
Executing: "C:\MCC18\bin\mcc18.exe" -p=18F1320 "main.c" -fo="main.o" -mL -Oa -Ou- -Ot- -Ob- -Op- -Or- -Od- -Opa-
MPLAB C18 v3.16 (demo)
Copyright 1999-2005 Microchip Technology Inc.
Days remaining until demo becomes feature limited:  59
Executing: "C:\MCC18\bin\mplink.exe" /l"C:\MCC18\lib" "C:\mplab\18F1320_Blink\18f13k20.lkr" "C:\mplab\18F1320_Blink\main.o" /w /o"main.cof"
MPLINK 4.16, Linker
Copyright (c) 2008 Microchip Technology Inc.
Error - processor types do not agree across all input files.
Errors    : 1

Link step failed.
BUILD FAILED: Sat Mar 01 00:18:21 2008
 
If you want to throw another language into the mix, try JAL:
http://www.voti.nl/jal/index_1.html
As for learning C, it would help to take a look at an ANSI C tutorial for writing C on the PC first. This will give you a starting point for learning C on the PIC and there are TONS of ANSI C tutorials out there.
A very basic C18 getting started tut:
**broken link removed**
There is also the C18s users guide:
http://ww1.microchip.com/downloads/en/DeviceDoc/C18_User_Guide_51288j.pdf
And if you want to use C18s built in Libraries instead of talking to the hardware yourself:
http://ww1.microchip.com/downloads/en/DeviceDoc/MPLAB_C18_Libraries_51297f.pdf
 
blueroomelectronics said:
I've just started with C18, never needed C before. Hopefully 3V0 will post some code.
Do you want to see code that lights a single LED or code that multiplexes LEDs to light more then one at a time.

I have a series of programs that start with a single LED and end with multiplexing the LEDs using timers. I have posted some of the in the past. Maybe I need to get them collected in one place.
 
just looked at the schematics for Junebug. I think i understand the process of high/low and the how it works. This is cool.

What other BASIC programs can you use to program a pic in (freeware would be nice) :D just that as it being a hobby mostly im not trying to spend $150 to buy this program. I could buy a Junebug + Inchworm + Firefly for that price almost.
 
Last edited:
AtomSoft said:
just looked at the schematics for Junebug. I think i understand the process of high/low and the how it works. This is cool.

What other BASIC programs can you use to program a pic in (freeware would be nice) :D just that as it being a hobby mostly im not trying to spend $150 to buy this program. I could buy a Junebug + Inchworm + Firefly for that price almost.
The Swordfish demo is pretty good as long as you don't use floats and do any string manipulation yourself. The Keyread and flash lights code above uses 39 bytes of ram, the demo allows upto 256 bytes.

Mike.
 
I Assumed that since it was a dead on match lol

I havent seen any basic examples like a how to. Some things newcomers might need/want to know.

1. How to set (a) single/multiple port(s) to Input or Output.
A.TRISA.7 = 1 ( This would set pin 7 on PortA to Input / 0 would be output)

2. How to set a Pin High(on)/Low(off)
A. High(PORTA.0) / Low (PORTA.0) // Set Pin 0 HIGH/LOW

3. This code below sets pins 0, 6 and 7 to inputs (used as a big off(low) i think)
TRISA.0 = 1
TRISA.6 = 1
TRISA.7 = 1


My questions are:
1. Is the above correct?
2. INTCON2.7=0 //What exactly does this do? (interrupt maybe? or PortB something?)
3. Config OSC = INTIO2, WDT = OFF, LVP = OFF
4. ADCON1 = %11110101 // Sets what to digital PortA ? How is this layed out like pin to digit?
5. OSCCON = $62 // 4 MHZ // But How is $62 = 4 MHZ ?
6. Maybe i missed something but what sets PortB as inputs ? in the module?


I know i ask alot of questions but its only to learn as not to be confused once i get my junebug.
 
Last edited:
1. no, TRIS simply sets the direction of the port (In = 1, Out = 0)
1a. LAT sets it high or low (so does PORT but LAT is better)
1b. PORT is used for reading the state of an input pin
2. INTCON2.7 should be written as INTCON2.NOTRBPU (same thing better syntax)
3. CONFIG sets the PIC defaults on power up
4. It's in the 18F1320 datasheet search for ADCON1
5. also in the datasheet the upper nibble sets the clock, lower the options
6. by default a port in Input and/ or Analog TRISA = %11111111 would set the entire port to input
 
So 1 was right because i wrote :
A.TRISA.7 = 1 ( This would set pin 7 on PortA to Input / 0 would be output)
and you wrote
no, TRIS simply sets the direction of the port (In = 1, Out = 0)

How would i use LAT then?
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top