Micro Askiseis Ear11
date post
23-Oct-2015Category
Documents
view
121download
3
Embed Size (px)
description
Transcript of Micro Askiseis Ear11
. .
2011
1.
2. 7-SEGMENT DISPLAY
3.
4. INTERRUPTS
5. O TIMER0
6. O TIMER1
7.
8.
9. /D
10.
M - 1 1
A 1
/
:
_ _
: 1. VR
(STK200/CodeVision C). 2. -
C. _ _
ATmega16 32 -, 4 (ports) A,B,C D. 8-bit, bit / . 3 : 1. M DDRx ( x=A,B,C,D) x
( bit 0) ( bit 1). ,
DDRA = 0b11000000; 0-5 6-7 .
2. PINx x, . ,
k = PINB; k ( unsigned char, . 8 bits)
bits ( 1 0) 8 .
3. H bits PORTx ( DDRx). , , PORTx (0 [0 Volt] 1 [5 Volt]) . , / (pull-up resistor), 1/0 bit . ,
DDRC = 0xf0; PORTC = 0x0f; 0-3 C pull up,
4-7 0 Volt. H Codevision C bits 3 . / , bitwise (""). :
DDRC.2 = 1; O 2 C PORTC.2 = 0; 2 C 0 Volt if (PINB.3 == 0).. 3
, ( 1 0). , .. ( ) C 1, PORTC :
M - 1 2
PORTC = 0b11111111; { } , PORTC = 255; { } , PORTC = 0xff; { }
- / STK200 8 (SW0-SW7) 8 (LED0-LED7). LED LEDn 0 Volt. , SWn 5 Volt . , (SW0 - SW7) D , (LED0 LED7) B.
LED PORTB.2 = 0; A LED2 PORTB.4 = 1; LED4
if (PIND.3 == 0) SW3 if (PIND.2 == 1) SW2
_ _
CODEVISION C , AVR E:
1. CodeVisionAVR ( desktop ).
2. project ( File -> New..).
3. , project .
4. (CodeWizard) Yes.
5. :
Chip
(i) Chip ATmega16
(ii) Clock 8,0 z
(iii) Program Type Application
- , , STK200
M - 1 3
6. File Generate, Save and Exit.
. directory . , 1 :
D:\MIKRO_ERG\HLEK1\ASK1\
directory, 3 . Ask1 .
7. , CodeVision Ask1.c CodeWizard. , .
, . , , ( Ctrl-A) delete.
, ( )
#include void main(void) {
#include ,
DDRB = 0b11111111; (0..7) B PORTB = 0b11111111;
1, LED
DDRD = 0b00000000; (0..7) D PORTD = 0b11111111;
pull-up D
while(1) {
( TRUE)
PORTB = 0xF8; PORTB 3 LED (LED0-2) 5
} while(1) ! } ( )
M - 1 4
DOWNLOAD
1. 8 LED STK200 , , B . LED pull-up (330) (Vcc).
2. ( LED ).
3. Project CodeVisionAVR Configure.
4. After Make Program The Chip OK.
!
5. Project CodeVisionAVR Make. , compile . , Program. , Make.
6. Program FLASH .
M - 1 5
_STK 200 _
PORT B
PORT A
PORT C
PORT D
LED0-LED7LED ISPLED
/ FF
ISP
SW0-SW7
jumpers STK200
Bit 0 Bit 1
Bit 7Bit 6VccGnd
PORTx (x=A, B, C, D) headers
STK200.
M - 1 6
_STK 200 _
Atmel ( ).
6 ( pin 2X5 IDC10) pin .
8 . 8 LED . 2 LED, . RS232 ( / ). Brownout ( ). Flash. EEPROM. 8 MHz ( 16 MHz). ISP (In System Programming) USB ( programmer ) /.
M - 1 7
1.1 LEDs
, PORTB, LED. LED0 STK200.
( ) PORTB : o LED{0 1 2 3 4} :
o LED{0 2 4 6} :
, directory , Save as , Ask11.c . , , , sk1.c, . , . , .
1.2
8 LEDs (LED0-LED7) PORT B ( ) a b.
: 255 8 bit. LED 1 0 . #include // unsigned char a=25; // (1 byte: 0-255) unsigned char b=3; unsigned char sum;
void main(void) { DDRB=0xff; // Port B sum=a+b; //
while(1) // { PORTB= ~sum; // Port B } // ~ sum } // LED 0 ,
LEDs. a b LED. C:
A++; // A 1 ( =+1) A--; // 1 ( =-1) A+=2; // 2 ( =+2) A-=3; // 3 ( =-3) A*=2; // ( =*2) A/=5; // 5 ( =/5)
a=210 b=80 . , .
M - 1 8
1.3
D 8 () SW0-SW7 STK200. D PIND LED PORTB.
SW0-SW7 0 , . AVR pull-up (330) PORTD=0xFF;.
: pull-down , , 8 10 GND.
#include // unsigned char a; //
void main(void) { DDRB=0xff; // B DDRD=0x00; // D PORTD=0xff; // : pull-up D
while(1) // { a=PIND; // D a PORTB=a; // a B } } , while :
PORTB = PIND; // Port D // PORT B
LED .
M - 1 9
1.4 if
SW1 LED4, SW2 LED6, SW3 LED.
#include // void main(void) { DDRB = 0xFF; // Port B PORTB = 0xFF; // , LED DDRD = 0x00; // Port D PORTD = 0xFF; // pull-up resistors Port D while(1) { if(PIND.1==0) // SW1 PORTB.4 = 0; // LED4 ( ) if(!PIND.2) // SW2 PORTB.6 = 0; // LED6 ( ) if(!PIND.3) // SW3 PORTB = 0xFF; // LED } } ( ) if (PIND.1==0) :
if(PIND==0xFD) ( ) if(PIND.1==0) ():
if(!(PIND&=0x02)) ( ) PORTB.4 = 0; PORTB = 0xEF;
LED SW0 SW7 SW3 SW4.
1.6
AVR Studio, ( )
M - 1 10
AVRStudio AVRStudio , , PC AVR. , compiler. ( /). ( 3 AVRStudio).
Codevision, compile , AVRStudio
AVRStudio, :
AVR Studio,
. ( , Alt+5 ).
(, , /, .) / ( ). , B D :
Debug , , . Trace into, F11 ( ). , I/O.
STK200, ( 1) "Input Pins" PORTD . STK200, , , .
- 2 1
A 2
:
_ _
(interrupts), interrupts. seven segment display , (delay).
_ _ , ,
7 (7 segment display) 0-9. 7 (LED) ( a, b, c, d, e, f g ), LED ( . dp), . . , 7 , display 8, , , a,b,c,d g, 3.
a b
c
de
fg CA
CA
ab
c
de
fg
.
To display (S52-11HA) (common anode), ( ). , display +VCC, segments 0 .
, display , flat idc-10, C, .
LLLLLLL
CA
+
ab
cd
e
fg
5 V
330R
5 V
LLLLLLL
L 557
CA
+
ab
cd
e
fg
Gated
BC557
PNP
5 V
L(0V)
1,5 K
a b g
330
CA
L L L
- 2 2
2.1 7 (seven segment display)
STK200, display (0-7). display .
D , SW0-SW7.
#include
void main(void) { DDRC =0xFF; PORTC=0xFF; //, display DDRD =0x00; //Port D PORTD=0xFF;
while(1) { switch(PIND) // { case 0xFE:PORTC=~0x3F;break; // SW0 display 0 case 0xFD:PORTC=~0x06;break; // SW1 display 1 case 0xFB:PORTC=~0x5B;break; // SW2 display 2 case 0xF7:PORTC=~0x4F;break; // SW3 display 3 case 0xEF:PORTC=~0x66;break; // SW4 display 4 case 0xDF:PORTC=~0x6D;break; // SW5 display 5 case 0xBF:PORTC=~0x7D;break; // SW6 display 6 case 0x7F:PORTC=~0x07;break; // SW7 display 7 default: PORTC=~0x00;break; // , // display } } } ( PORTC) display ;
2 .
default .
, SW3 SW5 display .
- 2 3
2.2
display , C. display .
#include
unsigned char button[] ={ 0xFE, 0xFD, 0xFB, 0xF7, 0xEF, 0xDF, 0xBF, 0x7F}; //buttons unsigned char display[]={~0x3F, ~0x06, ~0x5B, ~0x4F, ~0x66, ~0x6D, ~0x7D, ~0x07}; //display unsigned char i; void main(void) { DDRC =0xFF; PORTC=0xFF; DDRD =