How to set port to high impedance? TRIS seems not to be working.
Hello. I've got some special LED displays.
These are tiny 7 segment matrices, used in powerbanks and so on.
The key difference is that leds there are plugged into forward-reverse matrix, so you need to multiplex them to get meaningful results.
So in theory, operation is as follows:
1. Set all ports to high impedance state.
2. Pull high one port, pull down another port, so led connected thru it will be lit
repeat above with different ports in loop, to get the things needed.
The main issue is that either TRIS statements does not work, or HIGH-LOW statements interfere with them. In practice, this means that when I issue HIGH PORTB.3 or any other similar statement, some other PORTB pins also change their state. Adding TRIS.X=1 or 0 changes nothing. How to avoid this?
led segments are connected to PIC pins via 220 ohm resistors.
MCU is PIC16F886 and this is the sample code.
Code:
TRISA=%00000000 'S
TRISC=%00000000 'set
TRISB=%00000000 '
ANSELH=%00000000 ' ADC OFF B
ANSEL=%000000000 'configure PortA as digital except first 2
ADCON1=%10000000 'adc justify
OSCCON=%01110101 'SET FREQUENCY TO 8MHZ
WPUB=%00000000 'turn off Pullups
CM1CON0=0 'DISABLE COMPARATORS
CM2CON0=0 'SAME HERE
DEFINE OSC 8 'set oscillator speed
'adcin config
DEFINE ADC_BITS 10
DEFINE ADC_CLOCK 3
DEFINE ADC_SAMPLEUS 50
frak:
high porta.6
low portc.3
pause 2
low porta.6
high portc.3
pause 2
'
high portc.1
low portc.2
pause 2
low portc.1
high portc.2
pause 2
goto frak
stop
1 Attachment(s)
Re: How to set port to high impedance? TRIS seems not to be working.
Here is the pinout of the LED matrix.
Attachment 9210
Re: How to set port to high impedance? TRIS seems not to be working.
its called charlieplexing, forum examples abound
Re: How to set port to high impedance? TRIS seems not to be working.
Quote:
Originally Posted by
CuriousOne
The main issue is that either TRIS statements does not work, or HIGH-LOW statements interfere with them. In practice, this means that when I issue HIGH PORTB.3 or any other similar statement, some other PORTB pins also change their state. Adding TRIS.X=1 or 0 changes nothing. How to avoid this?
It sounds like you are describing the R-M-W (read-modify-write) effect that you get when setting one bit of a PORT output.
When you do a bit operation on a PORT, the entire PORT is read, the bit is modified, and the entire PORT is written back.
The easiest way to fix this is to use a part that has LAT registers, and always write to the LAT, read from the PORT.
Re: How to set port to high impedance? TRIS seems not to be working.
In your example code you clear all TRIS bits making them all outputs. Try:
Code:
TRISA = 111111
TRISB = 111111
TRISC = 111111
frak:
TRISA.6 = 0
TRISC.3 = 0
HIGH PORTA.6
LOW PORTC.3
PAUSE 2
LOW PORTA.6
HIGH PORTC.3
PAUSE 2
TRISA.6 = 1
TRISC.3 = 1
TRISC.1 = 0
TRISC.2 = 0
HIGH PORTC.1
LOW PORTC.2
PAUSE 2
LOW PORTC.1
HIGH PORTC.2
PAUSE 2
TRISC = 0
GOTO frak
Re: How to set port to high impedance? TRIS seems not to be working.
As I understand, that RMW issue might happen due to current flowing in reverse direction thru the one of the led segments.
For the latch part, I'll try one, too bad there is no search option to tell, which part has latch and which does not.
Re: How to set port to high impedance? TRIS seems not to be working.
Newer PICs have LATx registers that eliminate the RMW issues.
Re: How to set port to high impedance? TRIS seems not to be working.
charlieplexed correctly latx regs are not required at all