Вы находитесь на странице: 1из 13

10.

AVR

.
[1,3,4], AVRMega
c AtmelStudio 6.
, .
Proteus .
:
- 1 B;
- B;
- 1
pn2222.

1.
Proteus.
2. ,
.

Proteus.
:
1. . .
.
2.
(SchematicCapture).
3. .
4. ComponentMode P.
5. :
- res.
- AVRATMega8 atmega8.
- () led-green.
- pn2222.
6. TerminalsMode

GROUND.
7. B (
) ATMega8 100
.1.

.1. .

8. Proteus
.
9. AtmelStudio 6. , ,
.
10. , GCCCExecutableProjectC/C++.
.
11. ATMega8.
OK .
#include<avr/io.h>// /
intmain(void)
{
while(1)
{
//TODO:: Please write your application code
}
}

12. [_delay_ms(ms:int), _delay_us(us:int)]


.
#inlude<util/delay.h>,
.
13.
, .

DDRB B, DDRC C DDRD D.
B .
, .
, .
:
a. DDRB = 0b11111111; .
b. DDRB = 0xFF; .
c. DDRB = 255; .
2

d. DDRB |= _BV(PB0); .
e. DDRB |= (1<<DDB7)| (1<<DDB6)| (1<<DDB5)| (1<<DDB4)| (1<<DDB3)|
(1<<DDB2)| (1<<DDB1)| (1<<DDB0);
.
14. B : 0
1. PORTB.
, .
PORTB = 0x00;.
15.

.
B
^.
1 _delay_ms(1000);.
16.
RC .
#defineF_CPU 8000000.
8.
17. :
#defineF_CPU8000000 //
#include<avr/io.h>///
#include<util/delay.h>//
intmain(void)
{
DDRB=0xFF; // B
PORTB=0x00; // B
while(1)//
{
//TODO:: Please write your application code
PORTB^=(1<<PB0);// 0 B
_delay_ms(1000);// 1000 = 1
}
}

18.
Ctrl+Shift+B .
hex.
Debug, , .
19. Proteus.
ATMega8
(Editproperties).
Program File hex.
CKSELFuses Int. RC 8MHz OK.
20. , 1 .
21. , , .
USB.
MiniProProgrammer.
3

hex AtmelStudio 6.
Programming chip
.
22.
.
.
2

#include <mega8.h> // ATMega8


#include <delay.h> //
#define led 10 // led
void main(void)
{
PORTC=0x00; // C 0, , C
DDRC=0xFF; // C, , 5
while (1) //
{
PORTC.5=1; // 5- C
delay_ms(led); // ,
PORTC.5=0; // 5- C
delay_ms(led); // ,
}
}


?
?
, , , ?
.
1
1. B ATMega8
100 .1. : 1
4

B.
2. B ATMega8
100 .1. :
B.
3. B ATMega8
100 .1. 1
pn2222.
4. ATMega8
100 .1. : 2
.
5. ATMega8
100 .1. :
.
6. ATMega8
100 .1. : 1
pn2222.
7. D ATMega8
100 .1. : 5
D.
8. D ATMega8
100 .1. :
D.
9. D ATMega8
100 .1. : 1
pn2222.
10. B ATMega8
100 .1. : 7
B.
11. led-blue B
ATMega8 100 .1. :
B.
12. led-blue B
ATMega8 100 .1. 6
pn2222.
13. B ATMega8
100 .1. : 1
B.
14. B ATMega8
100 .1. :
B.
15. B ATMega8
100 .1. 1
pn2222.
16. ATMega8
100 .1. : 2
.
17. ATMega8
5

100 .1. :
.
18. ATMega8
100 .1. : 1
pn2222.
19. D ATMega8
100 .1. : 5
D.
20. D ATMega8
100 .1. :
D.
21. D ATMega8
100 .1. : 1
pn2222.
22. B ATMega8
100 .1. : 7
B.
23. led-blue B
ATMega8 100 .1. :
B.
24. led-blue B
ATMega8 100 .1. 6
pn2222.
25. ATMega8
100 .1. :
.
26. ATMega8
100 .1. : 1
pn2222.
27. D ATMega8
100 .1. : 5
D.
28. D ATMega8
100 .1. :
D.
29. ATMega8
100 .1. : 1
pn2222.
30. D ATMega8
100 .1. : 5
D.

11.


,
/.
PIN.
AVRATMEGA8
. /
( , ).
D, ,
.

1. Proteus (. 2).
2. AtmelStudio 6
.
2. .
3.

.
4. (. 2) ,
, .
5. .

. 2.


