Download MicroCamp2.0 - SparkFun Electronics
Transcript
54 l MicroCamp : ATmega8 Activity Kit Manual
6.1 Command in in_out.h library
6.1.1 Digital input port reading function
in_b : Port B input reading function
in_c : Port C input reading function
in_d : Port D input reading function
Function format :
char
char
char
char
in_a(x)
in_b(x)
in_c(x)
in_d(x)
Parameter :
x - determines the number of the input port that will be used. The value is 0 to 7.
Return value :
“0” or “1”
Example 6-1
char x=0;
x = in_b(2);
// Declare x to store the result.
// Get PB2 value to store in x
Example 6-2
char x=0;
x = in_d(4);
// Declare x to store the result.
// Get PD4 value to store in x
Example 6-3
#include <avr/io.h>
// Includes the Standard input/output port library
#include <in_out.h>
// Includes the Port control library
#include <sound.h>
// Includes the Sound generator library
void main()
{
while(1)
{
if (in_d(2)==0)
// Check SW1 pressed ?
{
sound(3000,100);
}
}
}
// Generate sound if SW1 is pressed