Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Can someone adjust and add this code: if (select < 25) //write code to assign PTT value to LEDs //position the LCD cursor and send

Can someone adjust and add this code:

if (select < 25)

//write code to assign PTT value to LEDs

//position the LCD cursor and send the string ON/ OFF, etc.

else if(select>30)

//write code to assign PTT value to LEDs

//position the LCD cursor and send the string ON/OFF, etc.

//write code to assign PTT value to LEDs

//position the LCD cursor and send the string ON/OFF, etc.

to this one:

#include /* common defines and macros */

#include "derivative.h" /* derivative-specific definitions */

//global variables

//4-bit initialization sequence for LCD - data: PC7,6,5,4 E: PC2 R/W~: PC1 RS: PC0

const unsigned char cInit_commands[20] =

{0x30,0x30,0x30,0x20,0x20,0x90,0x10,0x50,0x70,0x80,0x50,0xE0,

0x60,0xA0,0x00,0xE0,0x00,0x10,0x00,0x60};

const unsigned char Row1_Msg[17] = "Temp = ";

const unsigned char Row2_Msg[] = "HEAT A/C ";

const unsigned char Row3_Msg[] = "FAN";

const unsigned char cE = 0x04;

const unsigned char cRS = 0x01;

unsigned char cValue; // variable used in port initialization

unsigned int iValue;

// result from the ATD channel 1

int p;

//function prototypes

void initLCD(void);

void initPorts(void);

void LCDputs(char*);

void LCDputch(char);

void cmdwrt(unsigned char);

void datawrt(char);

void position(int,int);

void delay1u(void);

void delay100u(void);

void delay2m(void);

void delays(int);

void init_ATD(void);

void init_PLL(void);

void lcd_printd(unsigned int);

/************main************/

void main()

{

unsigned int select;

initPorts( );

// port initializations

initLCD( );

// LCD inititialization

init_PLL();

// Call init_PLL to initialize PLL

init_ATD();

// Call init_ATD to initialize ATD

EnableInterrupts;

// Global level of interrupt enable

position(1,0);

LCDputs(Row1_Msg);

position(2,0);

LCDputs(Row2_Msg);

position(3,0);

LCDputs(Row3_Msg);

for(;;)

{

position(1,7);

select = ((iValue & 0x03FF)-102)/2;

lcd_printd(select);

// Display messages on LCD

/* Fill in if...else if...else statements and the codes used to display LED status here. Besides

turning ON/OFF LEDs, display on the proper positions the strings ON and OFF for HEAT, A/C and

FAN on the

LCD

. */

} // end of infinite for loop

}

// ATD Interrupt Service Routine

#pragma CODE_SEG NON_BANKED

interrupt (((0x10000 - 0xFFD2) / 2 ) - 1 ) void isrATD(void)

{

iValue = ATDDR0;

// read conversion result, save to iValue

// PTT = (ATDDR0)&0xF0;

ATDSTAT0_SCF = 1;

// clear conv seq complete flag

ATDCTL5 = 1; //start another conversion

}

#pragma CODE_SEG DEFAULT

/******************** functions **********************/

// ATD Initialization

void init_ATD(void)

{

ATDCTL1_SRES = 1; // 10-bit results

ATDCTL2_ASCIE = 1;

// enable interrupt

ATDSTAT2 = 0;

ATDCTL3_DJM = 1; // right justified data

ATDCTL3_S8C = 0; // one conversion per sequence

ATDCTL3_S4C = 0; // one conversion per sequence

ATDCTL3_S2C = 0; // one conversion per sequence

ATDCTL3_S1C = 1; // one conversion per sequence

ATDCTL4_PRS = 11; // bus clk div 24, = ATD clock

ATDCTL4_SMP = 4; // 12 ATD clock cycle to sample

ATDSTAT0_SCF = 1;

// clear conversion complete flag

ATDCTL5 = 1; // select channel 1 - starts first conversion

}

// This function configures the clock module to use an external oscillator (8 MHz).

// PLL is configured to triple the oscillator frequency for bus frequency (24 MHz).

// It waits until the clock is stable before returning from the function.

void init_PLL(void)

{

CPMUPROT = 0x26;

// write 0x26 disables clock protection

CPMUOSC_OSCE = 1;

// use external oscillator

CPMUREFDIV = 0xC7;

// set PLL divisor to 8

CPMUSYNR = 0x57;

// set PLL multiplier to 24

CPMUPOSTDIV = 0x00; // set POSTDIV to 1

CPMUCLKS_PLLSEL = 1; // use PLL output as system clock

while(!CPMUFLG_UPOSC || !CPMUFLG_LOCK); // wait for PLL to lock

CPMUPROT = 0x01;

// enable protection for CMPU registers

}

void initPorts( )

