( 我第一次接触这个, 老师就叫写 , 我完全不懂这是什么 ,一片茫然, 如果有大神知道 请求告知。 感激不尽!!!!!! 以下是4个要写的程序)
1.Write a program to congure pin PB1 as an output. Toggle PB1 high-low repetitively as fast
as possible, this will result in a square wave. With an O-scope measure the period of the square
wave. Comment on the frequency of this square wave and if it falls within your expectations
given the C is running at 16 MHz (i.e. how many cycles do you estimate your loop is taking).
Comment on the duty cycle of the square wave, if it is not 50% explain why. Include an O-scope
screen capture of the signal on PB1.
2.Use the output pin PB1 and an O-scope to create our own delay function. Create a function void
myHardDelay(uint32 t delayInMsec), when called will delay an integer number of milliseconds
before returning. Inside the function create a delay by looping N * delayInMsec times. You will
have to experiment to nd a value N that provides an accurate delay function. This function
should now be used in future projects, replacing the Arduino wiring library function delay().
What is your value for N? Using your delay function create a 100 Hz square wave on PB1 and
include an O-scope screen capture. How accurate is your delay function at 1 and 1000 msec's?
What it the maximum delay of your myHardDelay()?
3.Write a function to de-bounce the input pin PB0. Once you de-bounce the pin, if there is a
change in the status write a message to the serial monitor program using the USART (you
may use the Arduino wiring library for this). Test your input with a push button connected
to ground. Enable the internal pull up on PB0. Make sure your de-bounce function doesn't
report false presses or releases of your button. You will use this function in future programs
and want to accurately detect when a button is pressed and released with out repeats of the
event or missing it altogether. How long was your delay between reads of the input pin and
why did you choose that value?
4.Use PB0 and PC0 as inputs to control two LED's that are attached to PD6 and PD5. PD6
LED should be an OR of the two inputs. The PD5 LED should be an AND of the two inputs.
When a de-bounced input change is detected on either PB0 or PC0 write a debug message
using the Arduino wiring library and the serial monitor program to view it. (Hint: You will
need a breadboard, 2 LED's and 2 current limiter resistors. Don't forget to current limit each
LED with a resistor). What is the value of your current limiting resistor and why did you
choose that value? What is the max current the ATmega328P can source and sink per GPIO
line (Hint: Look at the data sheet )? Does your program behave as expected?
|