Survey

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts

Evolving digital ecological networks wikipedia , lookup

Digital rhetoric wikipedia , lookup

Digital signature wikipedia , lookup

Transcript
```Use of Digital IO
Project Goals:
 Familiarize user with the Digital IO control functions
Equipment needed:
 PC or laptop computer equipped with MPLAB IDE
 PIC32 Starter kit
 Robot Platform
Lab Prerequisite:
 User need to be familiar with the concept of functions in C programming
language and know how to use functions.
Pre Lab Activities:
 Study the tutorial for this lab and do the sample project
Safety concerns
 There are no safety concerns
Tips:

Make sure the following line is included in program before main () routine.
#include "System.h"

Make sure following line is included in first line of code in the main() routine
InitRobot();
Robot Training Manual – Lesson 8
Page 1
Tutorial:
If you remember from the last lab, line following sensor could return any value from 0 to
3.3 volts depending on the intensity of the black color. We call this sort of signals analog
signal since they can give us a range of continuous values.
In contrast to the analog signal, digital signal could only have two values associated with
it. For example a lamp could be either ON or OFF.
If we had used digital line following sensor for the robot instead, this sensor could only
return 3.3v for a black line and 0v for white line.
Since the digital signals only take two values we can refer to these values as state instead
of referencing the voltage on the pin.
The convention is to call the higher level of voltage HIGH and lower voltage LOW
states. To make it easier when there is a need to do arithmetic we call these states 0 and 1
Robot Training Manual – Lesson 8
Page 2
All processors can only work with digital values. In fact the sole purpose of the Analog to
digital converser module on the microcontroller is to convert the analog values to digital
counterparts, so the microcontroller could understand and be able to read the analog
signal.
The digital pin on the microcontroller could be used for many purposes based on the
project at hand. In this lab however we use them to read the state of a switch. We also use
the digital pin to turn on and off an LED.
The robot has 8 general purpose digital IO pins. Any of these digital IO pins could be
configured as a digital input or digital output.
Digital.ConfigureAsInput
Description: This function set the desired digital pin as digital input
Prototype: void ConfigureAsInput (int DigialChannel)
Arguments: DigialChannel : Desired pin to be set as input (DIO0 – DIO7)
Return Value: None
Remark: Once a pin is configured as digital input it will stay that way until it is
configured otherwise
Digital. ConfigureAsOutput
Description: This function set the desired digital pin as digital output
Prototype: void ConfigureAsOutput (int DigialChannel)
Arguments: DigialChannel : Desired pin to be set as output (DIO0 – DIO7)
Return Value: None
Remark: Once a pin is configured as digital output it will stay that way until it
configured otherwise
Digital.Get
Description: when the pin is configures as digital input, it will read the digital state of
the pin
Prototype: unsigned char Get (int DigialChannel)
Arguments: DigialChannel : Desired pin to be read (DIO0 – DIO7)
Return Value: The current digital state of the pin
Remark: Make sure the pin is configured as digital input before calling this function;
otherwise the value returned by function would not be correct
Digital.Set
Robot Training Manual – Lesson 8
Page 3
Description: when the pin is configures as digital output, it will set the digital state of
the pin
Prototype: void (int DigialChannel , unsigned char State)
Arguments: DigialChannel : Desired pin to be set(DIO0 – DIO7)
State: Desired state of the pin, 1 set the pin to high state and 0 will set it to
low state
Return Value: None
Remark: Make sure the pin is configured as digital input before calling this function;
otherwise the value returned by function would not be correct
Remarks: To ensure the functions execute properly use the predefined DIO0 – DIO7 to
designate each digital channel in above functions.
Example: To set DIO0 as digital input and read its state:
unsigned char State;
Digital.ConfigureAsInput(DIO0);
State = Digital.Get(DIO0);
Example: To set DIO1 as digital output and set it to high:
unsigned char State;
Digital.ConfigureAsOutput(DIO1);
Digital.Set(1);
Robot Training Manual – Lesson 8
Page 4
```
Related documents