View
234
Download
1
Category
Preview:
Citation preview
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
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
Atmega 128’ GPIO
ZigbeX MCU Circuit
LED Circuit
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
Implement 3 LED on
Timer
ZigbeX utilizes two Clocks 7,372,800 Hz: Main clock
32,768 Hz: Timer 0 clock
Timer Interrupt 1
Overflow Interrupt
Timer Interrupt 2
Compare Interrupt
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)
…
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;
}}
}
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
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
Q & A
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
Recommended