More Related Content Similar to Avr lecture7 (20) More from ๋ด์กฐ ๊น (20) Avr lecture73. --33--20062006--0404--0707
Embedded AVR ProgrammingEmbedded AVR Programming
1-1 Dotmatrix ๊ตฌ๋ ์๋ฆฌ
โ LED๋ฅผ ๋งคํธ๋ฆญ์ค(ํ๋ ฌ)์ ํํ๋ก ๋์ดํ ๊ฒ
- 5ร7, 8ร8, 16ร16 ๋ฑ์ ๋งคํธ๋ฆญ์ค๋ก ์ด๋ฃจ์ด์ง ๊ฒ
โ ์นผ๋ผ ์์ ๋ฐ๋ผ ์ฑ๊ธ(single, ๋จ์)๋๋ ๋ฉํฐ(multi, ๋ค์)
โ LED๋ฅผ ์ฌ์ฉํ ๋์คํ๋ ์ด ์ฅ์น๋ ๊ณ ํ๋์ ์๋ช
์ด ๊ธธ๋ค๋ ์ฅ์
โ ๋ํธ ๋งคํธ๋ฆญ์ค๋ฅผ ๊ตฌ๋์ํค๋ ๋ฐฉ๋ฒ
- ์คํํฑ๊ตฌ๋(static drive)
: ์ํํธ ๋ ์ง์คํฐ์ ๋นํธ๋ฅผ LED ๊ฐฏ ์ ๋งํผ ์ค๋นํ๊ณ ์ฌ๊ธฐ์ ๋ฐ์ดํฐ๋ฅผ ๋ณด๋ด์ด ์ ๋ฑํ๋
๋ฐฉ์์ผ๋ก ํ ๋ฒ์ ๋ชจ๋ LED๋ฅผ ON/OFFํจ
- ๋ค์ด๋๋ฏน๊ตฌ๋(dynamic drive)
: ์ค์บ๋ผ์ธ๊ณผ ๋ฐ์ดํฐ๋ผ์ธ์ผ๋ก ๊ตฌ์ฑ๋์ด ์ค์บ๋ผ์ธ์ ์ํด ๊ฐ ํ ๋๋ ์ด์ 1ํ์ฉ ์ค์บํ๋ฉด์
๋ฐ์ดํฐ๋ผ์ธ์ ์ํด ๋๊ธฐ๋ ๋ฐ์ดํฐ๋ฅผ ์ถ๋ ฅํ๋ ๋ฐฉ์
โ ๋ค์ด๋๋ฏน ๋๋ผ์ด๋ธ๋ฐฉ์์ ์คํํฑ ๋๋ผ์ด๋ธ์ ๋นํด ํ๋๊ฐ ๋ฎ๊ณ , ์ค์บ์ฃผํ์๊ฐ ๋ฎ์ ๊ฒฝ์ฐ์
๊น๋ฐ๊ฑฐ๋ฆผ์ด ์ผ์ด๋๋ค๋ ์ ์์๋ ๋ค์ ๋จ์ด์ง๋ค๊ณ ํ ์ ์์ผ๋ ๊ตฌ๋ํ๋ก๊ฐ ๊ฐ๋จํ๊ธฐ ๋๋ฌธ์
์ ๊ฐ๊ฒฉ์ผ๋ก ๋ํ๋ฉด์ ๊ตฌ์ฑ์ ์ ํฉ
5. --55--20062006--0404--0707
Embedded AVR ProgrammingEmbedded AVR Programming
1-3 Dotmatrix 8*8 ํ๋ก๋
LED17
Red
LED28
Red
LED29
Red
LED23
Red
LED30
Red
LED22
Red
LED21
Red
LED25
Red
LED24
Red
LED20
Red
LED27
Red
LED26
Red
LED19
Red
LED31
Red
LED32
Red
LED18
Red
LED33
Red
COL1
LED44
Red
LED45
Red
LED39
Red
COL2
LED46
Red
COL3
LED38
Red
COL4
LED37
Red
COL5
LED41
Red
COL6
LED40
Red
LED36
Red
COL7
LED43
Red
COL8
LED42
Red
LED35
Red
LED47
Red
LED48
Red
LED34
Red
LED6
Red
LED49
Red
LED60
Red
LED61
Red
LED55
Red
LED62
Red
LED54
Red
LED53
Red
LED4
Red
LED8
Red
LED57
Red
LED56
Red
LED52
Red
LED59
Red
LED58
Red
LED51
Red
LED63
Red
LED64
Red
LED50
Red
LED3
Red
LED5
Red
LED2
Red
LED7
Red
ROW2
ROW1
ROW7
ROW8
ROW5
ROW6
ROW3
ROW4
PB6
PB5
PB4
PB3
PB2
PB1
PB0
PC6
PC5
PC4
PC3
PC2
PC1
PC0
PB7
PC7
LED9
Red
LED15
Red
LED14
Red
LED13
Red
LED16
Red
LED12
Red
LED11
Red
LED10
Red
LED1
Red
6. --66--20062006--0404--0707
Embedded AVR ProgrammingEmbedded AVR Programming
1-4 Heart ์ค์ต 1
โ ํํธ ๋ชจ์์ ์๋๋ก ์ฌํํธํ ํ ๋ค์ ์์ํ๋ก ๋ณต๊ทํ๋ ์ฅ๋ฉด ๋ฑ์ ๋ฐ๋ณตํ๋ ํ๋ก๊ทธ๋จ
flash unsigned char M[1][25]={
{1,2,3,4,5,6,8,9,7,6,5,4,3,2,1,12,10,11,10,12,13,1,9,1,0}
};
flash unsigned char P[14][8]={
{0x66,0xFF,0xFF,0xFF,0x7E,0x3C,0x18,0x00},
{0x66,0xFF,0xFF,0xFF,0x7E,0x3C,0x18,0x00},
{0x00,0x66,0xFF,0xFF,0xFF,0x7E,0x3C,0x18},
{0x00,0x00,0x66,0xFF,0xFF,0xFF,0x7E,0x3C},
{0x00,0x00,0x00,0x66,0xFF,0xFF,0xFF,0x7E},
{0x00,0x00,0x00,0x00,0x66,0xFF,0xFF,0xFF},
{0x00,0x00,0x00,0x00,0x00,0x66,0xFF,0xFF},
{0x00,0x00,0x00,0x00,0x00,0x00,0x66,0xFF},
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x66},
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
{0x66,0x99,0x81,0x81,0x42,0x24,0x18,0x00},
{0x00,0x66,0x99,0x81,0x81,0x42,0x24,0x18},
{0x66,0xFF,0xDB,0xC3,0x66,0x3C,0x18,0x00},
{0x66,0xFF,0xFF,0xE7,0x7E,0x3C,0x18,0x00}
};
#include <mega128.h>
#include <delay.h>
typedef unsigned char u08;
typedef unsigned int u16;
unsigned char line=0;
unsigned char patt=0;
unsigned char mod=0, num_mod=0;
unsigned char time=0;
unsigned char dir=0; //์ํ์ข์ฐ๋ฐฉํฅ๊ฒฐ์ ์ผ๋ก ๋์คํ๋ ์ด ๋ฐฉํฅ ์ ํ
unsigned char temp_led, temp_line;
/*
๋ฐฐ์ด P๋ ๊ฐ ๋์๋ค์ด ๋ํธ ๋งคํธ๋ฆญ์ค์ ํ์๋๋ ๋ฐ์ดํฐ์ด๊ณ (ํ๋ํ
๋์ ์ ์ง๋ชจ์ต)
๋ฐฐ์ด M์ ๊ทธ ๋์๋ค์ ์์๋๋ก ๋์ดํ์ฌ ํ๋์ ์์ง์์ด ๋๋๋ก ํ
๋ค.
*/
7. --77--20062006--0404--0707
Embedded AVR ProgrammingEmbedded AVR Programming
1-4 Heart ์ค์ต 2
โ ํํธ ๋ชจ์์ ์๋๋ก ์ฌํํธํ ํ ๋ค์ ์์ํ๋ก ๋ณต๊ทํ๋ ์ฅ๋ฉด ๋ฑ์ ๋ฐ๋ณตํ๋ ํ๋ก๊ทธ๋จ
void main(void)
{
DDRB = 0xff;
DDRC = 0xff;
DDRD = 0xff;
TCCR0 = 0x06; // clk/256
TCNT0 = 0xe3;
TIMSK = 0x01; // enable TOIE0
#asm("sei")
while(1)
{
if(M[mod][num_mod] == 0)
{
num_mod=0;
}
else{
patt= M[mod][num_mod]; //์์ง์ ์ํ ๋ณ๊ฒฝ
num_mod++;
}
delay_ms(200);
};
}
interrupt [TIM0_OVF] void timer0_int(void)
{
TCNT0 = 0xe3; // reload for 448us ticks(์ธก์ ๊ฐ : 460us)
switch (dir){ //dir์ ๋ฐ๋ผ ํ์๋๋ ๋ฐฉํฅ์ ๊ฒฐ์ ํ๋ค.
case 0: temp_led=1<<(7-line);
temp_line=P[patt][line];
break;
case 2: temp_led=P[patt][line];
temp_line=1<<line;
break;
case 1: temp_led=P[patt][7-line];
temp_line=1<<line;
break;
case 3: temp_led=1<<line;
// temp_led = 0x01 << line; line=0~7๊น์ง ํ์ ํ
temp_line=P[patt][line];
break;
}
PORTB = ~temp_line;
PORTC = temp_led; //๋นจ๊ฐ์ ์ถ๋ ฅ
if(line==7) line=0;
else line++;
}
8. --88--20062006--0404--0707
Embedded AVR ProgrammingEmbedded AVR Programming
1-5 BITMAN ์ค์ต 1
โ BITMAN์ผ๋ก ์ฌ๋์ ์์ง์์ ๋๋คํ๊ฒ ํ์ํ๋ ํ๋ก๊ทธ๋จ
/*
๋ฐฐ์ด P๋ ๊ฐ ๋์๋ค์ด ๋ํธ ๋งคํธ๋ฆญ์ค์ ํ์๋๋ ๋ฐ์ดํฐ์ด๊ณ (ํ๋ํ๋์
์ ์ง๋ชจ์ต)
๋ฐฐ์ด M์ ๊ทธ ๋์๋ค์ ์์๋๋ก ๋์ดํ์ฌ ํ๋์ ์์ง์์ด ๋๋๋ก ํ๋ค.
*/
flash unsigned char M[6][25]={
{1,2,3,4,5,6,5,4,3,2,1,7,8,9,10,11,10,9,8,7,1,0,0,0,0},
{12,13,14,13,12,13,12,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
{15,16,17,16,15,18,19,18,15,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
{20,21,22,21,20,23,24,23,20,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
{25,26,27,28,29,30,31,32,29,30,31,32,0,0,0,0,0,0,0,0,0,0,0,0,0},
{33,34,35,36,37,38,39,40,37,38,39,40,41,42,41,42,0,0,0,0,0,0,0
,0,0}
};
flash unsigned char P[43][8]={
{0x18,0x18,0x3c,0x5a,0x5a,0x24,0x24,0x66},
{0x18,0x18,0x3C,0x5A,0x5A,0x24,0x24,0x66},
{0x18,0x18,0x3C,0xDA,0x1A,0x24,0x24,0x66},
{0x0C,0xCC,0x3C,0x1A,0x1A,0x24,0x26,0x62},
{0x8C,0x4C,0x3C,0x1A,0x1A,0x24,0x27,0x60},
#include <mega128.h>
#include <delay.h>
typedef unsigned char u08;
typedef unsigned int u16;
#define DELAY 100
unsigned char line=0;
unsigned char patt=0;
unsigned char mod=0, num_mod=0;
unsigned char time=0;
unsigned char delay=DELAY;
unsigned char dir=3;
unsigned char temp_led, temp_line;
unsigned char temp_dir;
unsigned int dir_cnt=0;
unsigned char dir_chk_sw=0;
unsigned char mov_chk_sw=1; //์ผ์ ๊ฐ์ง ์์ผ๋ฉด ์์ง์ ์ ์ง.
unsigned char mov_chk_cnt=0;
unsigned char name_sw=0;
9. --99--20062006--0404--0707
Embedded AVR ProgrammingEmbedded AVR Programming
1-5 BITMAN ์ค์ต 2
โ BITMAN์ผ๋ก ์ฌ๋์ ์์ง์์ ๋๋คํ๊ฒ ํ์ํ๋ ํ๋ก๊ทธ๋จ
{0x18,0x18,0x3C,0x5A,0x5A,0x24,0x24,0x66},
{0x18,0x18,0x3E,0x59,0x58,0x24,0x26,0x60},
{0x0C,0x0C,0x18,0x3C,0x38,0x14,0x36,0x20},
{0x0C,0x0C,0x38,0x5E,0x58,0x14,0x74,0x46},
{0x0C,0x0C,0x38,0x3E,0x18,0x78,0x50,0x18},
{0x00,0x0C,0x3C,0x58,0x5C,0x16,0x30,0x20},
{0x0C,0x0C,0x78,0x9E,0x1C,0x14,0x76,0x40},
{0x0C,0x0C,0x3F,0x58,0x18,0x34,0x24,0x06},
{0x18,0x18,0x3C,0x5A,0x5A,0x24,0x24,0x66},
{0x18,0x18,0x7C,0x9A,0x1A,0x24,0x64,0x06},
{0x30,0x30,0x18,0x3C,0x1C,0x28,0x6C,0x04},
{0x30,0x30,0x1C,0x7A,0x1A,0x28,0x2E,0x62},
{0x30,0x30,0x7C,0x1A,0x18,0x16,0x12,0x30},
{0x30,0x30,0x1C,0x7C,0x18,0x1E,0x0A,0x18},
{0x00,0x30,0x3C,0x1A,0x3A,0x68,0x0C,0x04},
{0x30,0x30,0x1E,0x79,0x38,0x28,0x6E,0x02},
{0x30,0x30,0xFC,0x1A,0x18,0x2C,0x24,0x60},
{0x30,0x30,0x3E,0x58,0x1C,0x24,0x26,0x60}
};
{0x4C,0x4C,0x3C,0x1A,0x1A,0x24,0x27,0x60},
{0x2C,0x4C,0x3C,0x1A,0x1A,0x24,0x27,0x60},
{0x18,0x18,0x3C,0x5B,0x58,0x24,0x24,0x66},
{0x30,0x33,0x3C,0x58,0x58,0x24,0x24,0x66},
{0x31,0x32,0x3C,0x58,0x58,0x24,0xE4,0x06},
{0x32,0x32,0x3C,0x58,0x58,0x24,0xE4,0x06},
{0x34,0x32,0x3C,0x58,0x58,0x24,0xE4,0x06},
{0x18,0x18,0x3C,0x5A,0x5A,0x24,0x24,0x66},
{0x00,0x18,0x7E,0x99,0x18,0x3C,0x24,0x66},
{0x00,0x00,0xDB,0x3C,0x18,0x3C,0x3C,0x66},
{0x18,0x18,0x3C,0x5A,0x5A,0x24,0x24,0x66},
{0x18,0x18,0x3C,0xDA,0x1A,0x24,0x64,0x06},
{0x30,0x30,0x9C,0x7A,0x19,0x24,0x64,0x06},
{0x18,0x18,0x3C,0x5B,0x58,0x24,0x26,0x60},
{0x0C,0x0C,0x39,0x5E,0x98,0x24,0x26,0x60},
{0x18,0x18,0x3C,0x5A,0x5A,0x24,0x24,0x66},
{0x0C,0x0C,0x7C,0x9A,0x1A,0x24,0x26,0x60},
{0x00,0x06,0xFE,0x1C,0x1A,0x2A,0x28,0x6C},
{0x30,0x30,0x3E,0x59,0x58,0x24,0x64,0x06},
{0x00,0x60,0x7F,0x38,0x58,0x54,0x14,0x36},
10. --1010--20062006--0404--0707
Embedded AVR ProgrammingEmbedded AVR Programming
1-5 BITMAN ์ค์ต 3
โ BITMAN์ผ๋ก ์ฌ๋์ ์์ง์์ ๋๋คํ๊ฒ ํ์ํ๋ ํ๋ก๊ทธ๋จ
interrupt [TIM2_OVF] void timer2_ovf_isr(void)
//์์ง์์ ๋ฐ๊พธ๊ธฐ ์ํ ํ์ด๋จธ ์ฌ์ฉ(๋๋คํจ์์ ์ ์ฌ)
{
TCNT2 = 0xdf; // reload for 2.048ms ticks(์ธก์ ๊ฐ : 2.12ms)
time++;
if(mov_chk_sw==1 && time >= delay ) //(์ธก์ ๊ฐ : 214ms)
{
time=0;
if(M[mod][num_mod] == 0) { //์์ง์ ์ข
๋ฅ ๋ณ๊ฒฝ
mod= TCNT0%6;
num_mod=0;
mov_chk_cnt++;
if(mov_chk_cnt == 10) {
mov_chk_sw=0;
mov_chk_cnt=0;
}
}
else {
patt= M[mod][num_mod]; //์์ง์ ์ํ ๋ณ๊ฒฝ
num_mod++;
if(delay<= DELAY) delay++;
}
}
}
interrupt [TIM0_OVF] void timer0_int(void)
{
TCNT0 = 0xe3; // reload for 448us ticks(์ธก์ ๊ฐ : 460us)
switch (dir){ //dir์ ๋ฐ๋ผ ํ์๋๋ ๋ฐฉํฅ์ ๊ฒฐ์ ํ๋ค.
case 0: temp_led=1<<(7-line);
temp_line=P[patt][line];
break;
case 2: temp_led=P[patt][line];
temp_line=1<<line;
break;
case 1: temp_led=P[patt][7-line];
temp_line=1<<line;
break;
case 3: temp_led=1<<line;
temp_line=P[patt][line];
break;
}
PORTB = ~temp_line;
PORTC = temp_led; //๋นจ๊ฐ์ ์ถ๋ ฅ
if(line==7) line=0;
else line++;
}
11. --1111--20062006--0404--0707
Embedded AVR ProgrammingEmbedded AVR Programming
1-5 BITMAN ์ค์ต 4
โ BITMAN์ผ๋ก ์ฌ๋์ ์์ง์์ ๋๋คํ๊ฒ ํ์ํ๋ ํ๋ก๊ทธ๋จ
void main(void)
{
DDRA = 0x00;
PORTA = 0xff;
DDRB = 0xff;
DDRC = 0xff;
DDRD = 0xff;
TCCR0 = 0x06; // clk/256
TCCR2 = 0x05; // clk/1024
TCNT0 = 0xe3;
TCNT2 = 0x00;
TIMSK = 0x41; // enable TOIE2, TOIE0
#asm("sei")
while(1)
{ };
}