Adsense

Write Embedded C code to blink green LED with MKL25Z4.h library on KL25Z FRDM board.

 /* Toggling green LED on FRDM-KL25Z board with MKL25Z library
 * Program toggles green LED on the FRDM-KL25Z board.
 * The green LED is connected to PTB19.
 * The LEDs are low active (a '0' turns ON the LED).
 */

#include <MKL25Z4.H>

int main (void) {
    void delayMs(int n);
        
        // setup part includes Enable of clock, configure GPIO and output
    
    SIM->SCGC5 |= 0x400;        /* enable clock to Port B */
    PORTB->PCR[19] = 0x100;     /* make PTB19 pin as GPIO */
    PTB->PDDR |= 0x80000;       /* make PTB19 as output pin */
    
        // always run loop
    while (1) {
        PTB->PDOR &= ~0x80000;  /* turn on green LED */
                delayMs (20000);
                PTB->PDOR |= 0x80000;  /* turn off green LED */
                delayMs (20000);
    }
}

/* Delay n milliseconds
 * The CPU core clock is set to MCGFLLCLK at 41.94 MHz in SystemInit().
 */
void delayMs(int n) {
    int i;
    int j;
    for(i = 0 ; i < n; i++)
        for (j = 0; j < 16000; j++) {}
}

Write the embedded C code to blink all three green, red and blue the LEDs on the FRDM-KL25Z4 after 500ms.

 /* Toggling all three LEDs on FRDM-KL25Z board.
 * Program toggles all three LEDs on the FRDM-KL25Z board.
 * The red LED is connected to PTB18.
 * The green LED is connected to PTB19.
 * The blue LED is connected to PTD1.
 * The LEDs are low active (a '0' turns ON the LED).
 */

#include <MKL25Z4.H>

int main (void) {
    void delayMs(int n);
        
        // setup part includes Enable of clock, configure GPIO and output
    
            SIM->SCGC5 |= 0x1400;        /* enable clock to Port B */
            PORTB->PCR[18] = 0x100;     /* make PTB18 pin as GPIO (See Table 2-4)*/
            PORTB->PCR[19] = 0x100;     /* make PTB19 pin as GPIO */
            PTB->PDDR |= 0xC0000;       /* make PTB18, 19 as output pin */
            PORTD->PCR[1] = 0x100;      /* make PTD1 pin as GPIO */
            PTD->PDDR |= 0x02;          /* make PTD1 as output pin */
        
        // always run loop
    while (1) {
                PTB->PDOR &= ~0x80000;  /* turn on green LED */
                delayMs (500);
                PTB->PDOR |= 0x80000;  /* turn off green LED */
                delayMs (500);

                PTB->PDOR &= ~0x40000;  /* turn on red LED */
                delayMs (500);
                PTB->PDOR |= 0x40000;  /* turn off red LED */
                delayMs (500);
            
                PTD->PDOR &= ~0x02;     /* turn on blue LED */
                delayMs(500);
                PTD->PDOR |= 0x02;      /* turn off blue LED */
                delayMs(500);
    }
}

/* Delay n milliseconds
 * The CPU core clock is set to MCGFLLCLK at 41.94 MHz in SystemInit().
 */
void delayMs(int n) {
    int i;
    int j;
    for(i = 0 ; i < n; i++)
        for (j = 0; j < 7000; j++) {}
}

Step to realize the interfacing of switch and LED with KL25Z FRDM board.

Interfacing diagram of Switch and LED with FRDM KL25Z board


 switch taken from 4X4 matrix keypad

- Switch 1 from matrix keypad is taken as one of the switch and for that we need to connect the matrix   key pad to the FRDM KL25Z board with the port C pin 0-3 as for row and 4-7 as column.

- However we will use single key from 16 keys of the 4X4 matrix keypad, to demonstrate the switch and LED interface with the KL25Z board.

 Steps:

1) Enable clock to the ports C-keypad and D- blue LED connected.

2) to configure the switch we need to follow below mention steps.

- Row connected as an output and column connected as an input configure all through respective pin's PDDR registers.

- Columns are connected as input and connected through the internal pull up registers. 

- to configure input pullup registers enable bits 0 (PS) and 1 (PE) of PCR along with MUX field- bits 10-8 as GPIO ( 001). For details you can refer the diagram given below.

- 0x103 is the number that we need to load in to PCR of particular pin to configure it with the internal pull up register.

- Rows are connected as output and we need to configure it as GPIO through PCR register by loading 001 into bits 10-8 of MUX field. 

3) Configure blue LED of the board as output through PDDR register.

4) Apply logic to  detect the switch.

5) if switch is detected LED should glow and not than LED turned off.


  

 


Write a ARM cortex M0+ assembly language code based on arithmatc and logical instructions.

 Problem 1: Implement following code conversions to convert binary no 0x89ABCDEF(32-bits) into a) BCD (64-bits)   b) Gray (32-bits) Problem...