Pages

Micro Search Engine

Custom Search
Welcome To Microcontroller And Interfacing Programming

My Map

My Translator

Showing posts with label ATmega. Show all posts
Showing posts with label ATmega. Show all posts

Saturday, 19 March 2011

Infrared and Ultrasonic Scanner Using ATMega

This is a project that is a short range, infrared and ultrasonic scanner that uses a standard hobby servo to move the sensors and a color LCD screen to display the information from the distance sensors. The information displayed on the LCD is an overhead view of the scanning area, with increments of distance from the distance sensors. This is the figure of the project;
 

The core of the project is the ATMEGA32 microcontroller from Atmel. It controls the servo, gathers information from the sensors and places the information on the LCD screen. There is 32K of flash in the microcontroller and the software uses about 13K of that. Since the LCD uses a maximum of 3.3V, the microcontroller is run at 3.3V.

Read More...

Sunday, 13 December 2009

Interface Keypad to ATmega 8535


Basically keypad is a number of buttons compiled in such a manner so that forms formation of numeral button and some other menus. Many types of keypad that can be use for interface to microcontroller. Keypad needed to interaction with system, for example we make setting with set-point would a control feedback at the time of program still run.



Actually every programmer has different way interaction to with system. Even for keypad in hardware every programmer can differ in. This thing is more because of different requirement.

Keypad 4×4 very often applied by programmer. Besides its the hardware easy, software nor hard. Basically keypad 4×4 is 16 push-button stringed up in matrix. Interfacing keypad 4×4 with pattern scanning hardly easy to be done. Besides having to has keypad 4×4, we only require a diode as supporter component. Diode applied is 1N4001 attached by series with K1, K2, K3 and K4 with part of Anode.

Compiler program keypad by using in codevision AVR.
#include
// Alphanumeric LCD Module functions
#asm
.equ_lcd_port=0×15
#endasm
#include
//Declare your global variables here
Unsigned char dt, dtkey;
Void detect_key (void);
Void main(void)
{
//Declare your local variables here
// Input/Output Ports initialization
// Port A initialization
// Func7=On Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In
// State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=T
PORTA=0×00;
DDRA=0×00;
// Port B initialization
// Func7=On Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In
// State7=0 State6=0 State5=0 State4=0 State3=0 State2=0 State1=0 State0=0
PORTB=0×00;
DDRB=0×00;
// Port C initialization
// Func7=On Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In
// State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=T
PORTC=0×00;
DDRC=0×00;
// Port D initialization
// Func7=On Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In
// State7=P State6=P State5=P State4=P State3=P State2=P State1=P State0=P
PORTD=0×00;
DDRD=0×00;
// Timer/Counter 0 Initialization
// Clock source: System Clock
// Clock value: Timer 0 Stopped
// Mode: Normal top=FFh
// OC0 output: Disconnected
TCCR0=0×00;
TCNT0=0×00;
OCR0=0×00;
// Timer/Counter 1 Initialization
// Clock source: System Clock
// Clock value: Timer 1 Stopped
// Mode: Normal top=FFFFh
// OC1A output: Discon.
// OC1B output: Discon.
// Noise Canceler: Off
// Input Capture on Falling Edge
TCCR1A=0×00;
TCCR1B=0×00;
TCNT1H=0×00;
TCNT1L=0×00;
ICR1H=0×00;
ICR1L=0×00;
OCR1AH=0×00;
OCR1AL=0×00;
OCR1BH=0×00;
OCR1BL=0×00;
// Timer/Counter 2 Initialization
// Clock source: System Clock
// Clock value: Timer 2 Stopped
// Mode: Normal top=FFh
// OC2 output: Disconnected
ASSR=0×00;
TCCR2=0×00;
TCNT2=0×00;
OCR2=0×00;
// External Interrupt(s) initialization
// INT0: Off
// INT1: Off
// INT2: Off
MCUCR=0×00;
MCUCSR=0×00;
// Timer (s) / Counter (s) Interrupt (s) initialization
TIMSK=0×00;
// Analog Comparator initialization
// Analog Comparator: Off
// Analog Comparator Input Capture by Timer/Counter 1: Off
ACSR=0×80;
SFIOR=0×00;
LCD module initialization
lcd_init(16);
lcd_gotoxy(0,0);
lcd_puts(“Keypad to LCD…”);
lcd_gotoxy(0,1);
lcd_putsf(“Pad”);
while (1)
// Place your code here
Detect_key();
lcd_gotoxy(7,1);
sprint(buf, “%x hex”, dtkey);
lcd_puts(buf);
delay_ms(5);
};
}
Void detect_key(void) {
PORTD.4=0
Dt=(~PIND & 0×0F);
Switch (dt) {
Case1: dtkey=0×1;
Break;
Case2: dtkey=0×4;
Break;
Case4: dtkey=0×7;
Break;
Case8: dtkey=0xa;
Break;
};
PORTD.5=1; PORTD6=0;
Dt=(~PIND & 0×0F);
Switch (dt) {
Case 1: dtkey=0×3;
Break;
Case 2: dtkey=0×6;
Break;
Case 4: dtkey=0×9;
Break;
Case 8: dtkey=0xb;
Break;
};
PORTD.6=1; PORTD.7=0;
Dt=(~PIND & 0×0F);
Switch (dt) {
Case1: dtkey=0xc;
Break;
Case2: dtkey=0xd;
Break;
Case4: dtkey=0xe;
Break;
Case8: dtkey=0xf;
Break;
};
PORTD.7=1;
}


