Presentation is loading. Please wait.

Presentation is loading. Please wait.

충북인력개발원 전자과 공학박사 강원찬 2. Interrupt & LCD. uP AVR (Atmega128) - 2 -

Similar presentations


Presentation on theme: "충북인력개발원 전자과 공학박사 강원찬 2. Interrupt & LCD. uP AVR (Atmega128) - 2 -"— Presentation transcript:

1 충북인력개발원 전자과 공학박사 강원찬 2. Interrupt & LCD

2 uP AVR (Atmega128) - 2 -

3 uP AVR (Atmega128) - 3 -

4 uP AVR (Atmega128) - 4 - 테스트 회로구성 AVR J53 J42 연결 PORTA J34 J30 연결

5 uP AVR (Atmega128) - 5 - AVR Port B J29 연결

6 uP AVR (Atmega128) - 6 - 새 프로젝트 생성 (File->New)

7 uP AVR (Atmega128) - 7 -

8 uP AVR (Atmega128) - 8 - // External Interrupt 4 service routine interrupt [EXT_INT4] void ext_int4_isr(void) { // Place your code here } // External Interrupt 5 service routine interrupt [EXT_INT5] void ext_int5_isr(void) { // Place your code here } EICRA=0x00; EICRB=0x0F; // INT4/5 Mode: Rising Edge EIMSK=0x30; EIFR=0x30; // Global enable interrupts #asm("sei")

9 uP AVR (Atmega128) - 9 - #include // Declare your global variables here unsigned char led=0x0f; unsigned detect=0x00; // External Interrupt 4 service routine interrupt [EXT_INT4] void ext_int4_isr(void) {// Place your code here detect=1; } // External Interrupt 5 service routine interrupt [EXT_INT5] void ext_int5_isr(void) {// Place your code here detect=2; }

10 uP AVR (Atmega128) - 10 - while (1) { if(detect==0) { for(i=0;i<8;i++) { PORTB=led++; PORTA.7=1; PORTA.6=1; delay_ms(100); } } if(detect==1) {PORTB=0xf0; PORTA.6=0; delay_ms(1000); detect=0; } if(detect==2) {PORTB=0x0f; PORTA.7=0; delay_ms(1000); detect=0; } };

11 uP AVR (Atmega128) - 11 - 연습문제 1) SW1~SW6 각 키별 각기 다른 개별 동작을 구현하세요. ( 구별 입력 ) 2) SW1-SW2 동시 입력시 각 키별 각기 다른 개별 동작을 구현하세요.( 통합 입력 ) 3) SW3-SW6 16 가지 입력 상태에 따라 LED 점등 상태로 구별하세요.( 통합입력 )

12 uP AVR (Atmega128) - 12 - PORTA J30 연결

13 uP AVR (Atmega128) - 13 - PORTC J19 연결 [LCD][AVR Port] RS (pin4) ------ bit 0 RD (pin 5) ------bit 1 EN (pin 6) ------bit 2 DB4 (pin 11) ---bit 4 DB5 (pin 12) ---bit 5 DB6 (pin 13) ---bit 6 DB7 (pin 14) ---bit 7

14 uP AVR (Atmega128) - 14 -

15 uP AVR (Atmega128) - 15 - PORTC=0x00; DDRC=0xFF;

16 uP AVR (Atmega128) - 16 - #include // Alphanumeric LCD Module functions #asm.equ __lcd_port=0x15 #endasm #include // 자동삽입 루틴 ============================ // LCD module initialization lcd_init(16); // 자동삽입 루틴 while (1) {};

17 uP AVR (Atmega128) - 17 - LCD Function void _lcd_ready(void) void _lcd_write_data(unsigned char data) void lcd_write_byte(unsigned char addr, unsigned char data); unsigned char lcd_read_byte(unsigned char addr); void lcd_init(unsigned char lcd_columns) void lcd_clear(void) void lcd_gotoxy(unsigned char x, unsigned char y) void lcd_putchar(char c) void lcd_puts(char *str)//SRAM 영역에 데이터 존재 void lcd_putsf(char flash *str) //FLASH 에 데이터존재 ** 적색으로 기재된 명령은 외우세요 !!

18 uP AVR (Atmega128) - 18 - // LCD module initialization lcd_init(16); lcd_gotoxy(0,0); lcd_putsf("LCD test....!"); lcd_gotoxy(0,1); //lcd_data="Now Initialize..."; sprintf(lcd_data,"%s",d1); // lcd_puts(lcd_data); ** ED-4512 키트에서는 호환성 무시되어 사용할 수 없음. 따라서 모든 함수를 무식하게 만들어야 함.

19 uP AVR (Atmega128) - 19 - #include #include #include #include // Alphanumeric LCD Module functions #asm.equ __lcd_port=0x15 ;PORTC #endasm // Declare your global variables here char dd[17]=" ";

20 uP AVR (Atmega128) - 20 - Void main(void) { Int i; lcd_init(16); lcd_gotoxy(0,0); lcd_putsf(“LCD Test….. "); lcd_gotoxy(0,1); lcd_putsf("press any key..."); delay_ms(3000);

21 uP AVR (Atmega128) - 21 - while (1) { for(i=0;i<100;i++) { sprintf(dd,”Time is %3d sec..”, i); lcd_gotoxy(0,1); lcd_puts(dd); delay_ms(1000); } }; }

22 uP AVR (Atmega128) - 22 - 연습문제 1) LCD 에 5 초 간격으로 2 라인씩 글자를 출력 하도록 구현하시오. 2) SW1 을 누르면 카우트 시작, SW2 를 누르면 중지하는 스톱워치를 구현하시오 3) LCD 에 눌려진 키값을 출력하고, LED 로도 다양하게 표현하시오.

23 uP AVR (Atmega128) - 23 - -끝--끝-


Download ppt "충북인력개발원 전자과 공학박사 강원찬 2. Interrupt & LCD. uP AVR (Atmega128) - 2 -"

Similar presentations


Ads by Google