Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

#include //* common defines and macros */ #include derivative.h //* derivative-specific definitions */ #define LCD_DATA PORTK #define LCD_CTRL PORTK #define RS 0x01 #define EN 0x02

#include //* common defines and macros */

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

#define LCD_DATA PORTK

#define LCD_CTRL PORTK

#define RS 0x01

#define EN 0x02

void COMWRT4(unsigned char);

void DATWRT4(unsigned char);

void LCDInit(void);

void LCDStrWrt(unsigned char[]);

void MSDelay(unsigned int);

void seg7(unsigned char, unsigned char);

void buzz(unsigned int);

int key_scan(void);

int get_key(void);

void wait_for_keyup(void);

void main(void) { unsigned int z =0; int key; int max=11; int c; int data; int key0; int key1; int k; unsigned char overflow = 0; unsigned char i; unsigned char digits_7seg [] = {0x3f, 0x06, 0x5b, 0x4f,

0x66, 0x6d, 0x7d, 0x07, 0x7f, 0x6f,

0x77, 0x7c, 0x39, 0x5e, 0x79, 0x71};

unsigned char select_7seg[] = { 0x0e, 0x0d, 0x0b, 0x07 };

DDRB = 0xFF; // PORT B output DDRJ = 0xFF; // PTJ as output to control Dragon12+ LEDs PTJ=0x0; // Allow the LEDs to display data on PORTB pins DDRP = 0xFF; // 7-segment, DDRK = 0xFF; // LCD DDRM = 0xFF; // RGB LED DDRT = DDRT | 0b00100000; // buzzer DDRA = 0x0F; // keypad PUCR=0x01; DDRH=0x0; //Make PTH as input for DIP Switches PIEH = 0xFF; //enable PTH interrupt PPSH = 0XFF; //Make it Edge-Trig. //PORTH interrupt setup TSCR1 = 0x80; //enable timer TSCR2 = 0x04; //Prescaler=16 (Try 0-7 values to see changes on LEDs) __asm CLI; //Enable interrupts globally for (;;){

LCDInit(); // keypad

key= get_key(); if (key ==1){ COMWRT4(0x01); LCDStrWrt("channel 1"); MSDelay(200); wait_for_keyup ; } if (key == 2){ COMWRT4(0x01); LCDStrWrt("channel 2"); MSDelay(200); wait_for_keyup ; } if (key == 3){ COMWRT4(0x01); LCDStrWrt("channel 3"); MSDelay(200); wait_for_keyup ; } if (key == 4) { COMWRT4(0x01); LCDStrWrt("channel 4"); MSDelay(200); wait_for_keyup ; } if ( key == 5) { COMWRT4(0x01); LCDStrWrt("channel 5"); MSDelay(200); wait_for_keyup ; } if ( key == 6) { COMWRT4(0x01); LCDStrWrt("channel 6"); MSDelay(200); wait_for_keyup ; } if ( key == 7) { COMWRT4(0x01); LCDStrWrt("channel 7"); MSDelay(200); wait_for_keyup ; } // sound valume key0= get_key(); key1= get_key(); if(z

interrupt (((0x10000-Vporth)/2)-1) void PORTH_ISR(void){ COMWRT4(0x01); buzz(20); LCDStrWrt("Shut down"); MSDelay(2000);

PIFH = PIFH | 0xFF; //clear PTH Interupt Flags for the next round. Writing HIGH will clear the Interrupt flags }

// ********************* buzz

void buzz(unsigned int delay)

{

unsigned char duration = 25;

while(duration > 0)

{

PTT = PTT | 0x20;

MSDelay(delay);

PTT = PTT & 0xDF;

MSDelay(delay);

duration--;

}

}

// ********************* seg7

void seg7(unsigned char data, unsigned char digit)

{

PORTB = data;

PTP = digit;

MSDelay(1);

}

// ********************* LCDInit

void LCDInit(void)

{

COMWRT4(0x33); //reset sequence provided by data sheet

MSDelay(1);

COMWRT4(0x32); //reset sequence provided by data sheet

MSDelay(1);

COMWRT4(0x28); //Function set to four bit data length

//2 line, 5 x 7 dot format

MSDelay(1);

COMWRT4(0x06); //entry mode set, increment, no shift

MSDelay(1);

COMWRT4(0x0E); //Display set, disp on, cursor on, blink off

MSDelay(1);

COMWRT4(0x01); //Clear display

MSDelay(1);

}

// ********************* LCDStrWrt

void LCDStrWrt(unsigned char msg[])

{

unsigned char i;

for (i=0;msg[i]!='\0';i++)

{

DATWRT4(msg[i]);

MSDelay(1);

}

}

// ********************* COMWRT4

void COMWRT4(unsigned char command)

{

unsigned char x;

x = (command & 0xF0) >> 2; //shift high nibble to center of byte for Pk5-Pk2

LCD_DATA =LCD_DATA & ~0x3C; //clear bits Pk5-Pk2

LCD_DATA = LCD_DATA | x; //sends high nibble to PORTK

MSDelay(1);

LCD_CTRL = LCD_CTRL & ~RS; //set RS to command (RS=0)

MSDelay(1);

LCD_CTRL = LCD_CTRL | EN; //rais enable

MSDelay(5);

LCD_CTRL = LCD_CTRL & ~EN; //Drop enable to capture command

MSDelay(15); //wait

x = (command & 0x0F)<< 2; // shift low nibble to center of byte for Pk5-Pk2

LCD_DATA =LCD_DATA & ~0x3C; //clear bits Pk5-Pk2

LCD_DATA =LCD_DATA | x; //send low nibble to PORTK

LCD_CTRL = LCD_CTRL | EN; //rais enable

MSDelay(5);

LCD_CTRL = LCD_CTRL & ~EN; //drop enable to capture command

MSDelay(15);

}

// ********************* DATWRT4

void DATWRT4(unsigned char data)

{

unsigned char x;

x = (data & 0xF0) >> 2;

LCD_DATA =LCD_DATA & ~0x3C;

LCD_DATA = LCD_DATA | x;

MSDelay(1);

LCD_CTRL = LCD_CTRL | RS;

MSDelay(1);

LCD_CTRL = LCD_CTRL | EN;

MSDelay(1);

LCD_CTRL = LCD_CTRL & ~EN;

MSDelay(5);

x = (data & 0x0F)<< 2;

LCD_DATA =LCD_DATA & ~0x3C;

LCD_DATA = LCD_DATA | x;

LCD_CTRL = LCD_CTRL | EN;

MSDelay(1);

LCD_CTRL = LCD_CTRL & ~EN;

MSDelay(15);

}

/*************** get_key *********************/

int get_key(void)

{

int key; int count;

do {

key = key_scan(); } while (key==15);

return key;

}

/****************** key_scan */

// returns keypress code

int key_scan(void)

{

const char keycodes[] = {

0x7D, 0xEE, 0xED, 0xEB,

0xDE, 0xDD, 0xDB, 0xBE,

0xBD, 0xBB, 0xE7, 0xD7,

0xB7, 0x77, 0x7E, 0x7B

};

int i, j, key;

char readback;

int found;

i = 0;

key = 16; // return 16 if no key pressed

found = 0;

while ((i < 17) && (found == 0))

{

PORTA = keycodes[i]; // write keycode to Port A

for (j=0;j<10;j++); // wait a bit

readback = PORTA; // read back Port A

if (readback == keycodes[i]) // if same, get key number

{

key = i;

found = 1;

} else

i++; // else check next key

} return key;

}

/*********** wait_for_keyup ***********************/

// waits until a key is not being pressed

void wait_for_keyup(void)

{

while(key_scan() != 16) {

}

}

// ********************* delay

void MSDelay(unsigned int itime) //millisec delay

{

unsigned int i; unsigned int j;

for(i=0;i

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

}

fix this code to do the following :

when you press a number in the keypad, the Chanel number will show in the LCD.

Use # and * to turn the volume up and down by using the buzzer to make load and low sound.

use the LED to show how load or low the sound is. For example, the lowest is 1 and the highest is 10 if you press # the number will change to 2 in the LED and the sound will be louder.

Use key 0 to turn the remote control off and on.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered 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

Students also viewed these Databases questions