Read More...

Saturday, 7 November 2009

Temperature Sensor Using ATmega8

This is design for temperature sensor that is based ATMega 8. LM35 is using for sensing the temperature. This IC is cheaper than the price of this component is also easy to be in the market. This is the figure of the circuit.


LM35 have 10mV voltage change per 1 degree centigrade. LM35, in principle, given the voltage + Vs and GND, the voltage Vout will issue of
Vout = surrounding temperature (centigrade) x 10mV.
on the # include “lcd.h” you can download click here.

This is source code from this project in AVR-GCC format.

#include
#include
#include
#include
#include “lcd.h” //header lcd
volatile unsigned char suhu; //variabel store adc
//deklarasi lcd to stdio
static int lcd_putchar(char c, FILE *stream); //prototype
static FILE mystdout = FDEV_SETUP_STREAM(lcd_putchar, NULL,_FDEV_SETUP_WRITE); static int lcd_putchar(char c, FILE *stream)
{
if (c == ‘\n’) lcd_putchar(’\r’, stream);
LCD_send_char(c);
return(0);
}
//fungsi delay mili sekon
void delay_ms(int ms)
{for(int i=0;i<=ms;i++){_delay_ms(1);};
}
void adc_init(void) //inisialisasi lcd
{ ADMUX =(1<<
|(1<
|(0<<<<
ADCSRA =(1<<<
|(1<<<
sei ();
}
ISR(ADC_vect)
{ suhu=ADCH;
LCD_send_command(0xc0); //cursor line2
printf(”sekarang:%3d c”,suhu);
return;
}
int main (void)
{ adc_init();
delay_ms(200);
LCD_init();
stdout = &mystdout;
LCD_send_command(LCD_CLR);
LCD_send_command(LCD_HOME);
LCD_send_command(0×80); //cursor line1
printf(”suhu ruangan ini”);
LCD_send_command(0xc0); //cursor line2
printf(”sekarang:%3d c “,suhu);
while(1){
ADCSRA|=(1<
delay_ms(500);
}
return(0);
}

Read More...

Wednesday, 21 October 2009

Analog to Digital Converter (ADC) Circuit Using ATmega8

An analog to digital converter converts an analog input voltage into a digital value. This is a circuit for shows the analog to digital converter. This circuit is using microcontroller ATmega8 for control the operation. This is the figure of the circuit.


The resolution of the converter indicates the number of discrete values it can produce. It is usually expressed in bits. For example, an ADC that encodes an analog input to one of 256 discrete values has a resolution of eight bits, 28 = 256. Most ADCs are linear, which means that they are designed to produce an output value that is a linear function of, i.e. proportional to, the input. In this circuit, Atmega8 has 6 AD-converters which have a resolution of 10 bits so it has 210 = 1024 discrete values. In his example a potentiometer is connected to the portC.0 of the Mega8 and a LCD module of 20x4 characters is connected to port D. The LCD module displays the values that are measured on the ADC port. The values are presented on the display as discrete values (0 to 1023), the percentage (0 to 100%) of the values and in a bargraph display.

Read More...

Sunday, 4 January 2009

Programming LCD AVR ATmega8535

This is an example programming C for interfacing microcontroler to LCD at AVR ATmega8535


#include

// Alphanumeric LCD Module functions

#asm

.equ_lcd_port=0x15 ;PORTC

#endasm

#include

//Declare your global variables here

Void main(void)

{

//Declare your local variables here

// Input/Output Ports initialization

// Port A initialization

// Func7=On Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In

// State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=T

PORTA=0x00;

DDRA=0x00;

// Port B initialization

// Func7=On Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In

// State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=T

PORTB=0x00;

DDRB=0x00;

// Port C initialization

// Func7=On Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In

// State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=T

PORTC=0x00;

DDRC=0x00;

// Port D initialization

// Func7=On Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In

// State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=T

PORTD=0x00;

DDRD=0x00;

// Timer/Counter 0 Initialization

// Clock source: System Clock

// Clock value: Timer 0 Stopped

// Mode: Normal top=FFh

// OC0 output: Disconnected

TCCR0=0x00;

TCNT0=0x00;

OCR0=0x00;

// Timer/Counter 1 Initialization

// Clock source: System Clock

// Clock value: Timer 1 Stopped

// Mode: Normal top=FFFFh

// OC1A output: Discon.

// OC1B output: Discon.

// Noise Canceler: Off

// Input Capture on Falling Edge

// Timer 1 Overflow Interrupt: Off

// Input Capture Interrupt: Off

// Compare A Match Interrupt: Off

// Compare B Match Interrupt: Off

TCCR1A=0x00;

TCCR1B=0x00;

TCNT1H=0x00;

TCNT1L=0x00;

ICR1H=0x00;

ICR1L=0x00;

OCR1AH=0x00;

OCR1AL=0x00;

OCR1BH=0x00;

OCR1BL=0x00;

// Timer/Counter 2 Initialization

// Clock source: System Clock

// Clock value: Timer 2 Stopped

// Mode: Normal top=FFh

// OC2 output: Disconnected

ASSR=0x00;

TCCR2=0x00;

TCNT2=0x00;

OCR2=0x00;

// External Interrupt(s) initialization

// INT0: Off

// INT1: Off

// INT2: Off

MCUCR=0x00;

MCUCSR=0x00;

// Analog Comparator initialization

// Analog Comparator: Off

// Analog Comparator Input Capture by Timer/Counter 1: Off

ACSR=0x80;

SFIOR=0x00;

LCD module initialization

lcd_init(16); //initialization LCD

lcd_gotoxy(0,0); //locate position in 0,0

//columns 0, lines 0

lcd_puts(“Hallo…”); //display string Hallo…

lcd_gotoxy(0,1); //locate position

//columns 0, lines 1

lcd_putsf(“My name is Rico”); //display string

while (1)

{

// Place your code here

};

}

Read More...

Interfacing LCD to Microcontroller ATmega8535

LCD hardly assists in program because we don't apply debugging program. We need to present result of the calculations, contents of variable or need of other debug to LCD to know program process which we are create. LCD applicable to present result of retrieval of data from sensor even interaction applicable to between the microcontrollers with man.


LCD which there is marketing generally has consumption of low power as well as easy to be operated. At interfacing circuit, LCD doesn't require many supporter components. We only require one resistors and one Variable Resistor to give tension which contrast at LCD matrix. To explain about pins which there is in LCD we can see in tables of under this:




Interfacing LCD to Microcontroller Schematic


LCD display module is have been equip with a controller having two registers 8 bit that is instruction register (I) and data register (DR). I saving instruction code, as display clear, cursor shift and information address to display data RAM (DDRAM) and character generator (CGRAM). Louvre Data Display (DDRAM) save the display data in the form of character code 8 bit. Its(the capacities is 80 characters. Character Generator ROM (CGROM) will yield character with format 5x8 dot or 5x10 dot. Sees tables Format Character CGROM;

Character Louvre Generator (CGRAM)


With CGRAM, user can make itself character format wanted. For format 5x8 dot can be made 8 characters, for format 5x10 can be made 4 characters.



Read More...

Interfacing Keypad to Microcontroller AVR ATmega8535

Basically key pad is a number of buttons compiled in such a manner so that forms formation of numeral button and some other menus. Following is example configuration of key pad 4x4. Keypad needed to interaction with system, for example we make setting with set-point would a control feedback at the time of program still run. Actually every programmer has different way interaction to with system. Even for keypad in hardware every programmer can differ in. This thing is more because of different requirement.

Keypad 4x4 very often applied by programmer. Besides its the hardware easy, software nor hard. Basically keypad 4x4 is 16 push-button stringed up in matrix. Interfacing keypad 4x4 with pattern scanning hardly easy to be done. Besides having to has keypad 4x4, we only require a diode as supporter component. Diode applied is 1N4001 attached by series with K1, K2, K3 and K4 with part of Anode.


Interfacing Schematic for Keypad at Microcontroller ATmega8535:



After having keypad network 4x4, we will try does program by using keypad.

#include

// Alphanumeric LCD Module functions

#asm

.equ_lcd_port=0x15

#endasm

#include

//Declare your global variables here

Unsigned char dt, dtkey;

Void detect_key (void);

Void main(void)

{

//Declare your local variables here

// Input/Output Ports initialization

// Port A initialization

// Func7=On Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In

// State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=T

PORTA=0x00;

DDRA=0x00;

// Port B initialization

// Func7=On Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In

// State7=0 State6=0 State5=0 State4=0 State3=0 State2=0 State1=0 State0=0

PORTB=0x00;

DDRB=0x00;

// Port C initialization

// Func7=On Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In

// State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=T

PORTC=0x00;

DDRC=0x00;

// Port D initialization

// Func7=On Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In

// State7=P State6=P State5=P State4=P State3=P State2=P State1=P State0=P

PORTD=0x00;

DDRD=0x00;

// Timer/Counter 0 Initialization

// Clock source: System Clock

// Clock value: Timer 0 Stopped

// Mode: Normal top=FFh

// OC0 output: Disconnected

TCCR0=0x00;

TCNT0=0x00;

OCR0=0x00;

// Timer/Counter 1 Initialization

// Clock source: System Clock

// Clock value: Timer 1 Stopped

// Mode: Normal top=FFFFh

// OC1A output: Discon.

// OC1B output: Discon.

// Noise Canceler: Off

// Input Capture on Falling Edge

TCCR1A=0x00;

TCCR1B=0x00;

TCNT1H=0x00;

TCNT1L=0x00;

ICR1H=0x00;

ICR1L=0x00;

OCR1AH=0x00;

OCR1AL=0x00;

OCR1BH=0x00;

OCR1BL=0x00;

// Timer/Counter 2 Initialization

// Clock source: System Clock

// Clock value: Timer 2 Stopped

// Mode: Normal top=FFh

// OC2 output: Disconnected

ASSR=0x00;

TCCR2=0x00;

TCNT2=0x00;

OCR2=0x00;

// External Interrupt(s) initialization

// INT0: Off

// INT1: Off

// INT2: Off

MCUCR=0x00;

MCUCSR=0x00;

// Timer (s) / Counter (s) Interrupt (s) initialization

TIMSK=0x00;

// Analog Comparator initialization

// Analog Comparator: Off

// Analog Comparator Input Capture by Timer/Counter 1: Off

ACSR=0x80;

SFIOR=0x00;

LCD module initialization

lcd_init(16);

lcd_gotoxy(0,0);

lcd_puts(“Keypad to LCD…”);

lcd_gotoxy(0,1);

lcd_putsf(“Pad”);

while (1)

// Place your code here

Detect_key();

lcd_gotoxy(7,1);

sprint(buf, “%x hex”, dtkey);

lcd_puts(buf);

delay_ms(5);

};

}

Void detect_key(void) {

PORTD.4=0

Dt=(~PIND & 0x0F);

Switch (dt) {

Case1: dtkey=0x1;

Break;

Case2: dtkey=0x4;

Break;

Case4: dtkey=0x7;

Break;

Case8: dtkey=0xa;

Break;

};

PORTD.5=1; PORTD6=0;

Dt=(~PIND & 0x0F);

Switch (dt) {

Case 1: dtkey=0x3;

Break;

Case 2: dtkey=0x6;

Break;

Case 4: dtkey=0x9;

Break;

Case 8: dtkey=0xb;

Break;

};

PORTD.6=1; PORTD.7=0;

Dt=(~PIND & 0x0F);

Switch (dt) {

Case1: dtkey=0xc;

Break;

Case2: dtkey=0xd;

Break;

Case4: dtkey=0xe;

Break;

Case8: dtkey=0xf;

Break;

};

PORTD.7=1;

}

Read More...

Sunday, 21 December 2008

Structure Programming C for ATMega8535


Writing structures of language C in general is consisted of 4 blocks:


1. Header.

2. Constanta declaration global and or variable.

3. Function and or procedure (this can be written under principal program).

4. Principal program.


In general, programming C was simplest programming to be done with only writes down main program only, that is:

Void main (void)

{

….

}

The full programming done is:

/*HEADER for call library that will used*/

#include

#include

/*Constanta declaration and or global variable */

Unsigned char dt, xx;

Char buf[33];

/* Function declaration and or procedure */

Unsigned char lamp (unsigned char bitn)

{

PORTA=bitn & 0x3C;

}

/*Main program */

Void main (void);

/* Constanta declaration and or local variable */

Char data;

PORTA=0x00;

DDRA=0xF0;

While (1)

{

…

};

}

Read More...

My Ranks