Wednesday, 15 April 2015

[Freescale K20D50M MCU Programming] #2 Blinky Red LED onboard

#2  Blinky Red LED onboard


Lets try out blinking the RED onboard LED. We are going to use Codewarrior and processorexpert with FRDM-K20D50M board

Take a look at the [Freescale K20D50M MCU Programming] #1 Helloworld on the Console using Processor Expert  for quickstart 

Lets get started.


First we need to see the schematic to identify the onboard LED.  There is a good youtube video which gives an example on K25Z board.




LED  Schematic :





Red LED connected to D6.
Green LED connected to D3
Blue LED connected to D9



Identify the Ports and Pins for the LED's :



Red, look for D6





Green, Look for D3



Blue, Look for D9








The FRDM-K20D50 CPU uses the Blue LED. So, this has to be disabled to get this on-board LED to work.




Then Lets add BITIO_LDD component, 1 for each LED to control them.

Now lets setup the Bit_IO pins for the 3 LED's.  LED Cathode is connected to the microcontroller pin. i.e., Low Level (0) turns it on, and (1) turns it off.   By default we need to set all the 3 LED's to (1) to turn it off.


WE add 3 BitIO_LDD Components, for RED, Green and Blue. 




Green LED -> Switch off by Default. Cathode connected. So 1 is Off


Blue LED -> Switch off by Default. Cathode connected. So 1 is Off. But this pin is used by CPU, so enable PIN Sharing.




Red LED -> Switch ON by Default. Cathode connected. So 0 is On.



Now build and Run the Main.c  you will see the RED LED glowing by the code is flashed.







Now lets make a blinky. :-)


We need to enable the NegVal() method of the BitIO_LDD






And add this code in the main.c or processorexpert.c

int main(void)
/*lint -restore Enable MISRA rule (6.3) checking. */
{
  /* Write your local variable definition here */

  /*** Processor Expert internal initialization. DON'T REMOVE THIS CODE!!! ***/
  PE_low_level_init();
  /*** End of Processor Expert internal initialization.                    ***/

  for(;;)
  {
 int i =0;
 for(i=0;i<=1000000;i++)
 {
 }
 RED_LED_NegVal(NULL);  // Blink the RED Led
  }
  

Here is the blinky.


video

CodeWarrior, PEX Project :   Download  onboard_blinky.zip

No comments:

Post a Comment