Can't Change Individual Ports
Moderator: Benj
-
- Posts: 68
- Joined: Mon Oct 24, 2011 7:50 pm
- Has thanked: 11 times
- Been thanked: 3 times
- Contact:
Can't Change Individual Ports
Hello,
So I I need to display a number on one 7 segment display. There is one problem though. When I go into the Connections and try to change one Port Letter (i.e. PORTA, or PORTB) it changes EVERY port letter. I need to change segment A Port to PORTD 0 and segment B and up to ports PORTB 0 - PORTB 6. The reason I need to change segment A to a different port is because that port is being used by something else.
I'd really appreciate any help! Thank you!!!
So I I need to display a number on one 7 segment display. There is one problem though. When I go into the Connections and try to change one Port Letter (i.e. PORTA, or PORTB) it changes EVERY port letter. I need to change segment A Port to PORTD 0 and segment B and up to ports PORTB 0 - PORTB 6. The reason I need to change segment A to a different port is because that port is being used by something else.
I'd really appreciate any help! Thank you!!!
- Benj
- Matrix Staff
- Posts: 15312
- Joined: Mon Oct 16, 2006 10:48 am
- Location: Matrix TS Ltd
- Has thanked: 4803 times
- Been thanked: 4314 times
- Contact:
Re: Can't Change Individual Ports
Hello,
Ok this is possible but you cannot do it directly through the component without using code customization.
Select the component on the panel and click the custom code button.
Select the Show digit function and click edit.
Scroll down to the section beginning like this.
Edit it so that it matches your desired pin out. Basically you need to clear each bit in the tris register associated with the 8 outputs for the 7seg.
Next find this section.
And change to this to route the data to the correct output pins.
Click ok and then close and that's it your done.
Let me know how you get on.
Ok this is possible but you cannot do it directly through the component without using code customization.
Select the component on the panel and click the custom code button.
Select the Show digit function and click edit.
Scroll down to the section beginning like this.
Code: Select all
MX_7SEG1_COMMON_TRIS = MX_7SEG1_COMMON_TRIS & %o;
MX_7SEG1_SEGMENT_TRIS = MX_7SEG1_SEGMENT_TRIS & %p;
Code: Select all
MX_7SEG1_COMMON_TRIS = MX_7SEG1_COMMON_TRIS & %o;
TRISD = TRISD & ~(0x01);
TRISB = TRISB & ~(0x7E);
Code: Select all
//common anode
MX_7SEG1_SEGMENT_PORT = (MX_7SEG1_SEGMENT_PORT & %p) | cSegmentValue;
MX_7SEG1_COMMON_PORT = (MX_7SEG1_COMMON_PORT | %n);
#else
//common cathode
MX_7SEG1_SEGMENT_PORT = (MX_7SEG1_SEGMENT_PORT & %p) | ~cSegmentValue;
MX_7SEG1_COMMON_PORT = (MX_7SEG1_COMMON_PORT & %o);
Code: Select all
//common anode
PORTD = (PORTD & 0xFE) | (cSegmentValue & 0x01);
cSegmentValue = cSegmentValue >> 1;
PORTB = (PORTB & 0x80) | (cSegmentValue & 0x7F);
MX_7SEG1_COMMON_PORT = (MX_7SEG1_COMMON_PORT | %n);
#else
//common cathode
PORTD = (PORTD & 0xFE) | (~cSegmentValue & 0x01);
cSegmentValue = cSegmentValue >> 1;
PORTB = (PORTB & 0x80) | (~cSegmentValue & 0x7F);
MX_7SEG1_COMMON_PORT = (MX_7SEG1_COMMON_PORT & %o);
Let me know how you get on.
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
-
- Posts: 68
- Joined: Mon Oct 24, 2011 7:50 pm
- Has thanked: 11 times
- Been thanked: 3 times
- Contact:
Re: Can't Change Individual Ports
Benj wrote:Hello,
Ok this is possible but you cannot do it directly through the component without using code customization.
Select the component on the panel and click the custom code button.
Select the Show digit function and click edit.
Scroll down to the section beginning like this.
Edit it so that it matches your desired pin out. Basically you need to clear each bit in the tris register associated with the 8 outputs for the 7seg.Code: Select all
MX_7SEG1_COMMON_TRIS = MX_7SEG1_COMMON_TRIS & %o; MX_7SEG1_SEGMENT_TRIS = MX_7SEG1_SEGMENT_TRIS & %p;
Next find this section.Code: Select all
MX_7SEG1_COMMON_TRIS = MX_7SEG1_COMMON_TRIS & %o; TRISD = TRISD & ~(0x01); TRISB = TRISB & ~(0x7E);
And change to this to route the data to the correct output pins.Code: Select all
//common anode MX_7SEG1_SEGMENT_PORT = (MX_7SEG1_SEGMENT_PORT & %p) | cSegmentValue; MX_7SEG1_COMMON_PORT = (MX_7SEG1_COMMON_PORT | %n); #else //common cathode MX_7SEG1_SEGMENT_PORT = (MX_7SEG1_SEGMENT_PORT & %p) | ~cSegmentValue; MX_7SEG1_COMMON_PORT = (MX_7SEG1_COMMON_PORT & %o);
Click ok and then close and that's it your done.Code: Select all
//common anode PORTD = (PORTD & 0xFE) | (cSegmentValue & 0x01); cSegmentValue = cSegmentValue >> 1; PORTB = (PORTB & 0x80) | (cSegmentValue & 0x7F); MX_7SEG1_COMMON_PORT = (MX_7SEG1_COMMON_PORT | %n); #else //common cathode PORTD = (PORTD & 0xFE) | (~cSegmentValue & 0x01); cSegmentValue = cSegmentValue >> 1; PORTB = (PORTB & 0x80) | (~cSegmentValue & 0x7F); MX_7SEG1_COMMON_PORT = (MX_7SEG1_COMMON_PORT & %o);
Let me know how you get on.
My code looks a little different so I can't figure out where exactly to put the new code. Also, can you explain how the hex values correspond to the pin?
My code:
Code: Select all
//Segment Port Definitions
#define MX_7SEG1_SEGMENT_PORT PORT%a
#define MX_7SEG1_SEGMENT_DDR DDR%a
//Common Port Definitions
#define MX_7SEG1_COMMON_PORT PORT%b
#define MX_7SEG1_COMMON_DDR DDR%b
//set pattern array for the display
const char cSegmentArray[] = {%c, %d, %e, %f, %g, %h, %i, %j, %k, %l};
//get pattern for digit
char cSegmentValue = cSegmentArray[Value % 10];
if (DecimalPoint)
cSegmentValue = cSegmentValue & %m;
//set up ports
MX_7SEG1_COMMON_DDR = MX_7SEG1_COMMON_DDR | ~%o;
MX_7SEG1_SEGMENT_DDR = MX_7SEG1_SEGMENT_DDR | ~%p;
//display the digit
#if (%q == 1)
//common anode
MX_7SEG1_SEGMENT_PORT = (MX_7SEG1_SEGMENT_PORT & %p) | cSegmentValue;
MX_7SEG1_COMMON_PORT = (MX_7SEG1_COMMON_PORT | %n);
#else
//common cathode
MX_7SEG1_SEGMENT_PORT = (MX_7SEG1_SEGMENT_PORT & %p) | ~cSegmentValue;
MX_7SEG1_COMMON_PORT = (MX_7SEG1_COMMON_PORT & %o);
#endif
//undefine symbols
#undef MX_7SEG1_SEGMENT_PORT
#undef MX_7SEG1_SEGMENT_DDR
#undef MX_7SEG1_COMMON_PORT
#undef MX_7SEG1_COMMON_DDR
- Benj
- Matrix Staff
- Posts: 15312
- Joined: Mon Oct 16, 2006 10:48 am
- Location: Matrix TS Ltd
- Has thanked: 4803 times
- Been thanked: 4314 times
- Contact:
Re: Can't Change Individual Ports
Aha your using AVR not PIC, sorry about that.
Ok this section.
Change to this.
And this section.
Change to this.
Each Port register is made up of 8 bits. A hex value from 0x00 to 0xFF is an 8-bit value that contains all of the possible combinations of 0's and 1's, 256 different combinations to be precise and including 0.
cSegmentValue & 0x01
This masks off the first data bit allowing us to write the bit0 of portd.
cSegmentValue >> 1
cSegmentValue & 0x7F
This shifts the variable cSegmentValue to the right by one place essentially dropping the least significant bit.
We then use 7F to mask off the remaining 7 bits of data to pass to portb.
Ok this section.
Code: Select all
//set up ports
MX_7SEG1_COMMON_DDR = MX_7SEG1_COMMON_DDR | ~%o;
MX_7SEG1_SEGMENT_DDR = MX_7SEG1_SEGMENT_DDR | ~%p;
Code: Select all
MX_7SEG1_COMMON_DDR = MX_7SEG1_COMMON_DDR | ~%o;
DDRD = DDRD | 0x01;
DDRB = DDRB | 0x7E;
Code: Select all
//common anode
MX_7SEG1_SEGMENT_PORT = (MX_7SEG1_SEGMENT_PORT & %p) | cSegmentValue;
MX_7SEG1_COMMON_PORT = (MX_7SEG1_COMMON_PORT | %n);
#else
//common cathode
MX_7SEG1_SEGMENT_PORT = (MX_7SEG1_SEGMENT_PORT & %p) | ~cSegmentValue;
MX_7SEG1_COMMON_PORT = (MX_7SEG1_COMMON_PORT & %o);
Code: Select all
//common anode
PORTD = (PORTD & 0xFE) | (cSegmentValue & 0x01);
cSegmentValue = cSegmentValue >> 1;
PORTB = (PORTB & 0x80) | (cSegmentValue & 0x7F);
MX_7SEG1_COMMON_PORT = (MX_7SEG1_COMMON_PORT | %n);
#else
//common cathode
PORTD = (PORTD & 0xFE) | (~cSegmentValue & 0x01);
cSegmentValue = cSegmentValue >> 1;
PORTB = (PORTB & 0x80) | (~cSegmentValue & 0x7F);
MX_7SEG1_COMMON_PORT = (MX_7SEG1_COMMON_PORT & %o);
cSegmentValue & 0x01
This masks off the first data bit allowing us to write the bit0 of portd.
cSegmentValue >> 1
cSegmentValue & 0x7F
This shifts the variable cSegmentValue to the right by one place essentially dropping the least significant bit.
We then use 7F to mask off the remaining 7 bits of data to pass to portb.
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
-
- Posts: 68
- Joined: Mon Oct 24, 2011 7:50 pm
- Has thanked: 11 times
- Been thanked: 3 times
- Contact:
Re: Can't Change Individual Ports
So I actually need to change Segment D instead. I made all of your modifications with a couple changes to make it change to Segment D instead of A. So far, all the segments are working except for Segment D.Benj wrote:Aha your using AVR not PIC, sorry about that.
Ok this section.
Change to this.Code: Select all
//set up ports MX_7SEG1_COMMON_DDR = MX_7SEG1_COMMON_DDR | ~%o; MX_7SEG1_SEGMENT_DDR = MX_7SEG1_SEGMENT_DDR | ~%p;
And this section.Code: Select all
MX_7SEG1_COMMON_DDR = MX_7SEG1_COMMON_DDR | ~%o; DDRD = DDRD | 0x01; DDRB = DDRB | 0x7E;
Change to this.Code: Select all
//common anode MX_7SEG1_SEGMENT_PORT = (MX_7SEG1_SEGMENT_PORT & %p) | cSegmentValue; MX_7SEG1_COMMON_PORT = (MX_7SEG1_COMMON_PORT | %n); #else //common cathode MX_7SEG1_SEGMENT_PORT = (MX_7SEG1_SEGMENT_PORT & %p) | ~cSegmentValue; MX_7SEG1_COMMON_PORT = (MX_7SEG1_COMMON_PORT & %o);
Each Port register is made up of 8 bits. A hex value from 0x00 to 0xFF is an 8-bit value that contains all of the possible combinations of 0's and 1's, 256 different combinations to be precise and including 0.Code: Select all
//common anode PORTD = (PORTD & 0xFE) | (cSegmentValue & 0x01); cSegmentValue = cSegmentValue >> 1; PORTB = (PORTB & 0x80) | (cSegmentValue & 0x7F); MX_7SEG1_COMMON_PORT = (MX_7SEG1_COMMON_PORT | %n); #else //common cathode PORTD = (PORTD & 0xFE) | (~cSegmentValue & 0x01); cSegmentValue = cSegmentValue >> 1; PORTB = (PORTB & 0x80) | (~cSegmentValue & 0x7F); MX_7SEG1_COMMON_PORT = (MX_7SEG1_COMMON_PORT & %o);
cSegmentValue & 0x01
This masks off the first data bit allowing us to write the bit0 of portd.
cSegmentValue >> 1
cSegmentValue & 0x7F
This shifts the variable cSegmentValue to the right by one place essentially dropping the least significant bit.
We then use 7F to mask off the remaining 7 bits of data to pass to portb.
Here is the code:
Code: Select all
//set up ports
MX_7SEG1_COMMON_DDR = MX_7SEG1_COMMON_DDR | ~%o;
DDRB = DDRB | 0xF7;
DDRD = DDRD | 0x01;
Code: Select all
//common cathode
PORTB = (PORTB & 0xFE) | (~cSegmentValue & 0x01);
PORTB = (PORTB & 0xFD) | (~cSegmentValue & 0x02);
PORTB = (PORTB & 0xFB) | (~cSegmentValue & 0x04);
PORTD = (PORTD & 0xF7) | (~cSegmentValue & 0x08);
PORTB = (PORTB & 0xEF) | (~cSegmentValue & 0x10);
PORTB = (PORTB & 0xDF) | (~cSegmentValue & 0x20);
PORTB = (PORTB & 0xBF) | (~cSegmentValue & 0x40);
PORTB = (PORTB & 0x7F) | (~cSegmentValue & 0x80);
MX_7SEG1_COMMON_PORT = (MX_7SEG1_COMMON_PORT & %o);
- Benj
- Matrix Staff
- Posts: 15312
- Joined: Mon Oct 16, 2006 10:48 am
- Location: Matrix TS Ltd
- Has thanked: 4803 times
- Been thanked: 4314 times
- Contact:
Re: Can't Change Individual Ports
Hello,
I think this line of code.
Should look like this if you are using pin D0.
I think this line of code.
Code: Select all
PORTD = (PORTD & 0xF7) | (~cSegmentValue & 0x08);
Code: Select all
PORTD = (PORTD & 0xFE) | ((~cSegmentValue & 0x08) >> 3);
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
-
- Posts: 68
- Joined: Mon Oct 24, 2011 7:50 pm
- Has thanked: 11 times
- Been thanked: 3 times
- Contact:
Re: Can't Change Individual Ports
It works! Thank you!Benj wrote:Hello,
I think this line of code.
Should look like this if you are using pin D0.Code: Select all
PORTD = (PORTD & 0xF7) | (~cSegmentValue & 0x08);
Code: Select all
PORTD = (PORTD & 0xFE) | ((~cSegmentValue & 0x08) >> 3);
-
- Posts: 68
- Joined: Mon Oct 24, 2011 7:50 pm
- Has thanked: 11 times
- Been thanked: 3 times
- Contact:
Re: Can't Change Individual Ports
Benj wrote:Hello,
I think this line of code.
Should look like this if you are using pin D0.Code: Select all
PORTD = (PORTD & 0xF7) | (~cSegmentValue & 0x08);
Code: Select all
PORTD = (PORTD & 0xFE) | ((~cSegmentValue & 0x08) >> 3);
Hello! Sorry to bring this thread back from the dead, but I have a problem.
Basically I got a new 7-segment display and it has common anodes instead of cathodes. Could you help me make the code for the common anodes instead of the cathodes? Same exact as the common cathodes setup except now they need to be anodes. I am guessing the ports and segments would need to be inverted so the electricity can flow into the ports instead of out? I can't figure this out so could I get your help? Thank you so very much!
Also, if it helps, here is a pinout of what I need:
SEGMENT A > PORTB.0
SEGMENT B > PORTB.1
SEGMENT C > PORTB.2
SEGMENT D > PORTD.0
SEGMENT E > PORTB.4
SEGMENT F > PORTB.5
SEGMENT G > PORTB.6