'프로그래밍/AVR'에 해당되는 글 7건

  1. 2016.11.23 Timer 3개 모두사용하는 예제
  2. 2016.11.23 USBASP V2.0 펌웨어 업그레이드
  3. 2016.11.20 저항의 전류제한
  4. 2016.11.15 AVR Timer
  5. 2016.11.14 AVR LED 2개 제어
  6. 2016.11.09 Linux 에서 AVR 컴파일 및 프로그래밍
  7. 2016.10.30 AVR LED 작동
2016. 11. 23. 22:53

ATMega328P 에는 총 3개의 타이머가 있습니다.


타이머0 - 8비트

타이머1 - 16비트

타이머2 - 8비트


모드는 모두 CTC 모드로 작성 했습니다.


Clear Timer on Compare match


CTC모드는 TCNT 값이 0부터 증가 해서 OCR 에 정의된 값 까지 갑니다.

(여기서 8비트는 최대 255 까지 밖에 ㅜㅜ)


1초를 구하기 위해 16비트는 설정만으로 가능하지만, 8비트는 모두 세지 못합니다.


그래서 타이머 인터럽트 내에 몇번 반복 시켜서 1초를 구하게 됩니다.



8비트로 1초 구하는 방법...

CPU가 16 MHz 로 동작을 가정합니다.


1. 1초에 16000000 Hz 진동합니다.

2. prescale 256 으로 셋팅했으므로 256 Hz 당 1 타이머 count 가 증가합니다.

    즉, 16000000 / 256 = 0.000016 초에 1 Hz씩  ( 1 hz / 16 us)

3. OCR에 정의된 값까지 증가하고 0으로 되돌아 갑니다.

    125번 반복하면 걸리는 시간 = 0.000016 x 125 = 0.002  125번 반복에 0.002초 ( 2 ms) 

    125번 이지만 0 부터 시작하므로 -1을 하여 124를 설정합니다.

4. 타이머 인트럽트가 2ms 당 1번씩 호출되므로 500번 마다 작동하도록 설정하면 1초 마다 동작하도록 설정 됨.


복잡한 것 같지만... 차근차근 읽어보면 그냥 산수 입니다. ^__^


16비트 타이머의 경우 OCR 에 정의할 수 있는 값이 거대해서 인트럽트에서 별도 반복 없이도 1초 구하는 것이 가능합니다.



동작영상



타이머 3개 모두 동작시킨 풀 소스코드

예제는 16비트 1초, 8비트 1/2초, 8비트 1/4초 로 세팅되어 있습니다.

https://github.com/haebi/AVRExample/blob/master/atmega328p/timer2/timer2.cpp


#define F_CPU 16000000UL // Set CPU Frequency 16 MHz


#define setbit(PORTX, BitX) PORTX |= (1 << BitX) // set bit to 1

#define clrbit(PORTX, BitX) PORTX &= ~(1 << BitX) // clear bit


#include <avr/io.h>

#include <util/delay.h>

#include <avr/interrupt.h>


int count0 = 0;

int tick0  = 0;


int count1 = 0;


int count2 = 0;

int tick2  = 0;


void setTimer0()

{

// 1sec for 8-bit

// 1 / 16000000 = 0.0000000625 * 256 (prescale) = 0.000016 (usec)

// 0.000016 (usec) * 125 (multiplier) = 0.002 * 1000 = 2 (ms)

// 2 (ms) * 500 (count) = 1 (sec)


TCNT0   = 0;

// Set CTC compare value with a prescaler of 256

OCR0A   = 124; // 125 -1 


// 0 1 0 - Configure timer 0 for CTC mode [p.106]

clrbit(TCCR0B, WGM02); // 0

setbit(TCCR0A, WGM01); // 1

clrbit(TCCR0A, WGM00); // 0


// 1 0 0 - Start timer at Fcpu/256 [p. 108]

setbit(TCCR0B, CS02); // 1

clrbit(TCCR0B, CS01); // 0

clrbit(TCCR0B, CS00); // 0

// Enable CTC interrupt

setbit(TIMSK0, OCIE0A);

}


void setTimer1()