D2,
, D3, .
D1,
. D2 D3
.
:
#defineF_CPU8000000
#include<avr/io.h>
#include<util/delay.h>
voidpreset(void)

{
DDRB=0x00;
PORTB=0x00;
DDRC=0xFF;
PORTC=0x00;
DDRD=0xFF;
PORTD=0x00;
}
intmain(void)
{
preset();
while(1)
{
if(PINB&(1<<PB0))
{
PORTC|=(1<<PC1);
PORTC&=~(1<<PC0);
PORTD|=(1<<PD0);
_delay_ms(5);//
}
if(PINB&(1<<PB1))
{
PORTC&=~(1<<PC1);
PORTC|=(1<<PC0);
PORTD&=~(1<<PD0);
_delay_ms(5);//
}
_delay_us(20);
}
}


.
AVR ?
?
?
?
. .
? .
.

12.

L293D

,
.
L293D.
AVRATMEGA8 :
1. (.3).
2. (.4).
2 .

1. Proteus (. 3).
2. AtmelStudio 6
.
3. .
4.
.
5. (. 3) (.
4), ,
.
6. .

. 3. .



, .
:
#defineF_CPU8000000
#include<avr/io.h>
#include<util/delay.h>

voidpreset(void)
{
DDRB=0x00;
PORTB=0x00;
DDRC=0xFF;
PORTC=0x00;
}
intmain(void)
{
preset();
while(1)
{
if(PINB&(1<<PB0))
{
PORTC|=(1<<PC0);
PORTC&=~(1<<PC1);
_delay_ms(25);//
}
if(PINB&(1<<PB1))
{
PORTC&=~(1<<PC0);
PORTC|=(1<<PC1);
_delay_ms(25);//
}
_delay_ms(20);
}
}

.
4
. 1.

1
2
3
4

1.
1
2
3
4
1
1
0
0
0
1
1
0
0
0
1
1
1
0
0
1

10

. 4. .


#defineF_CPU8000000UL
#include<avr/io.h>
#include<util/delay.h>
unsignedcharu=1;
unsignedcharvector=3;

if(PINB&(1<<PC1))
{
if(vector==0)
u=vector_res(u);

intmain(void)
{
preset();
while(1)
{
if(PINB&(1<<PC0))
{

switch(u)
{
case1:
PORTC|=_BV(PC0);
PORTC|=_BV(PC3);
PORTC&=~_BV(PC1);
PORTC&=~_BV(PC2);
u++;
break;
case2:
PORTC&=~_BV(PC0);
PORTC&=~_BV(PC1);
PORTC|=_BV(PC2);
PORTC|=_BV(PC3);
u++;
break;
case3:
PORTC&=~_BV(PC0);
PORTC&=~_BV(PC3);
PORTC|=_BV(PC1);
PORTC|=_BV(PC2);
u++;
break;
case4:
PORTC&=~_BV(PC2);
PORTC&=~_BV(PC3);
PORTC|=_BV(PC0);
PORTC|=_BV(PC1);
u=1;
break;

if(vector==1)
u=vector_res(u);

}
vector=1;
_delay_ms(300);

voidpreset()
{
//
DDRB=0x00;
PORTB=0x00;
//
DDRC=0xFF;
PORTC=0x00;
}
charvector_res(charu)
{
switch(u)
{
case1:u=2;break;
case2:u=1;break;
case3:u=4;break;
case4:u=3;break;
}
returnu;
}

}
switch(u)
{
case1:
PORTC|=_BV(PC0);
PORTC|=_BV(PC1);
PORTC&=~_BV(PC2);
PORTC&=~_BV(PC3);

11

}
}

u++;
break;
case2:
PORTC&=~_BV(PC0);
PORTC&=~_BV(PC3);
PORTC|=_BV(PC1);
PORTC|=_BV(PC2);
u++;
break;
case3:
PORTC&=~_BV(PC0);
PORTC&=~_BV(PC1);
PORTC|=_BV(PC2);
PORTC|=_BV(PC3);
u++;
break;
case4:
PORTC&=~_BV(PC1);
PORTC&=~_BV(PC2);
PORTC|=_BV(PC0);
PORTC|=_BV(PC3);
u=1;
break;

}
vector=0;
_delay_ms(300);


L293D.
L293D.
.
L293D.
Enable 1 Enable 2
.
.
switch.

1 .. : . ,
2012. 588 .
2 .. AVR. . .: . .
, 2007. 240 .
3 .. ATMEL
. .: -, 2012. 320 .
4 .. AVR Mega. .: XXI, 2007. 592 .
5 .. - .
, 2010. 56 .

12

13