18
Microcontroller Programming ( ) 주주주주

Microcontroller Programming ( 주 ) 한백전자 Atmega128

Embed Size (px)

Citation preview

Page 1: Microcontroller Programming ( 주 ) 한백전자 Atmega128

Microcontroller Programming

( 주 ) 한백전자

Page 2: Microcontroller Programming ( 주 ) 한백전자 Atmega128

Atmega128

Page 3: Microcontroller Programming ( 주 ) 한백전자 Atmega128

AVR – Atmega128L

High-performance, Low-power AVR® 8-bit Microcontroller

Advanced RISC Architecture Up to 16 MIPS Throughput at 16 MHz

128K Bytes of In-System Reprogrammable Flash 4K Bytes Internal SRAM

4K Bytes EEPROM

Peripheral Features 4 Timer

10bit – ADC 8 channel

SPI, I2C, UART Interface

Six Sleep Modes

Page 4: Microcontroller Programming ( 주 ) 한백전자 Atmega128

GPIO

General Purpose Input/Output It can act as input to read digital signal from other devices

Or it can act as output to control 0 or 1 to outside

Important Registers for GPIO in Atmega128 DDx: setting input or output direction

PORTx: Input: pull-up resistor on/off

Output: signal 0 or 1

PINx: read input signal

Page 5: Microcontroller Programming ( 주 ) 한백전자 Atmega128

Atmega 128’ GPIO

Page 6: Microcontroller Programming ( 주 ) 한백전자 Atmega128

ZigbeX MCU Circuit

Page 7: Microcontroller Programming ( 주 ) 한백전자 Atmega128

LED Circuit

Page 8: Microcontroller Programming ( 주 ) 한백전자 Atmega128

Programming 3 LED On

1. Make new c file

2. Search GPIO registers

3. Setting register

4. Compile with avr-gcc

• avr-gcc -o output -Os -mmcu=atmega128 main.c xxx.c

• avr-objcopy -O ihex output main.hex

Page 9: Microcontroller Programming ( 주 ) 한백전자 Atmega128

Implement 3 LED on

Page 10: Microcontroller Programming ( 주 ) 한백전자 Atmega128

Timer

ZigbeX utilizes two Clocks 7,372,800 Hz: Main clock

32,768 Hz: Timer 0 clock

Page 11: Microcontroller Programming ( 주 ) 한백전자 Atmega128

Timer Interrupt 1

Overflow Interrupt

Page 12: Microcontroller Programming ( 주 ) 한백전자 Atmega128

Timer Interrupt 2

Compare Interrupt

Page 13: Microcontroller Programming ( 주 ) 한백전자 Atmega128

Atmega 128 interrupt

#define SIG_INTERRUPT0 _VECTOR(1)#define SIG_INTERRUPT1 _VECTOR(2)#define SIG_INTERRUPT2 _VECTOR(3)#define SIG_INTERRUPT3 _VECTOR(4)#define SIG_INTERRUPT4 _VECTOR(5)#define SIG_INTERRUPT5 _VECTOR(6)#define SIG_INTERRUPT6 _VECTOR(7)#define SIG_INTERRUPT7 _VECTOR(8)#define SIG_OUTPUT_COMPARE2 _VECTOR(9)#define SIG_OVERFLOW2 _VECTOR(10)#define SIG_INPUT_CAPTURE1 _VECTOR(11)#define SIG_OUTPUT_COMPARE1A _VECTOR(12)#define SIG_OUTPUT_COMPARE1B _VECTOR(13)#define SIG_OVERFLOW1 _VECTOR(14)#define SIG_OUTPUT_COMPARE0 _VECTOR(15)#define SIG_OVERFLOW0 _VECTOR(16)#define SIG_SPI _VECTOR(17)#define SIG_UART0_RECV _VECTOR(18)#define SIG_UART0_DATA _VECTOR(19)#define SIG_UART0_TRANS _VECTOR(20)#define SIG_ADC _VECTOR(21)

Page 14: Microcontroller Programming ( 주 ) 한백전자 Atmega128

Example Timer 0 interrupt

Timer0 Compare interrupt

char status = 0;INTERRUPT(SIG_OUTPUT_COMPARE0) {

if(status == 0){TOSH_CLR_YELLOW_LED_PIN();status = 1;

}else{TOSH_SET_YELLOW_LED_PIN();status = 0;

}}

}

Page 15: Microcontroller Programming ( 주 ) 한백전자 Atmega128

Implement Timer 0

Limitation Utilize 32,768 Khz

Utilize compare register

Operation When turn on power, on Red LED

After setting timer registers, on Green LED

Whenever expire 200ms, toggle LED

Page 16: Microcontroller Programming ( 주 ) 한백전자 Atmega128

Programming Timer 0 (200ms)

1. Make new c file

2. Includes: #include <avr/io.h>, #include <avr/signal.h>, #include

<avr/interrupt.h>

3. Search Timer registers

4. Setting register

5. Descript “interrupt hander”

6. Compile with avr-gcc

• avr-gcc -o output -Os -mmcu=atmega128 main.c xxx.c

• avr-objcopy -O ihex output main.hex

Page 17: Microcontroller Programming ( 주 ) 한백전자 Atmega128

Q & A

Page 18: Microcontroller Programming ( 주 ) 한백전자 Atmega128

HomeWorks

until 1/15 Implement Timer 0 example

until 1/19 Implement Timer Component having 3 interfaces

Use timer0 only

Timer unit is ms

Max timer setting value is 30000

Use C language only.

Hits: refer to TimerM component in TinyOS-1.x