{

// OCR1A =  OCR1AH + OCR1AL = (8 + 8 = 16 bit)

// Dec 15624 : repeat 0 ~ 15624 (15625 = 0)

OCR1A = 0x3D08; 


// Page 171-172

// Waveform Generation Mode : (TCCR1B:4,  TCCR1B:3, TCCR1A:1, TCCR1A:0)

// 0 1 0 0 - Set to TOP OCR1A

setbit(TCCR1B, WGM12); // Configure timer 1 for CTC mode


// Page 173

// Clock Select Bit ( CS12 CS11 CS10 )

// 0 1 0 - clock I/O / 1024 (From prescaler)

setbit(TCCR1B, CS12);

setbit(TCCR1B, CS10);


// Page 135

// TIMSK1 – Timer/Counter1 Interrupt Mask Register

setbit(TIMSK1, OCIE1A); // Enable CTC interrupt

}


void setTimer2()

{

// 1sec for 8-bit

// 1 / 16000000 = 0.0000000625 * 256 (prescale) = 0.000016 (usec)

// 0.000016 (usec) * 125 (multiplier) = 0.002 * 1000 = 2 (ms)

// 2 (ms) * 500 (count) = 1 (sec)


TCNT2   = 0;

// Set CTC compare value with a prescaler of 256 

OCR2A   = 124; // 125 -1 


// 0 1 0 - Configure timer 2 for CTC mode [p.155]

clrbit(TCCR2B, WGM22); // 0

setbit(TCCR2A, WGM21); // 1

clrbit(TCCR2A, WGM20); // 0


// 1 1 0 - Start timer at Fcpu/256 [p.156-157]

setbit(TCCR2B, CS22); // 1

setbit(TCCR2B, CS21); // 1

clrbit(TCCR2B, CS20); // 0


// Enable CTC interrupt

TIMSK2 |= (1 << OCIE2A);

}


// Main Function

int main(void)

{

setTimer0(); //  8 bit timer (TCNT0)

setTimer1(); // 16 bit timer (TCNT1)

setTimer2(); //  8 bit timer (TCNT2)


sei(); // Enable global interrupts


setbit(DDRD, DDD6); // Set output PD6

setbit(DDRD, DDD7); // Set output PD7

setbit(DDRB, DDB0); // Set output PB0


while (1)

{


}

}


// Timer0 interrupt

ISR (TIMER0_COMPA_vect)

{

tick0++;


// if (!(tick0 == 500)) // 1 sec

if (!(tick0 == 125)) // 1/4 sec

return;


tick0 = 0;


if (count0 == 0)

{

count0++;

clrbit(PORTB, PORTB0);

}

else

{

setbit(PORTB, PORTB0);

count0 = 0;

}

}


// Timer1 interrupt

ISR (TIMER1_COMPA_vect)

{

// already 1 sec


if (count1 == 0)

{

count1++;

clrbit(PORTD, PORTD6);

}

else

{

setbit(PORTD, PORTD6);

count1 = 0;

}

}


// Timer2 interrupt

ISR (TIMER2_COMPA_vect) 

{

tick2++;


// if (!(tick2 == 500)) // 1 sec

if (!(tick2 == 250)) // 1/2 sec

return;


tick2 = 0;


if (count2 == 0)

{

count2++;

clrbit(PORTD, PORTD7);

}

else

{

setbit(PORTD, PORTD7);

count2 = 0;

}

}




Posted by 해비
2016. 11. 23. 22:20

그간 미뤄오던 USBASP의 펌웨어 업그레이드를 진행 했다.


달라진건... warning 이 안뜬다는거랑 프로그램 속도가 좀 더 빨라진것 같은 느낌...?


까먹기전에 역시 메모...


준비물 : USBASP 2개 (한쪽은 주는쪽 한쪽은 당하는(?)... 쪽)


(서로 번갈아 가며 2번 하면 둘다 펌업이가능 합니다만... 1개만 있으면 아쉽게도.. 불가.;;)


타겟에 JP2 를 쇼트 내도록 합니다.

(이거 몰라서 왜 안되징...?? 하며 1시간 헤메었네요 ㅜㅜ)




소스코드 다운로드

http://www.fischl.de/usbasp/



압축해제 후 bin 폴더안에 hex 파일을 찾는다.


그리고 아래 명령어로 플래싱을 한다.

(-p m8 옵션은 ATMega8A MCU 이다. 혹시 다른 MCU 라면 해당 모델로 바꾸도록 한다)


$ avrdude -c usbasp -p m8 -F -e -U flash:w:usbasp.atmega8.2011-05-28.hex


avrdude: AVR device initialized and ready to accept instructions


Reading | ################################################## | 100% 0.00s


avrdude: Device signature = 0x1e9307 (probably m8)

avrdude: erasing chip

avrdude: reading input file "usbasp.atmega8.2011-05-28.hex"

