Adsense

Steps to realize basic embedded C code to blink green LED with some finite delay.

Free-scale Memory Map

Input output registers ranges from 0x400FF000 to 0x400FFFFF - we need to memory map every time when we perform simulation without kit. While flashing code into the kit memory mapping is necessary.


Memory Map of GPIO

Each port registers description is given below please refer figures for the same.

 


 

GPIO Programming and Interfacing

Port Data Output Register (GPIOx_PDOR): In the case of Freescale ARM chip, each of the Direction register needs to be a 0 to configure the port pin as input and a 1 as output.

 

 

The GPIO Clock enable for the I/O ports


 

 

Alternate pin functions and the simple GPIO

 

Portx_PCR of each port will be used for the configuration of the alternate functions bit 8-10 decides mux value and it will decide the function mentioned below.  

 

 

 Alternate functions and their descriptions.

 

 

 

LED connection in Freescale FRDM board

 

 

(1) Enable the clock to PORTB by setting 1 to SCGC5 register bit no 10, since access is denied to the port registers until the clock is enabled,

(2) Configure PortB_PCR19 (Pin Control Register) to select GPIO function for PTB19, by setting mux field (bit no 8 to 10) of the PCR19 register to 001.

(3) Set the Direction register bit 19 of PTB as output. by setting values 1 to bit 19 on PDDR register.

(4) Write HIGH to PTB19 in data register, to turn off the LED.

(5) Call a delay function,

(6) Write LOW to PTB19 in data register, to turn on LED.

(7) Call a delay function,

(8) Repeat steps 4 to 7.

 

 

How to simulate the basic LED blinking embedded C code on FRDM KL25Z freedom board ?

 // this is basic LED blinking code realize without external header file of the MKL25Z.h

/* System Integration Module System Clock Gating Control Register 5*/
#define SIM_SCGC5   (*((volatile unsigned int*)0x40048038))
/* Port B Pin Control Register 19*/
#define PORTB_PCR19 (*((volatile unsigned int*)0x4004A04C))
/* Port B Data Direction Register */
#define GPIOB_PDDR  (*((volatile unsigned int*)0x400FF054))
/* Port B Data Output Register */
#define GPIOB_PDOR  (*((volatile unsigned int*)0x400FF040))


int main (void) {
    void delayMs(int n);

    SIM_SCGC5 |= 0x400;             /* enable clock to Port B */
    PORTB_PCR19 = 0x100;            /* make PTB19 pin as GPIO (See Table 2-4) */
    GPIOB_PDDR |= 0x80000;          /* make PTB19 as output pin */

    while (1) {
         /* turn on green LED */
                GPIOB_PDOR &= ~0x80000;   
        delayMs(1000);
                       
                /* turn off green LED */
        GPIOB_PDOR |= 0x80000;      
        delayMs(1000);
    }
}

/* 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++) {}
}
 

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...