Using CodeWarrior and C Language to program a HCS12 Microcontroller Write a prog
ID: 3734289 • Letter: U
Question
Using CodeWarrior and C Language to program a HCS12 Microcontroller
Write a program to make a TV remote control by doing the following :
when you press a key 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 7-segment 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 one of the dip switches to turn off and on the remote
Explanation / Answer
public class TVRemote implements RemoteControl
{
private boolean power;
private boolean muted;
private int MIN_CHANNEL = 2;
private int MAX_CHANNEL = 10;
private int channel;
private int MIN_VOLUME = 0;
private int MAX_VOLUME = 10;
private int volume;
private boolean checkMute = true; // added to check if muted is true or false
public TVRemote()
{
boolean power = false;
muted = false;
channel =MIN_CHANNEL;
volume = MIN_VOLUME;
}
public boolean getPower()
{
return power;
}
public boolean getMuted()
{
return muted;
}
public int getChannel()
{
return channel;
}
public int getVolume ()
{
return volume;
}
public void powerOnOff()
{
if (power)
muted = muted;
else
power =! power;
}
public void mute ()
{
if (power)
muted =!muted;
}
public void channelUp ()
{
if (power)
{
if (channel == MAX_CHANNEL)
{
channel = MIN_CHANNEL;
}
else
{
channel++;
}
}
}
public void channelDown()
{
if (power)
{
if (channel == MIN_CHANNEL)
{
channel = MAX_CHANNEL;
}
else
{
channel--;
}
}
}
public void volumeUp ()
{
if (power)
{
if (muted == checkMute || volume = MAX_VOLUME) // check if tv is muted 'OR' at MAX_VOLUME
{
System.out.println("Volume is maxxed, or tv is muted");
}
else
{
volume++;
}
}
public void volumeDown ()
{
if (power)
{
if (muted == checkMute || volume = MIN_VOLUME) // check if tv is muted 'OR' at MIN_VOLUME
{
System.out.println("Volume is at min., or tv is muted");
}
else
{
volume--;
}
}
}
}