avrdude: input file usbasp.atmega8.2011-05-28.hex auto detected as Intel Hex

avrdude: writing flash (4700 bytes):


Writing | ################################################## | 100% 1.80s


avrdude: 4700 bytes of flash written

avrdude: verifying flash memory against usbasp.atmega8.2011-05-28.hex:

avrdude: load data flash data from input file usbasp.atmega8.2011-05-28.hex:

avrdude: input file usbasp.atmega8.2011-05-28.hex auto detected as Intel Hex

avrdude: input file usbasp.atmega8.2011-05-28.hex contains 4700 bytes

avrdude: reading on-chip flash data:


Reading | ################################################## | 100% 1.11s


avrdude: verifying ...

avrdude: 4700 bytes of flash verified


avrdude: safemode: Fuses OK (E:FF, H:D9, L:FF)


avrdude done.  Thank you. 


끝... (이래 간단한 것을...;;)




펌웨어 업글 이전 / 이후 비교로그

haebi@haebi-W330AU ~/workspace/avr/atmega328p/timer2 $ ./program.sh 


avrdude: warning: cannot set sck period. please check for usbasp firmware update.

avrdude: AVR device initialized and ready to accept instructions


Reading | ################################################## | 100% 0.00s


avrdude: Device signature = 0x1e950f (probably m328p)

avrdude: erasing chip

avrdude: warning: cannot set sck period. please check for usbasp firmware update.

avrdude: reading input file "timer2.hex"

avrdude: input file timer2.hex auto detected as Intel Hex

avrdude: writing flash (602 bytes):


Writing | ################################################## | 100% 0.41s


avrdude: 602 bytes of flash written

avrdude: verifying flash memory against timer2.hex:

avrdude: load data flash data from input file timer2.hex:

avrdude: input file timer2.hex auto detected as Intel Hex

avrdude: input file timer2.hex contains 602 bytes

avrdude: reading on-chip flash data:


Reading | ################################################## | 100% 0.30s


avrdude: verifying ...

avrdude: 602 bytes of flash verified


avrdude: safemode: Fuses OK (E:FF, H:DE, L:FF)


avrdude done.  Thank you. 

업글 이전 warning 이 표시되었다.



그리고 업글 후...

haebi@haebi-W330AU ~/workspace/avr/atmega328p/timer2 $ ./program.sh 


avrdude: AVR device initialized and ready to accept instructions


Reading | ################################################## | 100% 0.00s


avrdude: Device signature = 0x1e950f (probably m328p)

avrdude: erasing chip

avrdude: reading input file "timer2.hex"

avrdude: input file timer2.hex auto detected as Intel Hex

avrdude: writing flash (602 bytes):


Writing | ################################################## | 100% 0.23s


avrdude: 602 bytes of flash written

avrdude: verifying flash memory against timer2.hex:

avrdude: load data flash data from input file timer2.hex:

avrdude: input file timer2.hex auto detected as Intel Hex

avrdude: input file timer2.hex contains 602 bytes

avrdude: reading on-chip flash data:


Reading | ################################################## | 100% 0.15s


avrdude: verifying ...

avrdude: 602 bytes of flash verified


avrdude: safemode: Fuses OK (E:FF, H:DE, L:FF)


avrdude done.  Thank you.


warning 이 사라졌다!!







Posted by 해비
2016. 11. 20. 20:05


저항의 전류제한


LED 사용시 전류 제한을 위해 저항을 사용합니다.


전압(V) 전류(I) 저항(R)의 공식은 아래와 같죠.

V = IR


좀 헷갈릴 수 있어서 미리 추가 설명 붙이자면

- 전류 (I) 의 단위는 A (암페어) 를 사용

- 저항 (R) 의 단위는 ohm (옴) 을 사용

- 전류의 단위 1000 mA = 1 A



[가정]

백색 LED 1개를 5V 전원에 연결하고자 한다면 ?

통상적으로 백색 LED 는 전압(V) 3.4 - 4.0, 전류 20mA 를 필요로 합니다.


입력 전압이 5V 이고 전압을 3.4 까지 낮춰야 합니다.


LED 에서 필요로 하는 전류 20mA = 0.02 A

전압의 차이 5V - 3.4V = 1.6V


V = IR 에 의거, R = V / I

1.6 / 0.02 = 80 ohm


80옴 의 저항이 필요함을 알 수 있습니다.

보통 계산에 딱 맞는 수치의 저항이 없는 경우가 많은데, 이 경우 근사치의 비슷한 저항을 사용합니다.



