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)
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
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!
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) 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.
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.
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.
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)