I can power pin 1:
I can power pin 4:
But I can't do the same thing at the same time, two unwanted LEDs come on:
Edit: I just noticed I missed another unwanted LED between pins 4 and 2.
I'll probably use a dedicated 18F24K22 running at 64MHz to manage the LEDs. I have to test, but blinking each LED individually might give enough persistence of vision (50 Hz or so).
I was initially planning on powering all LEDs active on one pin, but that might complicate things beyond my limitted abilities. I like to keep things simple.
I might also manage a simple keypad, not sure yet. I have enough pins, but tests will show how much the PIC can manage and still give satisfactory visual effects.
Robert
Last edited by Demon; - 21st December 2014 at 02:10.
As I sit down to think how to manage this, one MAJOR drawback:
You had better not forget any LEDs on your project 'cause adding one later is going to be "troublesome".
You can always add it at the bottom of your truth table, but I'm the obsessive compulsive type that likes symetry; LEDs are handled in the logic as they are placed on the circuit board. Remnants of hating spaghetti code on mainframes (COBOL + GOTO = NIGHTMARES).
Robert
Some neat stuff I forgot that I found several years ago on Charlie-plexing.
Code:clear define osc4 cmcon0=7 ansel=0 adcon0 = 0 @ device mclr_off @ device wdt_off @ device bod_off @ device cpd_off @ device protect_off led var byte ledstates var byte trisstate var byte delay var word noghost var byte gpnoghost var byte noghost= %111111 delay= 1500 starthere: gpio.3 = 0 if gpio.3 = 1 then goto main endif goto starthere main: for led = 1 to 6 select case led case 0 : ledstates =%001 : trisstate =%100 case 1 : ledstates =%010 : trisstate =%100 case 2 : ledstates =%001 : trisstate =%010 case 3 : ledstates =%100 : trisstate =%010 case 4 : ledstates =%100 : trisstate =%010 case 5 : ledstates =%010 : trisstate =%001 case 6 : ledstates =%100 : trisstate =%001 end select trisio = noghost gpio = ( gpio & %111000) | ledstates trisio = (trisio & %111000) | trisstate pause delay next led for led = 1 to 5 select case led case 1 : ledstates =%000001: trisstate =%101110 case 2 : ledstates =%011000: trisstate =%101110 case 3 : ledstates =%000010: trisstate =%101101 case 4 : ledstates =%010000: trisstate =%101101 case 5 : ledstates =%000010: trisstate =%011101 end select trisio = noghost gpio = ( gpio & %111000) | ledstates trisio = (trisio & %111000) | trisstate pause delay next led trisio=noghost gpio=gpnoghost goto starthere end
Editted to add some colour, original was black on light gray background.
I wish I could give a link and credit, but I can't find anything on google for this now (been looking for over an hour).
Robert
Last edited by Demon; - 14th December 2014 at 22:42. Reason: Added code instead of PDF
Did this a while ago. Don't know if it will help. http://www.picbasic.co.uk/forum/showthread.php?t=14220
If you use the above program you'll need to change you define osc line.
Good luck.
I used the wiring above for pins D.1, D.2 and D.3 on a 16F877 and it didn't work as expected.
I get 3 LEDs blinking faintly instead of a single one. It seems as if the current loops over to the unused pin and comes back.
I'll have to check out your thread. I must be missing something.
RobertCode:' Blink 6 LEDs connected to Port D.1, D.2 and D.3 in charlie-plex manner ' PIC 16F877 ext osc 20MHz ' PBP v2.60c ' MPASM v5.49 ' MCS+ v2.1.0.7 ' U2 programmer v4.32 asm __config _HS_OSC & _WDT_OFF & _PWRTE_OFF & _BODEN_ON & _LVP_OFF & _CPD_OFF & _WRT_OFF & _DEBUG_OFF & _CP_OFF endasm DEFINE OSC 20 ADCON1 = 7 ' Set Ports to digital TRISA = %00000000 ' Set all Ports to output TRISB = %00000000 TRISC = %00000000 TRISD = %00000000 TRISE = %00000000 PORTA = %00000000 ' Set ports OFF PORTB = %00000000 PORTC = %00000000 PORTD = %00000000 PORTE = %00000000 pause 100 mainloop: TRISD = %11111001 ' Enable pins D.1 and 2 PORTD = %00000100 ' Turn ON pin D.2 --> D.1 pause 500 PORTD = %00000010 ' Turn ON pin D.1 --> D.2 pause 500 ; TRISD = %11110101 ' Enable pins D.1 and 3 ; PORTD = %00001000 ' Turn ON pin D.3 --> D.1 ; pause 500 ; PORTD = %00000010 ' Turn ON pin D.1 --> D.3 ; pause 500 ; TRISD = %11110011 ' Enable pins D.2 and 3 ; PORTD = %00000100 ' Turn ON pin D.2 --> D.3 ; pause 500 ; PORTD = %00001000 ' Turn ON pin D.3 --> D.2 ; pause 500 TRISD = %11111111 ' All pins disabled pause 500 goto mainloop End
Hi AvionicsMaster1
No big deal, someone on here reckons that mistakes are not mistakes but learning opportunities and I think he's right having had plenty of learning opportunities myself.
Still getting them.
Using your idea to copy and paste |OR Demon, thanks.
Thanyou to Richard for keeping us right and for introducing me to the lookup command which has led me onto writing my code in decimal and hex.
Having great fun with them, well this is a hobby and hobbies are supposed to be fun.
The following code is for a set of traffic lights on the roads as part of a 1/76 scale model railway.
RegardsCode:'**************************************************************** '* Name : Four Way Traffic Lights * '* Author : Jim Hagan * '* Date : 10/07/2016 * '* Version : 1.0 * '* Notes : For 16F84A * '**************************************************************** #CONFIG __CONFIG _XT_OSC & _CP_OFF #ENDCONFIG 'Defines DEFINE OSC 4 'Tell PBP3 expected system clock frequency 'Aliases LEDS1 var PORTB 'Assign name LEDS1 to PORTB LEDS2 VAR PORTA 'Assign name LEDS2 to PORTA 'Variables i var byte 'Initialize TRISB = $0 'Set PORTB to Output TRISA = $0 'Program Code START gosub REDGREEN gosub REDAMBER gosub GREENRED gosub AMBERRED goto START REDGREEN LEDS1 = $61 'LEDS 0, 5 and 6 on PORTB On LEDS2 = $08 'LED 3 on PORTA On pause 3000 'Puts lights on for 3 seconds for i = 1 to 10 LEDS1 = $0 LEDS2 = $0 next i return REDAMBER LEDS1 = $D3 'LEDS 0, 1, 4, 6 and 7 on PORTB On LEDS2 = $04 'LED 2 on PORTA On pause 2000 'Puts lights on for 2 seconds for i = 1 to 10 LEDS1 = $0 LEDS2 = $0 next i return GREENRED LEDS1 = $C 'LEDS 2 and 3 on PORTB On LEDS2 = $03 'LEDS 0 and 1 on PORTA On pause 3000 for i = 1 to 10 LEDS1 = $0 LEDS2 = $0 next i return AMBERRED LEDS1 = $9A 'LEDS 1, 3, 4 and 7 on PORTB On LEDS2 = $06 'LEDS 1 and 2 on PORTA On pause 2000 for i = 1 to 10 LEDS1 = $0 LEDS2 = $0 next i return end
Jim
LMAO!
I posted YOUR program above! I googled and searched this forum to try and find where I got it from but never found it.
I'll have to look this over again, I must miss something obvious. You have GPIO, I only see PORT and TRIS registers as relevant on a 16F877.
Robert
Partly fixed.
I was using 3 red, green and yellow LEDs; they have wildly different current draw/voltage drops. I switched to all greens and the ghosting effect is practically gone.
I saw your comments about ghosting and noticed you output PORT before TRIS, didn't help me; tried both ways.
Robert
EDIT:
Code:asm __config _HS_OSC & _WDT_OFF & _PWRTE_OFF & _BODEN_ON & _LVP_OFF & _CPD_OFF & _WRT_OFF & _DEBUG_OFF & _CP_OFF endasm DEFINE OSC 20 ADCON1 = 7 ' Set Ports to digital TRISA = %00000000 ' Set all Ports to output TRISB = %00000000 TRISC = %00000000 TRISD = %00000000 TRISE = %00000000 PORTA = %00000000 ' Set ports OFF PORTB = %00000000 PORTC = %00000000 PORTD = %00000000 PORTE = %00000000 pause 100 mainloop: TRISD = %11111001 ' Enable pins D.1 and 2 PORTD = %00000100 ' Turn ON pin D.2 --> D.1 pause 500 TRISD = %11111001 ' Enable pins D.1 and 2 PORTD = %00000010 ' Turn ON pin D.1 --> D.2 pause 500 TRISD = %11110101 ' Enable pins D.1 and 3 PORTD = %00001000 ' Turn ON pin D.3 --> D.1 pause 500 TRISD = %11110101 ' Enable pins D.1 and 3 PORTD = %00000010 ' Turn ON pin D.1 --> D.3 pause 500 TRISD = %11110011 ' Enable pins D.2 and 3 PORTD = %00000100 ' Turn ON pin D.2 --> D.3 pause 500 TRISD = %11110011 ' Enable pins D.2 and 3 PORTD = %00001000 ' Turn ON pin D.3 --> D.2 pause 500 TRISD = %11111111 ' All pins disabled pause 500 goto mainloop End
Hi
Looks like I made a wrong post??
Don't know what?
Hi Demon and AvionicsMaster1
Thank you for the information.
I will try your suggestions though I think typing OR seems the easiest.
Regards
Jim
I will try your suggestions though I think typing OR seems the easiest..Though it looks cool to use those symbols I think it's easier just to type OR and know what it means
NOT sure about that , this is what the book says
3.4.2 Logical vs. Bitwise
Logical operators are very different than bitwise operators! There are
circumstances under which PBP will allow the use of logical operators in
expressions. This means that no error message will be generated when you
mistakenly use a logical operator in a bitwise calculation. Consider the following:
result = PORTB AND %00001111
' Returns logical result (1 or 0)
The above example will compile and give a result. The value of the result can only
be one or zero (true or false). If the intent is to use a bitwise operation to obtain a
binary result, you MUST USE BITWISE OPERATORS:
PRINTOUT:Code:i_term=0 d_err=4 i_err= 3 i_term= i_err | d_err serout2 PORTA.0,84,[ "3 | 4 ",9,#i_term, 13,10] i_term= i_err OR d_err serout2 PORTA.0,84,[ "3 OR 4 ",9,#i_term, 13,10]
3 | 4 7
3 OR 4 65535
Last edited by richard; - 29th June 2016 at 05:36.
Warning I'm not a teacher
Hi Richard
Looking at the PBP3 Compiler Manual it only shows OR as the description for
| in the Bitwise operators. It does show OR as an operator in the Logical operators.
Regards
Jim
Logical operators are not bitwise operators
| does a bitwise OR
OR does a Logical OR
2 | 3 = 7
2 OR 3 = ! 0 [ not nothing ]
Warning I'm not a teacher
Yes I made a mistake. There is a difference between bitwise operations and logical operations. I vehemently apologize for the second part of my post.
Bookmarks