Presentation is loading. Please wait.

Presentation is loading. Please wait.

Microcontroller Programming

Similar presentations


Presentation on theme: "Microcontroller Programming"— Presentation transcript:

1 Microcontroller Programming
(주)한백전자

2 Atmega128

3 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

4 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

5 Atmega 128’ GPIO

6 ZigbeX MCU Circuit

7 LED Circuit

8 Programming 3 LED On Make new c file Search GPIO registers
Setting register Compile with avr-gcc avr-gcc -o output -Os -mmcu=atmega128 main.c xxx.c avr-objcopy -O ihex output main.hex

9 Implement 3 LED on

10 Timer ZigbeX utilizes two Clocks 7,372,800 Hz: Main clock
32,768 Hz: Timer 0 clock

11 Timer Interrupt 1 Overflow Interrupt

12 Timer Interrupt 2 Compare Interrupt

13 Atmega 128 interrupt #define SIG_INTERRUPT0 _VECTOR(1)
#define SIG_OUTPUT_COMPARE2 _VECTOR(9) #define SIG_OVERFLOW _VECTOR(10) #define SIG_INPUT_CAPTURE _VECTOR(11) #define SIG_OUTPUT_COMPARE1A _VECTOR(12) #define SIG_OUTPUT_COMPARE1B _VECTOR(13) #define SIG_OVERFLOW _VECTOR(14) #define SIG_OUTPUT_COMPARE0 _VECTOR(15) #define SIG_OVERFLOW _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)

14 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; }

15 Implement Timer 0 Limitation Operation 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

16 Programming Timer 0 (200ms)
Make new c file Includes: #include <avr/io.h>, #include <avr/signal.h>, #include <avr/interrupt.h> Search Timer registers Setting register Descript “interrupt hander” Compile with avr-gcc avr-gcc -o output -Os -mmcu=atmega128 main.c xxx.c avr-objcopy -O ihex output main.hex

17 Q & A

18 HomeWorks until 1/15 until 1/19
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


Download ppt "Microcontroller Programming"

Similar presentations


Ads by Google