1.) a. Modify the following code so that: the switches and LEDs behave this way: Switch 3...
Question:
1.)
a. Modify the following code so that: the switches and LEDs behave this way: Switch 3 turns LED 4 ON, Switch 4 turns LED 5 ON…, Switch 9 turns LED 10 on.
#include "msp430f5308.h"
unsigned int BusAddress,BusData; // The bridge between Assembler code and C code. Memory address from 1C00H to 1C03H for absolute option
void Initial(void);
void BusRead(void);
void BusWrite(void);
//******************************************************************************************************************
const int SwitchesAddr=0x4000;
const int LedsAddr=0x4002;
//******************************************************************************************************************
void main(void){
Initial();
for(;;){
BusAddress=SwitchesAddr;
BusRead();
BusData=~BusData;
BusAddress=LedsAddr;
BusWrite();
}
}
b.) Modify the below code so that seven-segment 1 shows 1 number bigger than the binary equivalent for example if the binary number is 10, the seven-segment 1 should show 3. Also, modify seven-segment 2 so it adds 2 to the binary equivalent for example for binary number 10, seven-segment 2 should show 4. Do this for binary numbers 0 to E.
#include "msp430f5308.h"
unsigned int BusAddress,BusData; // The bridge between Assembler code and C code. Memory address from 1C00H to 1C03H for absolute option
void Initial(void);
void BusRead(void);
void BusWrite(void);
//******************************************************************************************************************
const int SwitchesAddr=0x4000;
const int LedsAddr=0x4002;
const int SegLow=0x4004;
const int SegHigh=0x4006;
const char LookupSeg[16]={0x040,0x79,0x24,0x30,0x19,0x12,0x02,0x78,0x00,0x18,0x08,0x03,0x46,0x21,0x06,0x0E};
//******************************************************************************************************************
unsigned char Temp,Count;
void main(void){
Initial();
for(;;){
BusAddress=SwitchesAddr;
BusRead();
Temp=BusData;
BusData=~BusData;
BusAddress=LedsAddr;
BusWrite();
Count=0;
while(Temp>=16)
{
Temp=Temp-16;
Count++;
}
BusData=LookupSeg[Temp];
BusAddress=SegLow;
BusWrite();
BusData=LookupSeg[Count];
BusAddress=SegHigh;
BusWrite();
}
}
c.) Observe the I2C setup and LCD setup parts of following the code. Write down the parts of codes responsible for “Master mode synchronization”, “Transmit Acknowledgement or ACLK” and “Slave Address” . Modify the code so it writes the name "JOHN" and "FRANK" on the LCD.
#include "msp430f5308.h"
void Initial(void);
const char ECE[16]=" ECE" ;
const char CURTIN[16]=" Curtin Uni ";
/**************************************** Main routine *****************************************************************/
void main(void){
unsigned int Wait;
unsigned char Count;
Initial();
/****************************************** I2C setup ********************************************************************/
UCB1CTL1|=UCSWRST; // Reset I2C
UCB1CTL0|=(UCMST+UCMODE_3+UCSYNC); // Master mode, I2C, Synchronous
UCB1CTL1|=(UCTR+UCSSEL_1); // Transmit, ACLK
UCB1BR0=63; // 400kHz
UCB1I2CSA=0x3E; // Slave address
P4SEL|=0x02; // Data
P4SEL|=0x04; // Clock
//for(Wait=0;Wait<100;Wait++){}
UCB1CTL1&=~UCSWRST; // Release I2C reset
/********************************************** LCD setup ****************************************************************/
UCB1CTL1|=UCTXSTT; // Start
/*
UCB1TXBUF=0x00; // Control LCD
while(!(UCTXIFG&UCB1IFG));
UCB1TXBUF=0x38; // Function set
while(!(UCTXIFG&UCB1IFG));
UCB1CTL1|=UCTXSTP; // Stop
UCB1IFG&=~UCTXIFG;
UCB1CTL1|=UCTXSTT; // Start
while(!(UCTXIFG&UCB1IFG));
*/
UCB1TXBUF=0x00; // Control LCD
while(!(UCTXIFG&UCB1IFG));
UCB1TXBUF=0x39; // Function set
while(!(UCTXIFG&UCB1IFG));
UCB1TXBUF=0x14; // Internal oscillator frequency
while(!(UCTXIFG&UCB1IFG));
UCB1TXBUF=0x74; // Contrast set
while(!(UCTXIFG&UCB1IFG));
UCB1TXBUF=0x54; // Power/ICON control/Contrast set
while(!(UCTXIFG&UCB1IFG));
UCB1TXBUF=0x6F; // Follower control
while(!(UCTXIFG&UCB1IFG));
UCB1TXBUF=0x0E; // Display ON/OFF, Cursor ON, No blink
while(!(UCTXIFG&UCB1IFG));
UCB1TXBUF=0x01; // Clear display
while(!(UCTXIFG&UCB1IFG));
UCB1CTL1|=UCTXSTP; // Stop
UCB1IFG&=~UCTXIFG; // Clear transmitt interrupt flag
for(Wait=0;Wait<10000;Wait++){}
/***********************************************************************************************/
UCB1CTL1|=UCTXSTT; // Start
UCB1TXBUF=0x40; // Control byte to write data
while(!(UCTXIFG&UCB1IFG));
for(Count=0;Count<16;Count++){
UCB1TXBUF=ECE[Count];
while(!(UCTXIFG&UCB1IFG));
}
UCB1CTL1|=UCTXSTP; // Stop
UCB1IFG&=~UCTXIFG; // Clear transmitt interrupt flag
for(Wait=0;Wait<200;Wait++){}
UCB1CTL1|=UCTXSTT; // Start
UCB1TXBUF=0x80; // 0x00-Control byte for instruction with next Stop. 0x80-Control byte without next Stop
while(!(UCTXIFG&UCB1IFG));
UCB1TXBUF=0x0C0; // Jump to second line instruction
while(!(UCTXIFG&UCB1IFG));
/*
UCB1CTL1|=UCTXSTP; // Stop
UCB1IFG&=~UCTXIFG; // Clear transmit interrupt flag
for(Wait=0;Wait<200;Wait++){}
UCB1CTL1|=UCTXSTT; // Start
*/
UCB1TXBUF=0x40; // Write instruction
while(!(UCTXIFG&UCB1IFG));
for(Count=0;Count<16;Count++){
UCB1TXBUF=CURTIN[Count];
while(!(UCTXIFG&UCB1IFG));
}
UCB1CTL1|=UCTXSTP; // Stop
UCB1IFG&=~UCTXIFG; // Clear transmitt interrupt flag
for(;;);
}
d.) Modify the following code so that each key press shows one digit higher on the seven-segment, for example pressing 1 on the keypad must display 2 on the seven-segment. Do this for numbers 0 to E. This modification must be done using two methods. (Hint: One method could be to modify the lookup table for the seven segment).
#include "msp430f5308.h"
#include "intrinsics.h"
unsigned int BusAddress,BusData; // The bridge between Assembler code and C code. Memory address from 1C00H to 1C03H
void Initial(void);
void BusRead(void);
void BusWrite();
//***********************************************************************************************************************************************
const int Seg7AddrL=0x4004;
const int Seg7AddrH=0x4006;
const int KeyPadAddr=0x4008;
const char LookupSeg[16]={0x040,0x79,0x24,0x30,0x19,0x12,0x02,0x78,0x00,0x18,0x08,0x03,0x46,0x21,0x06,0x0E};
const char LookupKeys[16]={0x82,0x11,0x12,0x14,0x21,0x22,0x24,0x41,0x42,0x44,0x81,0x84,0x88,0x48,0x28,0x18};
unsigned int DelCount;
unsigned char Array[16];
unsigned char Acount;
unsigned char KeyPad,KeyCode,Count,BigCount;
//***********************************************************************************************************************************************
#pragma vector=PORT2_VECTOR
__interrupt void PORT2_ISR( void )
{
BusAddress=KeyPadAddr;
BusRead();
KeyPad=BusData;
//Array[Acount]=BusData;
//Acount++;
for (Count=0;Count<16;Count++){
if ( KeyPad==LookupKeys[Count] ){
KeyCode=LookupSeg[Count];
BusAddress=Seg7AddrL;
BusData=KeyCode;
BusWrite();
BusAddress=Seg7AddrH;
BusData=KeyCode;
BusWrite();
PUCTL|=PUOUT0; // Switch ON buzzer
for(BigCount=0;BigCount<5;BigCount++){
for(DelCount=0;DelCount<50000;DelCount++){} //50000
}
PUCTL&=~PUOUT0; // Switch OFF buzzer
}
}
P2IFG&=~0x01; // Clear button interrupt flag
}
//***************************************************************************************************************************************************
void main(void) {
Initial();
P2IES&=~0x01; // Positive edge of the pin interrupt
P2IE|=0x01; // Enable P2.0 interrupt
P1IFG=0x00; // Clear all P1 interrupt flags
P2IFG&=~0x01; // Clear P2.0 interrupt flag
Acount=0;
__enable_interrupt();
for(;;){}
} // End "main"
Federal Tax Research
ISBN: 9781285439396
10th edition
Authors: Roby Sawyers, William Raabe, Gerald Whittenburg, Steven Gill