저항에 걸리는 전압은 V = IR 에 의거, 0.02 (A) * 80 (ohm) = 1.6 (V)


저항에 흐르는 전류는 0.02 (A) * 0.02 (A) * 80 (ohm) = 0.0004 * 80 = 0.032 (W)


보통 일반적으로 많이 보는 가느다란 저항들이 1/4 w 입니다.

이는 저항이 0.25 (W) 까지 버틸 수 있음을 의미합니다.


저항에 흐르는 전류 생각 안하다가 저항이 활활(?) 탑니다.



[가정]

5V 라인에 1개의 저항에 LED 10개 를 병렬로 연결하게 되면...?

저항은 8옴이 필요하고, 저항에 흐르는 전류가 0.32 (W) 가 되겠네요.


이 경우 1/4 W 저항 사용하게되면 저항 태워 먹습니다 (제한 전류를 오버 했으니까 -_- )

1/2 W 저항이나 이 이상의 높은 전류를 견디는 저항을 사용하면 되겠습니다만 권장하지 않는 방법 입니다.


저항 1개 나가면 거기 물린 LED 줄 초상 나거든요 ;;

그래서 보통 1 LED, 1 저항을 추천합니다.


추가로, AVR MCU 의 경우 핀에 흘릴수 있는 전류의 양에 제한이 있습니다.

대 전류를 필요로 하는 모터 같은 경우, 별도의 전용 드라이버IC를 이용해야 하는 이유이지요;




전류 제한을 위해 저항 사용시 계산 입니다.


5V 전원에 저항없이 바로 직결 했다고 가정 하면 5 A 라는 어마어마한 전류가 흐릅니다.

W = V x A 이므로, 이 경우 25 W 가 됩니다.


5V 전원에 10k (10,000) ohm 짜리 저항을 사용시 회로에 흐르는 전류는 고작 0.5 mA 입니다.

W = V x A 에 대입 시, 0.0025 W 라는 아주 미약한 전류가 흐를 뿐입니다.




Posted by 해비
2016. 11. 15. 23:16

AVR 타이머 예제


앞에서 while 문에 타이밍 에 따라 분기 시켰는데...


이게 더 정답일듯 하다. 왜냐면.. 그 앞의 함수 실행 시간 동안 미세하게 나마 지연(?)같은 것이 발생할 테고... 그러면 미미하게나마 타이밍이 틀어질 수 있으니까...


타이머 사용하면 타이밍에 맞게 알아서 인트럽트 발생시켜 주니까 이쪽이 타이밍이 더 정확하게 동작할 것 같다.


스레드 대신 타이머... 로 생각하면 되려나...?

...일단은 어렵다!!


타이머가 몇개 인지는 모르겠는데... 타이머 갯수만큼 스레드 처럼 부려먹을수 있을지 조사해 봐야겠다 -_-;;


모드가 아래 2가지가 있는 듯 한데 

Normal - 정확하지 않은 타이밍

CTC - 정확한 타이밍


이것만 보면 당연히 CTC만 써야되고 Normal 은 못쓸것이 된다.

장/단점 이라던가... 더 찾아봐야 겠다.


음... 이 코드는 OCR1A가 있는 것으로 봐서 CTC 모드 인 것으로 보인다. (아직 코드 이해가 -_-)


일단 갖고 놀다보면 이해가 될거라 굳게 믿고 있음!! 꼭!!


#define F_CPU 16000000UL // Set CPU Frequency 16 MHz


#define setbit(PORTX, BitX) PORTX |= (1 << BitX) // set bit to 1

#define clrbit(PORTX, BitX) PORTX &= ~(1 << BitX) // clear bit


#include <avr/io.h>

#include <avr/interrupt.h>


int count = 0;


// Main Function

int main(void)

{

OCR1A = 0x3D08;


setbit(TCCR1B, WGM12);

setbit(TIMSK1, OCIE1A);

setbit(TCCR1B, CS12);

setbit(TCCR1B, CS10);


sei();


DDRD |= (1 << DDD6); // Set output PD6

DDRD |= (1 << DDD7); // Set output PD7


while (1)

{


}

}


ISR (TIMER1_COMPA_vect)

