Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Provided SKELETON: (What really needed to be done the \"// modify section\" in t

ID: 3707119 • Letter: P

Question

Provided SKELETON: (What really needed to be done the "// modify section" in the SKELETON code)

#include <msp430.h>

//Digit configuration, make sure segments h-a are connected to PORT1 pins 7-0
//also besides disigts 0-9, you have single segments abcdefg.
int LEDS[] = {0x3F,0x06,0x5B,0x4F,0x66,0x6D,0x7D,0x07,0x7F,0x67,0x01,0x02,04,0x08,0x10,0x20,0x40,0x80};

int switches=0;
int leftdigit=0, rightdigit=0;
int pleftdigit=0, prightdigit=0;    //preset values
int flag=0;

int main(void)
{
// WDTCTL = WDTPW | WDTHOLD;        // Stop watchdog timer
   BCSCTL2 |= DIVS_2;                   // DIVS_0; DIVS_1; DIVS_2; DIVS_3;
   WDTCTL = WDT_MDLY_0_5;          // WDT_MDLY_32; WDT_MDLY_8; WDT_MDLY_0_5;
   IE1 |= WDTIE;

    P1OUT = 0x00;                   // port 1 out default 00
    P1DIR = 0xff;                    // port 1 all output
    P2DIR = 0x03;                   // port 2 all inputs, except BIT0 and BIT1

   __enable_interrupt();

for (;;)
{
//   switches = P2IN; //if wired as active low
   switches = ~P2IN; //if wired as active high

   // the displayed numbers while we keep multiplexing of the display relatively faster

   //check switches for 000 --> Counter resets to 00
   if (((switches & BIT5) != BIT5) && ((switches & BIT4) != BIT4) && ((switches & BIT3) != BIT3))
   {leftdigit=0; rightdigit=0; }

   //check switches for 001 --> right digit count up
   if (((switches & BIT5) != BIT5) && ((switches & BIT4) != BIT4) && ((switches & BIT3) == BIT3))
   {rightdigit++; if (rightdigit >=10) {rightdigit=0;} }

   //check switches for 010 --> left digit count up
   if (((switches & BIT5) != BIT5) && ((switches & BIT4) == BIT4) && ((switches & BIT3) != BIT3))
   {leftdigit++ ; if (leftdigit >=10) {leftdigit=0;} }

   //check switches for 011 --> Right and left digits both hold values (preset value)
   if (((switches & BIT5) != BIT5) && ((switches & BIT4) == BIT4) && ((switches & BIT3) == BIT3))
   {pleftdigit=leftdigit; prightdigit=rightdigit; }

   // SW-321 = 101: Counter cycles up from the preset value to 99
   if (((switches & BIT5) == BIT5) && ((switches & BIT4) != BIT4) && ((switches & BIT3) == BIT3))
   // modify this secion, for now you have a rotating pattern
   {
       if (rightdigit <=9) {rightdigit=10;}
       if (leftdigit <=9) {leftdigit =10;}

       rightdigit++; if (rightdigit >=16) {rightdigit=10;}
       leftdigit--; if (leftdigit ==9 ) {leftdigit =15;}
   }

   // SW-321 = 110: Counter cycles down from the preset value to 00
   if (((switches & BIT5) == BIT5) && ((switches & BIT4) == BIT4) && ((switches & BIT3) != BIT3))
   // modify this section,
   { }

   //check switches for 100 --> 2 digit count up
   if (((switches & BIT5) == BIT5) && ((switches & BIT4) != BIT4)&& ((switches & BIT3) != BIT3))
   // modify this section,
   { }

   //check switches for 111 --> 2 digit count down
   if (((switches & BIT5) == BIT5) && ((switches & BIT4) == BIT4)&& ((switches & BIT3) == BIT3))
   // modify this section,
   { }

   // this delay determins the speed of chaning the number bing displayd
   __delay_cycles (500000);

} // end of for loop
} // end of main


// WDT interrupt service routine
#pragma vector=WDT_VECTOR
__interrupt void WDT(void)
{
   //This executes everytime there is a timer interrupt from WDT
   //The fequency of this interrupt controls the flickering of display
   //The right and left digits are displayed alternatively
   //Note that both digits must be turned off to avoid aliasing

/*
    //Display code for Common-Anode display
   P1OUT= 0; P2OUT=0;
   __delay_cycles (100);
   if (flag == 0) {P2OUT= BIT0; P1OUT= LEDS[leftdigit]; flag=1;}
   else             {P2OUT= BIT1; P1OUT= LEDS[rightdigit]; flag=0;}
   __delay_cycles (100);
*/

   //Display code for Common-Cathod display
   P1OUT= 0xFF; P2OUT=0xFF;
   __delay_cycles (100);
   if (flag == 0) {P2OUT &= ~BIT0; P1OUT= ~LEDS[leftdigit]; flag=1;}
   else             {P2OUT &= ~BIT1; P1OUT= ~LEDS[rightdigit]; flag=0;}
   __delay_cycles (100);


}

[20] 5) Write a C program using the MSP430G2553 Launchpad which creates a counter from 00-99. Your kit may have 7-seg displays with different pinout than the one in the drawings. As always check datasheets of your hardware components before wiring. For input control we use three DIP switches SW-321 which are connected to pins P2.5-3 with pulk-up resistors. The different combinations of these 3 switches determine the operat ion of the counter as explained be low. The two 7-segment digits are mult iplexed (turned on alternately) by two control signals coming from P2.0 and P2.1. The two 2N2222 transistors with 1K Ohm resistors on the gate are used as power drivers for the Common Anode pins of the displays. The 8 segments (a,b,c,d,e,fg) ofboth disp lays are connected to Port 1 pins P1.0-P1.6 through a resister network (470-1000 Ohm). Please use the figure be low as a sample how to organize components and wires on your breadboard. For exact pinout of the 2-digit 7-segment display, check the actual data sheet on the display part you are given in the lab kit. Ifthe displays have Common Cathode instead of Common Anode, you need to use PNP transistors instead ofNPN [4] 5.a) Build the circu it as described above and run the skeleton code. [8] 5.b Modify the code so that the counter init ial number setup goes as fo lows. You may wish to slow down the display update so you see the changes better: » SW-321 000: Counter resets to 00 * SW-321 001: Right digit cycles 0-9 * SW-321 010: Left dig it cycles 0-9 * SW-321 011: Right and leff digits both hold values (preset value) [8] 5.c) Counter counts up or down * SW-321 111: Counter cycles up from the preset value to 99 * SW-321 100: Counter cycles down from the preset value to 00 * SW-321 101: Pause Counting * SW-321 110: Pause Counting

Explanation / Answer

#include<msp430g2553.h>

#define T1 BIT4

#define T2 BIT5

#define T3 BIT6

#define T4 BIT7

int so[10]={0xC0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90 };

void hienthi(int number,int led_enable)

{

P2OUT=so[number]; P1OUT |=led_enable;

_delay_cycles(150); P1OUT &=~led_enable;

}

void main(void)

{

WDTCTL=WDTHOLD+WDTPW;

P2SEL=0; P1DIR=0xff;

P2DIR=0xff;

while(1)

{

hienthi(2,T1);

hienthi(0,T2);

hienthi(1,T3);

hienthi(3,T4);

}

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote