On this page I will provide tutorials that can help to start learning a microcontroller. In this tutorial, I will give examples of the application microcontroller programming using C language
Good! ... Let's start learning.
Good! ... Let's start learning.
Now we will learn to use a microcontroller to convert data from analog data into digital data, or better known as the Analog to Digital Conversion (ADC). In this project we will use microcontroller AVR-009 from Circuits-Home. In this tutorial, I will give examples of flame control LED display and control of motor using a potentiometer on the basis of a reference voltage ATmega8535 AVR microcontroller ADC channel.
AVR-009 microcontroller kit (www.circuits-home.com)
Before creating the program, the first job we have to do is understand about the hardware specs.
A. AVR-009 Kit Specifications:
MCU : AVR ATmega8535 (compatible with series MEGA16 and MEGA32)
Crystal : 8 MHz
Pin Description :
• Porta = as channel DC servo motor driver, ADC, and LEDs.
• PORTB = path to programming microcontrollers (MISO, motions, SCK).
• PORTC = connect with a seven segment display unit
• PORTD = connect with DC motor drivers MP and 2 units of tag-switch.
Power: About 5 volts DC.
Once we know the specification of hardware, now let us work on our project.
B. Running Programs CodeVision-AVR:
Step 1 = Run the CodeVisionAVR IDE software.
Step 2 = Make a new project with CodeWizard
Step 3 = Type the code on the text editor That show after you choose "File>> Generate, save, and exit".
C. Example C program:
Next, I provide an example program (in C) use the ADC to control the flame LED display and DC motor (Permanent Magnet) by using the AVR-009 kit. Here's the program.
I. ADC to control the LED display.
#include
#include
#define ADC_VREF_TYPE 0x00
// Read the AD conversion result
unsigned int read_adc(unsigned char adc_input)
{
ADMUX=adc_input | (ADC_VREF_TYPE & 0xff);
delay_us(10); // untuk stabilisasi tegangan input ADC
ADCSRA|=0x40; // Start the AD conversion
while ((ADCSRA & 0x10)==0); // Wait for the AD conversion to complete
ADCSRA|=0x10;
return ADCW;
}
void main(void)
{
DDRA=0xF3;
DDRB=0xFF;
DDRC=0xFF;
DDRD=0x3F;
ADMUX=ADC_VREF_TYPE;
ADCSRA=0x85;
while (1)
{
PORTA.7=~read_adc(2);
}
}
II. ADC to control permanent magnet DC motor rotation.
#include
#include
#define ADC_VREF_TYPE 0x00
#define ENA PORTD.5
// Read the AD conversion result
unsigned int read_adc(unsigned char adc_input)
{
ADMUX=adc_input | (ADC_VREF_TYPE & 0xff);
delay_us(10); // untuk stabilisasi tegangan input ADC
ADCSRA|=0x40; // Start the AD conversion
while ((ADCSRA & 0x10)==0); // Wait for the AD conversion to complete
ADCSRA|=0x10;
return ADCW;
}
void main(void)
{
DDRA=0xF3;
DDRB=0xFF;
DDRC=0xFF;
DDRD=0x3F;
ADMUX=ADC_VREF_TYPE;
ADCSRA=0x85;
while (1)
{
PORTD.4=1;
PORTD.3=0;
ENA=read_adc(2);
}
}
To practice, you need a microcontroller kit.
Hardware:
Software:





