Docsity

Tutorial 1 Embedded Microcontrollers, Exercises of Microcontrollers

Partial preview of the text

Download Tutorial 1 Embedded Microcontrollers and more Exercises Microcontrollers in PDF only on Docsity!

Q1) Write comments next to the following simple program explaining the purpose of each portion of code.

Q2) Locate and correct the error in the code.

#include "derivative.h" void delay () { int i; for (i=0; i<1000000; i++) { asm ("nop"); } } int main ( void ) { SIM_SCGC5 |= SIM_SCGC5_PORTD_MASK; PORTD_PCR(5) = PORT_PCR_MUX(1) | PORT_PCR_DSE_MASK | PORT_PCR_PE_MASK | PORT_PCR_PS_MASK;

GPIOD_PDDR |= 1<<5;

for (;;) { GPIOA_PTOR = 1<<5; delay(); } return 0; }

Further Questions

What port and pin is being used in the above example?

How fast will the port pin change?

How could I approximately double the speed of change?

Why do I need the delay?

What might happen if I remove the nop?

Why is a counting loop not a good idea?