Jump to content
43oh

Help With Multiplexing LEDs


Recommended Posts

I have wired up a layout in which the LEDs are connected in a grid. The rows are all connected to transistors which switch between the positive supply and zero, and the columns switch between an open circuit and a connection to ground

 

multiplex.png

 

I am using the following code:

 

#include "io430.h"

void TurnON(unsigned x, unsigned y)
{
 unsigned YBITS[5] = {BIT0, BIT1, BIT2, BIT3, BIT4};
 unsigned XBITS[3] = {BIT5, BIT6, BIT7};

 P1OUT &= ~YBITS[y]; 
 P1SEL &= ~YBITS[y]; 
 P1DIR |= YBITS[y];  
 P1OUT |= YBITS[y]; 

 if(x < 3)
 {
   P1OUT &= ~XBITS[x]; 
   P1SEL &= ~XBITS[x]; 
   P1DIR |= XBITS[x];  
   P1OUT |= XBITS[x]; 
 }else
 {
   P2OUT &= ~BIT6; 
   P2SEL &= ~BIT6; 
   P2DIR |= BIT6;  
   P2OUT |= BIT6;  
 }
}

void TurnOFF(unsigned x, unsigned y)
{
 unsigned YBITS[5] = {BIT0, BIT1, BIT2, BIT3, BIT4};
 unsigned XBITS[3] = {BIT5, BIT6, BIT7};

 P1OUT &= ~YBITS[y]; 

 if(x < 3)
 {
   P1OUT &= ~XBITS[x]; 
 }else
 {
   P2OUT &= ~BIT6; 
 }
}

int main( void )
{
 // Stop watchdog timer to prevent time out reset
 WDTCTL = WDTPW + WDTHOLD;

 TurnON(1,0);
 TurnOFF(1,0);
}

 

The problem is that when I run it with TurnON then TurnOFF, the LED doesn't light up. When run it with just TurnON, the led lights up. However, when I try to display a number on the grid without using TurnOFF, such as a 2, the entire grid just lights up.

 

What am I doing wrong? How do I make the LEDs turn on and off and still see them?

 

Thanks

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...