{

unsigned char cValue;

DDRT = 0xF0; // set PORT T -T4 as output (LEDs)

PTT = 0xF0; // turn off all LEDs

DDRB = 0x80; // LCD CSB active low

DDRC = 0xFF; // PC7-PC4 - 4-bit LCD data bus, PC2 - E, PC1 - R/W~, PC0 - RS: all outputs

cValue = PORTB;

PORTB = cValue | 0x00; // LCD CSB (PORT B7) enabled with a logic low

}

// sends initialization commands one-by-one

void initLCD( )

{

unsigned char i;

for (i=0;i<=19;i++)

{

cmdwrt(cInit_commands[i]);

}

}

// sends a control word to LCD bus

void cmdwrt(unsigned char cCtrlword)

{

PORTC = cCtrlword;

// output command onto LCD data pins

PORTC = cCtrlword + cE;

// generate enable pulse to latch it (xxxx x100)

delay1u( );

// hold it for 1us

PORTC = cCtrlword;

// end enable pulse (xxxx x000)

delay2m();

// allow 2ms to latch command inside LCD

PORTC = 0x00;

delay2m();

// allow 2ms to latch command inside LCD

}

void position(int iRow_value, int iCol_value)

{

int iPos_h, iPos_l, iValue;

if(iRow_value == 1) iValue = (0x80+0x00);

if(iRow_value == 2) iValue = (0x80+0x10);

if(iRow_value == 3) iValue = (0x80+0x20);

iPos_h=((iValue + iCol_value) & 0xF0);

iPos_l=((iValue + iCol_value) & 0x0F) << 4;

cmdwrt(iPos_h);

cmdwrt(iPos_l);

}

//Sends a string of characters to the LCD;...

void LCDputs(char *sptr)

{

while(*sptr)

{ //...the string must end in a 0x00 (null character)

datawrt(*sptr); // sptr is a pointer to the characters in the string

++sptr;

}

}

//Sends a single character to the LCD;...

void LCDputch(char cValues)

{

datawrt(cValues); // single character value

}

// sends the character passed in by caller to LCD

void datawrt(char cAscii)

{

char cAscii_high, cAscii_low;

cAscii_high = (cAscii & 0xF0);

cAscii_low = (cAscii & 0x0F) << 4; // Shift left by 4 bits

PORTC = cAscii_high; // output ASCII character upper nibble onto LCD data pins

PORTC = cAscii_high + cRS + cE; // generate enable pulse to latch it (0xxx x101)

delay1u( );

// hold it for 1us

PORTC = cAscii_high + cRS; // end enable pulse (0xxx x001)

delay1u( );

// hold it for 1us

PORTC = cAscii_low; // output ASCII character lower nibble onto LCD data pins

PORTC = cAscii_low + cRS + cE; // generate enable pulse to latch it (0xxx x101)

delay1u( );

// hold it for 1us

PORTC = cAscii_low + cRS; // end enable pulse (0xxx x001)

delay100u( ); // allow 100us to latch data inside LCD

}

void delay1u( )

{

unsigned int i;

for(i=0;i<=0x0f;i++)

{ /* adjust condition field for delay time */

asm("nop");

}

}

void delay100u( )

{

unsigned int i,j;

for(i=0;i<=0x02;i++)

{

/* adjust condition field for delay time */

for(j=0;j<=0xff;j++)

{

asm("nop");

}

}

}

void delay2m( )

{

unsigned int i,j;

for (i=0;i<=0x20;i++)

{ /* adjust condition field for delay time */

for (j=0;j<=0xff;j++)

{

asm("nop");

}

}

}

void delays(int k )

{

unsigned int i,j;

for (i=0;i<=k;i++)

{ /* adjust condition field for delay time */

for (j=0;j<=0xff;j++)

{

asm("nop");

}

}

}

void lcd_printd(unsigned int val){ //displays 3 digit hex as decimal to lcd

unsigned char i;

unsigned int valcopy; // abbreviations: R=remainder, Q=quotient

char dig[3] ; // storage for R.'s

valcopy = val; // successive /10 to generate R.'s

i = 0;

while (i<2){ // keep looping until Q. drops to 0

val /= 10; // 1st Q., next Q., etc.

dig[i++] = (char)(valcopy % 10); // 1st R., store it, next R..etc.

valcopy = val; // copy of 1st Q., copy of next Q., etc.

}

i=2; // select location after last R.

while(i){ // convert & output remainders (digits), last to first

dig[--i] += 0x30;

// convert to ASCII numeral and...

LCDputch(dig[i]); // send dig[1] and dig[0] out to lcd

}

}

/************************* end of file ***************************/

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Optimizing Data Collection In Warzones

Authors: Aaget Aamber

1st Edition

B0CQRRFP5F, 979-8869065902

More Books

Students also viewed these Databases questions

Question

=+ Who has this information?

Answered: 1 week ago