, .
mikroC PRO for AVR . .
1. , : B0, B1, B2, B3, B4, B5, B6, B7, 0 .
:
// ,
PORTC.B0 = 1; // . 1 0-
PORTC.B7 = 0; // . 0 7-
SREG.B7 = 1; // 1
// (7- SREG)
2. , : _bit.
:
SREG_I_bit = 1; // 1 SREG_I SREG
// ( 7- )
, , :
DDRA DDA0_bit, DDA1_bit, , DDA7_bit;
PORTA PORTA0_bit, PORTA1_bit, , PORTA7_bit;
PINA PINA0_bit, PINA1_bit, , PINA7_bit.
(B, C, D, ) .
// ,
PORTC0_bit = 1; // . 1 0-
PORTC7_bit = 0; // . 0 7-
. mikroC , . :
1) Delay_us(), ( unsigned long 1 4294967295);
2) Delay_ms(), ( unsigned long 1 4294967295);
3) Vdelay_ms(), ( unsigned int, 1 65535).
:
Delay_us(100); // 100
Delay_ms(2000); // 2000 = 2
unsigned int time = 500;
Vdelay_ms(time); // 500
(), ATmega16 , 0- () C. ( Proteus) , 1. ( 1) PC0 , ( 0) PC0 .
1 -
|
|
, 0,5 , 1 .
:
1) B0, B1, , B7;
2) _bit.
/**********************************************************
led_1.c (1- )
***********************************************************/
void main()
{
DDRC.B0 = 1; // 0-
PORTC.B0 = 0; // D1
while(1) //
{
PORTC.B0 = 1; // D1
Delay_ms(500); // 500
PORTC.B0 = 0; // D1
Delay_ms(500); // 500
}
}
.
/***********************************************************
led_2.c (2- )
***********************************************************/
void main()
{
DDC0_bit = 1; // 0-
PORTC0_bit = 0; // D1
while(1)
{
PORTC0_bit = 1; // D1
Delay_ms(500);
PORTC0_bit = 0; // D1
Delay_ms(500);
}
}
, mikroC (). 2 ( Proteus), D1 () SB1 . SB1 , D1 , SB1 , D1 . D1 SB1. , SB1 .
. 2 PB1 (1- ) SB1. , ( ) , ( 1) .
AVR- , , .. . 1 PORTx , .
.
DDRC = 0; //
PORTC = 0xFF; //
//
.
DDRA.B2 = 0; // 2- (PA2)
PORTA.B2 = 1; // PA2
.
DDB1_bit = 0; // 1- (PB1)
PORTB1_bit = 1; // PB1
, if . else.
***********************************************************
|
|
led_but_1.c
**********************************************************/
void main()
{
DDRB.B1= 0; // 1- B
PORTB.B1 = 1; //
// PB1
DDRC.B1 = 1; // 1-
PORTC.B1 = 0; //
while(1) //
{
if(PINB.B1 ==0) // SB1 ,
PORTC.B1 = 1; //
else //
PORTC.B1 = 0; //
}
}
2
, SB1 while.
/**********************************************************
led_but_2.c -
********************************************************* */
void main()
{
DDB1_bit = 0; // 1-
PORTB1_bit = 1; //
// PB1
DDC1_bit = 1; // 1-
PORTC1_bit = 0; //
while(1) //
{
while(PINB1_bit == 1); // SB1
PORTC1_bit = 1; //
while(PINB1_bit == 0); // SB1
PORTC1_bit = 0; //
}
}