{

if (count == 0)

{

count++;

clrbit(PORTD, PORTD6);

}

else

{

setbit(PORTD, PORTD6);

count = 0;

}


일단... 돌아는 갑니다... 직접 칩에 넣고 돌려서 확인 했어용~ 




Posted by 해비
2016. 11. 14. 01:03

LED 1개 에 이어 2개 ...


운영체제 올라가면 별도 쓰레드로 올리고 sleep 주면 되겠지만... 여긴 그런게 없다...


while 문의 타이밍 주기를 1ms 로 세팅하고 LED 켜고 꺼지는 주기는 설정한 간격에 의해 별도 함수 내에서 처리하도록 프로그램 하였다.


time이 계속 증가만 하는데 이거 상관 없는지는 확인 이 필요할 것 같다.



사진



작동영상



소스코드

#define F_CPU 16000000UL


#include <avr/io.h>

#include <util/delay.h>


void PPD6(int time, int interval)

{

if ((time %  (2 * interval)) == 0)

{

PORTD &= ~(1<<PORTD6);

}

else if ((time %  interval) == 0)

{

PORTD |= (1<<PORTD6);

}

}


void PPD7(int time, int interval)

{

if ((time %  (2 * interval)) == 0)

{

PORTD &= ~(1<<PORTD7);

}

else if ((time %  interval) == 0)

{

PORTD |= (1<<PORTD7);

}

}


int main(void)

{

int time = 0;


DDRD |= (1<<DDD6); // PD6 Out

DDRD |= (1<<DDD7); // PD7 Out

while(1)

{

PPD6(time, 125);

PPD7(time, 500);


time++;

_delay_ms(1);

}




Posted by 해비
2016. 11. 9. 23:18

윈도우 에서 삽질하다 포기하고 리눅스로 넘어왔다.


첨부터 리눅스로 할껄...;;


필요한 프로그램 설치

apt install gcc-avr avr-libc avrdude 


다른 곳에서는 binutils 와 uisp 까지 설치 하라고 되있는 곳도 있던데...

일단 테스트 결과 네모 안에 있는 3개만 설치해도 빌드 및 프로그램이 가능함을 확인 하였다.

avr-gcc, avrdude 만 있음 되는 거 같다... 일단은 -_-


음영으로 표시된 부분이 명령창에서 입력하는 부분이다.



1. 소스 작성 (cpp)

2. Makefile 작성

3. 컴파일 -> hex 파일 생성

4. 프로그램 -> hex 파일 을 ATMega328p 에 전송 (USBASP 2.0 사용)

5. 퓨즈비트 세팅 -> 내장클릭 1Mhz 를 사용하지 않고 외부의 16 MHz 크리스탈을 사용하여 동작하도록 설정



잊어먹기 전에 정리.... -_-;;


안되서 맨날 시방시방 하다가 되니까... 이 기분을 어찌 표현해야 할지... ㅎㅎㅎ


펌웨어 버젼 어쩌고 경고 뜨는데, 현재로서는 모르겠다능 -_-;;

펍업 하다 USBASP 해먹으면... 진행을 못하니까... 열댓개 사서 시도를 해보던가 해야겠다.



ledblink.cpp

#define F_CPU 16000000UL

#include <avr/io.h>

#include <util/delay.h>

int main(void)

{

DDRB |= (1<<DDB5); //Set the 6th bit on PORTB (i.e. PB5) to 1 => output

while(1)

{

PORTB |= (1<<PORTB5);    //Turn 6th bit on PORTB (i.e. PB5) to 1 => on

_delay_ms(1000);        //Delay for 1000ms => 1 sec

PORTB &= ~(1<<PORTB5);    //Turn 6th bit on PORTB (i.e. PB5) to 0 => off

_delay_ms(1000);        //Delay for 1000ms => 1 sec

}



Makefile

ledblink.o: dummy

avr-gcc -mmcu=atmega328p -Os ledblink.cpp -o ledblink.o


ledblink: ledblink.o

avr-objcopy -j .text -j .data -O ihex ledblink.o ledblink.hex


dummy: 



compile

$ make ledblink

avr-gcc -mmcu=atmega328p -Os ledblink.cpp -o ledblink.o

avr-objcopy -j .text -j .data -O ihex ledblink.o ledblink.hex 



program

$ avrdude -c usbasp -p m328p -e -U flash:w:ledblink.hex


avrdude: warning: cannot set sck period. please check for usbasp firmware update.

avrdude: AVR device initialized and ready to accept instructions


Reading | ################################################## | 100% 0.00s


avrdude: Device signature = 0x1e950f (probably m328p)

avrdude: erasing chip

avrdude: warning: cannot set sck period. please check for usbasp firmware update.

avrdude: reading input file "ledblink.hex"

avrdude: input file ledblink.hex auto detected as Intel Hex

avrdude: writing flash (176 bytes):


Writing | ################################################## | 100% 0.15s


avrdude: 176 bytes of flash written

avrdude: verifying flash memory against ledblink.hex:

avrdude: load data flash data from input file ledblink.hex:

avrdude: input file ledblink.hex auto detected as Intel Hex

avrdude: input file ledblink.hex contains 176 bytes

avrdude: reading on-chip flash data:


Reading | ################################################## | 100% 0.13s


avrdude: verifying ...

avrdude: 176 bytes of flash verified


avrdude: safemode: Fuses OK (E:FF, H:DE, L:FF)


avrdude done.  Thank you. 



fuse-bit setting

$ avrdude -c usbasp -p m328p -C /etc/avrdude.conf -U lfuse:w:0xFF:m -U hfuse:w:0xDE:m -U efuse:w:0x05:m


avrdude: warning: cannot set sck period. please check for usbasp firmware update.

avrdude: AVR device initialized and ready to accept instructions


Reading | ################################################## | 100% 0.00s


avrdude: Device signature = 0x1e950f (probably m328p)

avrdude: reading input file "0xFF"

avrdude: writing lfuse (1 bytes):


Writing | ################################################## | 100% 0.00s


avrdude: 1 bytes of lfuse written

avrdude: verifying lfuse memory against 0xFF:

avrdude: load data lfuse data from input file 0xFF:

avrdude: input file 0xFF contains 1 bytes

avrdude: reading on-chip lfuse data:


Reading | ################################################## | 100% 0.00s


avrdude: verifying ...

avrdude: 1 bytes of lfuse verified

avrdude: reading input file "0xDE"

avrdude: writing hfuse (1 bytes):


Writing |                                                    | 0% 0.00s ***failed;  

Writing | ################################################## | 100% 0.03s


avrdude: 1 bytes of hfuse written

avrdude: verifying hfuse memory against 0xDE:

avrdude: load data hfuse data from input file 0xDE:

avrdude: input file 0xDE contains 1 bytes

avrdude: reading on-chip hfuse data:


Reading | ################################################## | 100% 0.00s


avrdude: verifying ...

avrdude: verification error, first mismatch at byte 0x0000

         0xd9 != 0xde

avrdude: verification error; content mismatch


avrdude: safemode: hfuse changed! Was de, and is now d9

Would you like this fuse to be changed back? [y/n] y

avrdude: safemode: and is now rescued

avrdude: safemode: Fuses OK (E:FF, H:DE, L:FF)


avrdude done.  Thank you. 








Posted by 해비
2016. 10. 30. 23:40

ATMega328P 를 브레드보드에 직접 구성하여 동작시켜 보았다.


인터넷 찾아가며 구성해서 일단 동작은 되긴 되는데...

1초에 한번씩 깜빡거리도록 작성된 코드인데 엄청 느리게 깜빡인다.


외부 클럭 설정문제 또는 크리스탈 불량으로 의심된다.



브레드 보드를 제외한 모든 부품은 알리에서 구매한 것들이다.


USBASP 드라이버는 구글 검색으로 쉽게 찾을 수 있다.


USBASP 핀 구조



카즈마? AVR 프로그래머는 오류... 메시지가 뜨는데.. 걍 무시하고 진행하면 OK 메시지 나온다.


아트멜 스튜디오 에서 컴파일 하고, hex 파일을 카즈마? AVR 프로그래머로 AVR에 집어 넣었다.



사용한 툴

Atmel Studio 7.0

http://www.atmel.com/Microsite/atmel-studio/


Khazama AVR Programmer

http://khazama.com/project/programmer/



소스코드 (인터넷에서 검색한 샘플 소스코드)

#define F_CPU 16000000UL

#include <avr/io.h>

#include <util/delay.h>

int main(void)

{

DDRB |= (1<<DDB5); //Set the 6th bit on PORTB (i.e. PB5) to 1 => output

while(1)

{

PORTB |= (1<<PORTB5);    //Turn 6th bit on PORTB (i.e. PB5) to 1 => on

_delay_ms(1000);        //Delay for 1000ms => 1 sec

PORTB &= ~(1<<PORTB5);    //Turn 6th bit on PORTB (i.e. PB5) to 0 => off

_delay_ms(1000);        //Delay for 1000ms => 1 sec

}



hex 파일

blinkled.zip




결과



정면 샷





Posted by 해비