Docsity

Chapter 2: Concepts of Microcontrollers, Exercises of Microcontrollers

Partial preview of the text

Download Chapter 2: Concepts of Microcontrollers and more Exercises Microcontrollers in PDF only on Docsity!

Chapter 2: Concepts of Microcontrollers

1

In this chapter the reader will learn general information about:

  • Connecting LEDs
  • Connecting motors and coils
  • Connecting switches and buttons
  • Connecting keypads
  • Analog to digital conversion
  • Digital to analog conversion
  • Power supplies for embedded systems
  • Clock generation options
  • Reset circuitry

2

RX63N I/O ports

  • Eighteen I/O ports
  • Each port has o Port Direction Register (PDR), o Port Output Data Register (PODR), o Port Mode Register (PMR).

4

Port Direction Register (PDR)

  • This register, as the name suggests, is used to set the data direction (input or output) of a pin.
  • Each bit of the Port Direction Register represents a pin.
  • Set the corresponding bit to 0 to make it input and set the bit to 1 to make it an output pin

Example: Setting Port 4 bit 1 as output

PORT4.PDR.BIT.B1 = 1;

Port Input Register (PIDR)

Port Input Register (PIDR) is used to read the state of a pin

Example: Reading the state of port 4, bit 1and, if it is high, make port D bit 0 high

if(PORT4.PIDR.BIT.B1 == 1) PORTD.PODR.BIT.B0 = 1;

Other Important Registers

Open Drain Control Registers (ODR0/ODR1) Selects the output pin as either CMOS or NMOS open drain

Pull-Up Resistor Control Register (PCR) Used to enable pull-up MOS for a particular pin of a port

Drive Capacity Control Register (DSCR) This register is used to switch the drive capacity of a port

Using LED as an Output

There are two ways in which you can interface an LED with a microcontroller:

The microprocessor is sourcing current to an LED.

Turning on this LED requires a logical HIGH signal on the output pin.

Using LED as an output

The microprocessor is sinking current from the LED.

Turning on the LED requires a logical LOW on the output pin.

Interfacing a matrix keypad

We often find the need for using a Keypad in various applications, The easiest way to use it is using a matrix of switches.

Keypads work as a matrix of buttons. In the previous example: The top three output pins are used as the columns of the matrix A button is placed in the circuit at each intersection of a column and a row One at a time, the output pins turn on and each of the input pins is read. If an input is detected, the microprocessor can determine which button on the keypad had been pressed.

Interfacing a matrix keypad

Interfacing with Analog Signals

Analog Signals must be converted to digital values so that the microcontrollers can process them.

Analog to Digital converters are used to convert analog signals to digital values and Digital to Analog converters are used to convert Digital signals to appropriate analog values.

ADC

ADC is a device that converts a continuous physical quantity (usually voltage) to a digital number that represents the quantity's amplitude.

The number of bits binary number helps determine the resolution or precision of the reading

Types of ADC: Flash Successive approximation ADC Ramp

17

DAC

In systems that control audio, speed, or even light levels; digital output from a microprocessor must be converted into an analog signal.

There are several different methods for converting digital signals to analog.

Resistor Networks Binary Weighted DACs R-2R DAC

19

20

Binary Weighted DAC