Presentation is loading. Please wait.

Presentation is loading. Please wait.

AVR 실습.

Similar presentations


Presentation on theme: "AVR 실습."— Presentation transcript:

1 AVR 실습

2

3

4 ESL-ATmega16 ports ATmega16 VCC BIT0 BIT1 BIT2 BIT3 BIT4 BIT5 BIT6
GND PORTB PORTA PORTD PORTC

5 PORT 제어 100ms 마다 PORTC의 LED가 차례로 점멸되는 프로그램을 작성하시오.

6 Char led = 0x01 PORTC=0x0F; DDRC=0xFF; While(1){ // Place your code here PORTC = ~led; delay_ms(100); led<<=1; if(led == 0 ) led = 0x01; }

7 PORT 제어 2 PORTA로 부터 값을 읽어와서. PORTC로 출력하는 프로그램을 작성하시오

8 PORTA=0x00; DDRA=0x00; PORTC=0x0F; DDRC=0xFF; While(1){ PORTC = PINA; }

9 외부 인터럽트 외부 INT0에 달린 스위치를 한번 누를 때 마다 PORTC의 값을 토글 시키는 프로그램
(PORTC 초기값 0xf0)

10 Interrupt setting // External Interrupt(s) initialization // INT0: On
// INT0 Mode: Falling Edge // INT1: Off // INT2: Off GICR|=0x40; MCUCR=0x02; MCUCSR=0x00; GIFR=0x40;

11 Interrupt handler interrupt [EXT_INT0] void ext_int0_isr(void) {
// Place your code here PORTC ^= 0xff; }

12 Lab 1 스위치를 누르고 있는 동안에 500ms 마다 토글되는 프로그램을 작성하시오.

13 외부 인터럽트 셋팅 interrupt [EXT_INT0] void ext_int0_isr(void) {
// Place your code here #asm("cli"); PORTC ^= 0xff; delay_ms(500); #asm("sei") }

14 Lab2 INT0를 누르면 오른쪽으로 쉬프트 되고, INT1버튼을 누르면 왼쪽으로 쉬프트 되는 프로그램을 작성하시오.

15 interrupt [EXT_INT0] void ext_int0_isr(void)
{ // Place your code here led >>=1; if(led == 0) led = 0x01; PORTC = ~led; } // External Interrupt 1 service routine interrupt [EXT_INT1] void ext_int1_isr(void) led <<=1; if(led == 0) led = 0x80;

16 Timer 실습 Timer1을 이용하여 0.1초마다. PORTC의 LED가 순차적으로 점멸하도록 프로그램 하시오.

17 Timer1 Setting // Timer/Counter 1 initialization
// Clock source: System Clock // Clock value: kHz // Mode: CTC top=OCR1A // 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: On // Compare B Match Interrupt: Off TCCR1A=0x00; TCCR1B=0x0D; TCNT1H=0x00; TCNT1L=0x00; ICR1H=0x00; ICR1L=0x00; OCR1AH=0x06; OCR1AL=0x1A; OCR1BH=0x00; OCR1BL=0x00;

18 char led = 0x00; // Timer 1 output compare A interrupt service routine interrupt [TIM1_COMPA] void timer1_compa_isr(void) { // Place your code here led <<=1; if(led == 0) led = 0x01; PORTC = ~led; }

19 ADC ADC0 핀으로 들어오는 값을 ADC를 통하여 8비트 디지털 값으로 변환하여 그 값을 PORTC로 출력하는 프로그램을 작성하라

20 // ADC initialization // ADC Clock frequency: kHz // ADC Voltage Reference: AVCC pin // ADC Auto Trigger Source: Free Running // Only the 8 most significant bits of // the AD conversion result are used ADMUX=ADC_VREF_TYPE; ADCSRA=0xAF; SFIOR&=0x1F; ADCSRA |= 0x40; //start conversion

21 interrupt [ADC_INT] void adc_isr(void) {
unsigned char adc_data; // Read the 8 most significant bits // of the AD conversion result adc_data=ADCH; // Place your code here PORTC = ~adc_data; }


Download ppt "AVR 실습."

Similar presentations


Ads by Google