목차
AVR (Advanced Virtual RISC)
MegaAVR
ATmega128
Pin function in ATmege128
Experimental Results
HW1
HW2
HW3
MegaAVR
ATmega128
Pin function in ATmege128
Experimental Results
HW1
HW2
HW3
본문내용
1 second, we can use the function _delay_ms() in util.delay header file. After maintaining 1 second using _delay_ms, as all the LED should be turned on, the value should be 0011 1100. It is converted to 3 C in hexadecimal digit. Declare PORTD = 0x3C and maintain the state for 1 second using _delay_ms() function. Finally, to make the loop infinite and state return to the initial state we used while(1).
3.HW2
A.Source Code
#include
#include
#define F_CPU 11059200UL
int main()
{
unsigned int i;
DDRD = 0xff;
PORTD = 0x01;
while(1){
for(i=0;i<8;i++)
{
_delay_ms(200);
PORTD = PORTD << 1;
}
PORTD = 0x10;
for(i=0;i<8;i++)
{
_delay_ms(400);
PORTD = PORTD >> 1;
}
PORTD = 0x01;
}
return 0;
}
B.Data
C.Discussion
It is an application of ex1, we can see that the LED turns on 1 bit up orderly, and turns on 1 bit down orderly as a result. In other words, moves 1bit to the left, with PORTD = 0x10; among the 4 LED, the very top LED returns to an initial value. Afterwards, with “for” statement, move 1 bit to the right so that to turn on the LED downwards in order. With PORTD = 0x01; turn on the LED which was turned on at the beginning.
4.HW3
A.Source Code
#include
int main(void){
DDRC = 0x00;// port C의 bit 7:0 을 Read으로 선언
DDRD = 0x3C;// port D의 bit 5:2 를 Write으로 선언
while(1){
if(PINC != 0x0F)// pin C의 bit 3:0가 high가 아니라면 작동
PORTD = (~(PINC<<2)) & 0x3C;
else
PORTD = 0x00;
}
return 0;
}
B.Data
When PINC = 0x01, PORTD = 0x04
When PINC = 0x04, PORTD = 0x10
When PINC = 0x05, PORTD = 0x14
When PINC = 0x07, PORTD = 0x1C
C.Discussion
When DDRn is ‘1’, it becomes read mode. when DDRn is ‘0’, it becomes Write mode.
DDRC = 0x00
7bit
6bit
5bit
4bit
3bit
2bit
1bit
0bit
0
0
0
0
0
0
0
0
R
R
R
R
R
R
R
R
Read all the bit of DDRC
DDRD = 0x3C
7bit
6bit
5bit
4bit
3bit
2bit
1bit
0bit
0
0
1
1
1
1
0
0
R
R
W
W
W
W
R
R
DDRD bit 5:2 Write
if(PINC != 0x0F)
PORTD = (~(PINC<<2)) & 0x3C;
Port C is connected to the switches. The ones we used were bit 3:0 of portC. When a pin is ‘1’, It becomes off state. When a pin is 0, it becomes on state. As “if” statement activates when all the bit 3:0 of pinc is not ‘1’, it operates when no switches are pressed. It gets the switches’ on/off information with PINC and shift 2 bit to the left. Then reverse ‘0’ with ‘1’, ‘1’ with ‘0’ which is the pin state and compare portC which is the port of LED with 0x3C which is in writing mode. When both are 1, bit of portD has a value ‘1’.
For example, press bit2 and bit0 of the switch.
PINC=0x05
7bit
6bit
5bit
4bit
3bit
2bit
1bit
0bit
0
0
0
0
0
1
0
1
on
on
↓
(PINC=0x05)<<2
7bit
6bit
5bit
4bit
3bit
2bit
1bit
0bit
0
0
0
1
0
1
0
0
on
on
↓
~((PINC=0x05)<<2)
7bit
6bit
5bit
4bit
3bit
2bit
1bit
0bit
1
1
1
0
1
0
1
1
&
PORTD=0x3C
7bit
6bit
5bit
4bit
3bit
2bit
1bit
0bit
0
0
1
1
1
1
0
0
↓↓
As 5bit and 3 bit are both ‘1’, 5bit and 3bit of PORTD is ‘1’.
PORTD
7bit
6bit
5bit
4bit
3bit
2bit
1bit
0bit
0
0
1
0
1
0
0
0
When bit2 and bit0 of the switch is pressed, 5bit and 3bit of LED port turn on.
3.HW2
A.Source Code
#include
#include
#define F_CPU 11059200UL
int main()
{
unsigned int i;
DDRD = 0xff;
PORTD = 0x01;
while(1){
for(i=0;i<8;i++)
{
_delay_ms(200);
PORTD = PORTD << 1;
}
PORTD = 0x10;
for(i=0;i<8;i++)
{
_delay_ms(400);
PORTD = PORTD >> 1;
}
PORTD = 0x01;
}
return 0;
}
B.Data
C.Discussion
It is an application of ex1, we can see that the LED turns on 1 bit up orderly, and turns on 1 bit down orderly as a result. In other words, moves 1bit to the left, with PORTD = 0x10; among the 4 LED, the very top LED returns to an initial value. Afterwards, with “for” statement, move 1 bit to the right so that to turn on the LED downwards in order. With PORTD = 0x01; turn on the LED which was turned on at the beginning.
4.HW3
A.Source Code
#include
int main(void){
DDRC = 0x00;// port C의 bit 7:0 을 Read으로 선언
DDRD = 0x3C;// port D의 bit 5:2 를 Write으로 선언
while(1){
if(PINC != 0x0F)// pin C의 bit 3:0가 high가 아니라면 작동
PORTD = (~(PINC<<2)) & 0x3C;
else
PORTD = 0x00;
}
return 0;
}
B.Data
When PINC = 0x01, PORTD = 0x04
When PINC = 0x04, PORTD = 0x10
When PINC = 0x05, PORTD = 0x14
When PINC = 0x07, PORTD = 0x1C
C.Discussion
When DDRn is ‘1’, it becomes read mode. when DDRn is ‘0’, it becomes Write mode.
DDRC = 0x00
7bit
6bit
5bit
4bit
3bit
2bit
1bit
0bit
0
0
0
0
0
0
0
0
R
R
R
R
R
R
R
R
Read all the bit of DDRC
DDRD = 0x3C
7bit
6bit
5bit
4bit
3bit
2bit
1bit
0bit
0
0
1
1
1
1
0
0
R
R
W
W
W
W
R
R
DDRD bit 5:2 Write
if(PINC != 0x0F)
PORTD = (~(PINC<<2)) & 0x3C;
Port C is connected to the switches. The ones we used were bit 3:0 of portC. When a pin is ‘1’, It becomes off state. When a pin is 0, it becomes on state. As “if” statement activates when all the bit 3:0 of pinc is not ‘1’, it operates when no switches are pressed. It gets the switches’ on/off information with PINC and shift 2 bit to the left. Then reverse ‘0’ with ‘1’, ‘1’ with ‘0’ which is the pin state and compare portC which is the port of LED with 0x3C which is in writing mode. When both are 1, bit of portD has a value ‘1’.
For example, press bit2 and bit0 of the switch.
PINC=0x05
7bit
6bit
5bit
4bit
3bit
2bit
1bit
0bit
0
0
0
0
0
1
0
1
on
on
↓
(PINC=0x05)<<2
7bit
6bit
5bit
4bit
3bit
2bit
1bit
0bit
0
0
0
1
0
1
0
0
on
on
↓
~((PINC=0x05)<<2)
7bit
6bit
5bit
4bit
3bit
2bit
1bit
0bit
1
1
1
0
1
0
1
1
&
PORTD=0x3C
7bit
6bit
5bit
4bit
3bit
2bit
1bit
0bit
0
0
1
1
1
1
0
0
↓↓
As 5bit and 3 bit are both ‘1’, 5bit and 3bit of PORTD is ‘1’.
PORTD
7bit
6bit
5bit
4bit
3bit
2bit
1bit
0bit
0
0
1
0
1
0
0
0
When bit2 and bit0 of the switch is pressed, 5bit and 3bit of LED port turn on.
추천자료
자신의 학과소개-전자공학부
전자공학이란 무엇인가
[전자공학] 등가전원정리 결과리포트
전자공학에 대하여
(전자공학) 슈미트 트리거
옵셋 리소그래픽 프린팅(Offset Lithographic Printing) 기법의 특징 및 공정법과 유기전자공...
전력전자공학 1장2장 연습문제풀이
[전자전기공학] 반도체 생산공정
전자공학과 윤리강령
[전자전기공학] 저항 콘덴서 코일 특성 - Resistor, capacitor, Inductor의 특성과 응용
재료공학실험 인장실험
화학공학실험 - 고정층(fixed bed)과 유동층(fluidized bed) 실험
최신디지털공학실험 제10판 실험 2 논리 프로브 구성 : 7404 인버터 사용한 간단한 논리 프로...
[학업계획서] 2009학년도 KAIST(카이스트) 학사과정 입학전형 - 자기소개서 (전기 및 전자공...
소개글