6.3. OUTPUT DEVICES 133
PORTD = PORTD|0x80; //RS=1
PORTD = PORTD|0x40; //E=1
PORTD = PORTD&0xbf; //E=0
delay_5ms();
}
//***************************************************************
//performs specified LCD related command
//***************************************************************
void putcommand(unsigned char d)
{
DDRC = 0xff; //set PORTC as output
DDRD = DDRD|0xC0; //make PORTD[7:6] output
PORTD = PORTD&0x7f; //RS=0
PORTC = d;
PORTD = PORTD|0x40; //E=1
PORTD = PORTD&0xbf; //E=0
delay_5ms();
}
//***************************************************************
6.3.6 HIGH-POWER DC DEVICES
A number of direct current devices may be controlled with an electronic switching device such as
a MOSFET. Specifically, an N-channel enhancement MOSFET (metal oxide semiconductor field
effect transistor) may be used to switch a high-current load on and off (such as a motor) using
a low-current control signal from a microcontroller as shown in Figure 6.13(a). The low-current
control signal from the microcontroller is connected to the gate of the MOSFET. The MOSFET
switches the high-current load on and off consistent with the control signal. The high-current load
is connected between the load supply and the MOSFET drain. It is important to note that the load
supply voltage and the microcontroller supply voltage do not have to be at the same value. When
the control signal on the MOSFET gate is logic high, the load current flows from drain to source.
When the control signal applied to the gate is logic low, no load current flows.Thus, the high-power
load is turned on and off by the low-power control signal from the microcontroller.
Often the MOSFET is used to control a high-power motor load. A motor is a notorious source
of noise. To isolate the microcontroller from the motor noise, an optical isolator may be used as an
interface as shown in Figure 6.13(b). The link between the control signal from the microcontroller

Get Atmel AVR Microcontroller Primer, 2nd Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.