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);
}
}
}