This thread has been locked.
If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.
Tool/software: Code Composer Studio
Hi. I need to Make a project for my lecture my teacher asked us use 7 segment display and 4 led for 0-9 counter. 7 segment display show the number and 4 led is show as a binary. And we need to use 3 button to adjust upper and lower the number and one button is used to close the all led. Me and my friend write a code that do everything he asked for but we cant use port 1 and port 2 vector at the same time because of that we are limited to 2 button we cant use the third button. If you can show us the way how can we use Port1 and port 2 vector interrupt same time it will be so good. My msp430 is a launchpad with g2553 inside.
Code:
#include <msp430.h>
int main(void)
{
WDTCTL = WDTPW | WDTHOLD; // stop watchdog timer
P1DIR |= BIT0+BIT1+BIT2+BIT3+BIT4+BIT5+BIT6; // seven segment display bagladigimiz portlari output yaptik
P2DIR |= BIT0+BIT1+BIT2+BIT3; //Binary olarak gosterecegimiz ledleri icin input yaptik ancak bu devreye daha sonra baglayacagiz(kodunu daha sonra yazacagiz)
P1OUT &= ~(BIT0+BIT1+BIT2+BIT3+BIT4+BIT5+BIT6); //baslangicta ledlerimizi kapadik
P2OUT &= ~(BIT0+BIT1+BIT2+BIT3);
P1DIR &= ~BIT7; // Port 1 deki BIT0dan BIT6 ya kadar olan Pinleri seven segment display icin kullandik geriye kalan BIT7 yi ONOFF tusu icin input yaptik
P2DIR &= ~(BIT4+BIT5); // bu iki BIT i ise rakamlarimizi arttirmak
//alttaki kisimda ise butonlarimizi pull up olarak ayarladik
P1REN |= BIT7;
P2REN |= BIT4+BIT5;
P1OUT |= BIT7;
P2OUT |= BIT4+BIT5;
//islemci hizini 1mhz yaptik
DCOCTL= CALDCO_1MHZ;
BCSCTL1 = CALBC1_1MHZ;
// alttaki kisimda butonlarimiz icin gerekli interrupt registerlarini atadik
P1IE |= BIT7;
P2IE |= BIT4+BIT5;
P1IFG &= ~BIT7;
P2IFG &= ~(BIT4+BIT5);
P1IES |= BIT7;
P2IES |= BIT4+BIT5;
_BIS_SR(GIE);
return 0;
}
#pragma vector = PORT1_VECTOR
__interrupt void ONOFF (void)
{
int display[11]={0,0x3F,0x06,0x5B,0x4F,0x66,0x6D,0x7D,0x07,0x7F,0x6F}; //internetten yararlanarak seven segment display icin hexadecimal kodlari yazip displaye atadik
int n=0; // n integerini belirledik boylece her n yi arttirdigimizda display icinde sonraki sayiya gelecek ve seven segment display de gozlemleyecegiz
if((P1IN&BIT7)!= BIT7) // port 1 deki butonu kapatmak icin ayaladik
{
n=4;
P1OUT |= display[n];
P1IFG &= ~BIT7;
}
}
#pragma vector = PORT2_VECTOR
__interrupt void AYAR (void)
{
int display[11]={0,0x3F,0x06,0x5B,0x4F,0x66,0x6D,0x7D,0x07,0x7F,0x6F};
int n=0;
int led[11]={0x00,0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09};
while(1)
{
if(((P2IN&BIT4)!= BIT4)&&((P2IN&BIT5)== BIT5)) // port2 deki bit4e denk gelen butonu sayiyi arttirmak icin kurduk
{
if(n==10) // n degerimiz 10 a esit olursa (yani sayi olarak 9 u gercerse) basa at dedik
{
n=0;
P2IFG &= ~BIT4;
}
P1OUT &= ~display[n]; // burada yaptigimiz islem once suanki n degerini sondur sonraki n degerine gec o o degere denk gelen ledleri yak
P2OUT &= ~led[n];
n++;
P1OUT |= display[n];
P2OUT |= led[n];
P2IFG &= ~BIT4;
if(n==1)
{
P2OUT &= ~(BIT0+BIT1+BIT2+BIT3);
}
if(n==1) // bunu koymayinca 0 da bazi ledlerin yerleri karisiyordu onu debugladik
{
P1OUT &= ~BIT6;
P1OUT |= BIT1;
}
if(n==2) // bu kodda ise 1 de 1 tane led fazladan yaniyordu onu sondurduk
{
P1OUT &= ~BIT6;
}
__delay_cycles(250000);
}
if(((P2IN&BIT5)!= BIT5)&&((P2IN&BIT4)== BIT4)) // yukaridaki islemlerin aynisini yaptik tek fark burda rakamlarimiz azaliyor
{
if(n<=1)
{
n=11;
P2IFG &= ~BIT5;
}
P1OUT &= ~display[n];
P2OUT &= ~led[n];
n--;
P1OUT |= display[n];
P2OUT |= led[n];
P2IFG &= ~BIT5;
if(n==1)
{
P2OUT &= ~(BIT0+BIT1+BIT2+BIT3);
}
if(n==10)
{
P1OUT &=~ BIT4;
}
if(n==1)
{
P1OUT &=~ BIT6;
P1OUT |= BIT1;
}
if(n==2)
{
P1OUT &=~ BIT6;
}
__delay_cycles(250000);
}
if (((P2IN&BIT5)!= BIT5)&((P2IN&BIT4)!= BIT4))
{
P1OUT &= ~display[n];
P2OUT &= ~led[n];
P2IFG &= ~BIT5;
P2IFG &= ~BIT4;
__delay_cycles(750000);
}
}
}
Hello,
I will bring this thread to the attention of the device experts. Note that due to the local holiday, responses may be delayed.
Thanks
ki
> while (1)
This shouldn't appear in an ISR, since interrupts (GIE) are disabled in an ISR. There are no "break" or "return" statements in this loop, so once the PORT2 ISR is triggered it will never exit, so the PORT1 ISR will never be called.
The simple remedy is to just delete this while statement. Once you do that, you might (or might not) encounter other dependencies on having the ISR run forever.
You should be thinking of a button push as an "event"; the ISR deals with that event and returns, then your program does nothing until the next event.
Eventually you'll need debouncing. The symptom will be that you'll push a button once and it will look like it was pushed multiple times. The G2ET Launchpad buttons don't bounce much, so for the moment concentrate on the logic.
[Edit: Fixed typo]
This is my new code i delete the while part and do a few changes because older version of the code does not accept port 1 and port 2 vector button interrupt together. I can use 2 port at the same time now but i cannot change the display n and led n because of that display and led status not changed at all. Thank you for answer.
#include <msp430.h>
int main(void)
{
WDTCTL = WDTPW | WDTHOLD; // stop watchdog timer
P1DIR |= BIT0+BIT1+BIT2+BIT3+BIT4+BIT5+BIT6; // seven segment display bagladigimiz portlari output yaptik
P2DIR |= BIT0+BIT1+BIT2+BIT3; //Binary olarak gosterecegimiz ledleri icin input yaptik
P1OUT &= ~(BIT0+BIT1+BIT2+BIT3+BIT4+BIT5+BIT6); //baslangicta ledlerimizi kapadik
P2OUT &= ~(BIT0+BIT1+BIT2+BIT3);
P1DIR &= ~BIT7; // Port 1 deki BIT0dan BIT6 ya kadar olan Pinleri seven segment display icin kullandik geriye kalan BIT7 yi ONOFF tusu icin input yaptik
P2DIR &= ~(BIT4+BIT5); // bu iki BIT i ise rakamlarimizi arttirip azaltmak icin kullacagimiz butonlar icin input yaptik
//alttaki kisimda ise butonlarimizi pull up olarak ayarladik
P1REN |= BIT7;
P2REN |= BIT4+BIT5;
P1OUT |= BIT7;
P2OUT |= BIT4+BIT5;
//islemci hizini 1mhz yaptik
DCOCTL= CALDCO_1MHZ;
BCSCTL1 = CALBC1_1MHZ;
// alttaki kisimda butonlarimiz icin gerekli interrupt registerlarini atadik
P1IE |= BIT7;
P2IE |= BIT4+BIT5;
P1IFG &= ~BIT7;
P2IFG &= ~(BIT4+BIT5);
P1IES |= BIT7;
P2IES |= BIT4+BIT5;
_BIS_SR(GIE);
return 0;
}
#pragma vector = PORT1_VECTOR
__interrupt void ONOFF (void)
{
int display[11]={0,0x3F,0x06,0x5B,0x4F,0x66,0x6D,0x7D,0x07,0x7F,0x6F}; //internetten yararlanarak seven segment display icin hexadecimal kodlari yazip displaye atadik
int n=0; // n integerini belirledik boylece her n yi arttirdigimizda veya azlattigimizda display icinde sonraki veya onceki sayiya gececek ve seven segment display de gozlemleyecegiz
int led[11]={0x00,0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09}; // Binary ledlerimiz icin ayarlamalar
n=8;
__delay_cycles(250000);
if(P1IFG&BIT7)
{
P2OUT^=led[n];
P1OUT^=display[n];
__delay_cycles(250000);
}
P1IFG=0;
}
#pragma vector = PORT2_VECTOR // rakamlari arttirip azaltmak icin 2 butonumuz port2 de
__interrupt void AYAR (void)
{
int display[11]={0,0x3F,0x06,0x5B,0x4F,0x66,0x6D,0x7D,0x07,0x7F,0x6F}; //internetten yararlanarak seven segment display icin hexadecimal kodlari yazip displaye atadik
int n=0; // n integerini belirledik boylece her n yi arttirdigimizda veya azlattigimizda display icinde sonraki veya onceki sayiya gececek ve seven segment display de gozlemleyecegiz
int led[11]={0x00,0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09}; // Binary ledlerimiz icin ayarlamalar
if(P2IFG&BIT4)
{
P1OUT &= ~display[n]; // burada yaptigimiz islem once suanki n degerini sondur sonraki n degerine gec ve o degere denk gelen ledleri yak
P2OUT &= ~led[n]; // Binary icin o anki degeri sondur sonraki n degerine gec ve o degere denk gelen ledleri yak
n=n+1;
P1OUT |= display[n];
P2OUT |= led[n];
P2IFG =0;
}
if(P2IFG&BIT5)
{
P2OUT^=BIT1;
P1OUT^=BIT2;
__delay_cycles(250000);
}
P2IFG=0;
}
> int n=0; // n integerini belirledik boylece her n yi arttirdigimizda veya azlattigimizda display icinde sonraki veya onceki sayiya gececek ve seven segment display de gozlemleyecegiz
This appears in each of your ISRs. This creates two different variables, local to each ISR (also temporary) which "disappear" when each ISR returns.
I suspect you actually want a single "global" variable which both ISRs can use, and which holds its value between button pushes.
To do this, declare it (once) outside any function (near the top of the file is usually a good place).
You should also declare it "volatile", i.e. "volatile int n = 0;" -- you don't need this now, but you might later, depending on how your program grows.
---------------
> P2IFG =0;
> }
> if(P2IFG&BIT5)
This sequence looks a bit odd -- if P2.4 shows an IFG, the code will clear the flag before it checks for P2.5, so you will never see both of them at the same time. Perhaps this was intentional, but at first glance it looks like a mistake.
Hi,
We haven’t heard from you for more than a week, so I’m assuming you were able to resolve your issue. If this isn’t the case, please click the "This did NOT resolve my issue" button and reply to this thread with more information. If this thread locks, please click the "Ask a related question" button and in the new thread describe the current status of your issue and any additional details you may have to assist us in helping to solve your issues.
**Attention** This is a public forum