Using the Analog to Digital Converter (ADC) for the QE Microcontrollers
QE128 Quick Reference User Guide, Rev. 1.0
Freescale Semiconductor
8-5
NOTE
This example is developed using the CodeWarrior version 6.0 for the
HCS08 and V1 families. It is expressly made for the MCF51QE128 and
MC9S08QE128 (80-pin package). There may be changes needed in the
code to initialize another MCU.
Figure 8-1
, shows the hardware connections used for the ADC project, for
detailed information about the MCU hardware needed, please refer to the
Pins and Connections chapter in the Reference Manual. It can be found at
www.freescale.com.
8.3
ADC project for Demo board
8.3.1
Code Example and Explanation
This example code is available from the Freescale Web site www.freescale.com.
This section explains the differences of codes using an EVB and Demo board. The codes are the same.
The project file contains the following functions:
•
Main — Endless loop waiting for the ADC interrupt to occur.
•
MCU_Init – MCU initialization, watchdog disable and the ADC clock module enabled.
•
GPIO_Init – Configure PTC0 to PTC5, PTE6 and PTE7 as as outputs.
•
ADC_Init – ADC module configuration.
•
ADC_ISR — The data obtained by the ADC module is displayed on PTC0 to PTC5 pins, PTE6 and
PTE7 pins.
This is the General Purpose Input/Output configuration. These code lines configure the direction for the
PTC port. Only six LEDs from the demo board are connected to the PTC port. The other two LEDs are
connected to port E. In this example the PTC0 to PTC5, and PTE6, PTE7 are configured as outputs in order
to drive LEDs.
void GPIO_Init(void) {
PTCDD = (UINT8) (PTCD | 0x3F); // Configure PTC0-PTC5 as outputs
PTEDD = (UINT8) (PTED | 0xC0); // Configure PTE6 and PTE7 pins as outputs
PTCD = 0x3F; // Put 1's in port C in order to turn off the LEDs
PTED = 0xC0; // Put 1's in port E in order to turn off the LEDs
}
NOTE
This is the ADC interrupt service routine. Every time an interrupt is
detected, this routine displays the converted value in eight LEDs. The
VectorNumber_Vadc can be replaced by the interrupt vector number, this
depends if the MCU is S08 or V1. Using these example makes the code fully
compatible for either MCU.
void interrupt VectorNumber_Vadc ADC_ISR(void) {
// ADC vector address = 19 (S08)
// ADC vector address = 81 (V1)