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

Status
Not open for further replies.

#### blueroomelectronics

##### Well-Known Member
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/

#### AtomSoft

##### Well-Known Member
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

#### blueroomelectronics

##### Well-Known Member
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...

Last edited:

#### 3v0

##### Coop Build Coordinator
Forum Supporter
AtomSoft said:
how about both? First a single LED then Multiplexed LEDs using timers.

I will try to collect them and publish them some place soon.

#### Pommie

##### Well-Known Member
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) 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. #### AtomSoft ##### Well-Known Member where does it say how many bytes of ram used? I get: 39 Variable Bytes Used 373 Program Bytes used #### Pommie ##### Well-Known Member Most Helpful Member The variable bytes used is the ram used. Mike. #### AtomSoft ##### Well-Known Member 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:

#### blueroomelectronics

##### Well-Known Member
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

#### AtomSoft

##### Well-Known Member
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.

Replies
4
Views
990
Replies
5
Views
886
Replies
15
Views
2K
Replies
5
Views
2K
Replies
5
Views
2K