arm mannual

Upload: deepansh-agrawal

Post on 13-Apr-2018

257 views

Category:

Documents


0 download

TRANSCRIPT

  • 7/27/2019 Arm Mannual

    1/30

    2012

    ARM

    ARM MANNUAL

    VIKALP

    DRMZ SYSTEM INNOVATIONS PVT. LTD. | Bhopal (MP)

  • 7/27/2019 Arm Mannual

    2/30

    Contents

    1 ARM TUTORIAL ..................................................................................................................................... 2

    1.1 Steps to use KEIL U-Vision .......................................................................................................... 2

    2 Setting up the KEIL .............................................................................................................................. 12

    2.1 You can add groups by using manage components or directly as well ...................................... 14

    3 Snapshots for using manage components tool................................................................................... 18

    4 Sample codes ................................................................................................................................... 26

    4.1 LED blinking on any port ............................................................................................................. 26

    4.2 using lcd ...................................................................................................................................... 26

    4.3 Using ADC .................................................................................................................................... 28

  • 7/27/2019 Arm Mannual

    3/30

    1 ARM TUTORIALSETTINGS OF KEILwith snapshots

    STEPS FOR USING KEIL TO PROGRAMwith snapshots

    SAMPLE CODES

    1) After loading USB boot-loader firmware (already done in our board) to theBlueBoard-LPC214X, (our board has 2148)hold down SW1 (USBBL) and SW3 (RESET), then release SW3 first and finally

    SW1.Now the pre-loaded USB boot-loader which allows you to enumerate the board

    as a Mass Storage Device .Drag the compiled binary file and drop onto the deviceand reset the board using SW3.keep Bluetooth of your device off.

    2) In order to check your board or for using the board first time a number of samplecodes and their corresponding binary files are stored in 2 different folders. Copy thebinary files to the mass storage drive and delete the pre-existing files.

    3) As per my information given LED code is not for this board. So after trying thepre-existing codes you can start coding with Keil-U Vision 4.

    1.1 Steps to use KEIL U-Vision Following are some snapshots of a number of settings which you have to do

  • 7/27/2019 Arm Mannual

    4/30

  • 7/27/2019 Arm Mannual

    5/30

  • 7/27/2019 Arm Mannual

    6/30

  • 7/27/2019 Arm Mannual

    7/30

  • 7/27/2019 Arm Mannual

    8/30

  • 7/27/2019 Arm Mannual

    9/30

  • 7/27/2019 Arm Mannual

    10/30

    Here \Obj\serial.axf and \Obj\serial.bin are just your filenames.

    They can be interpreted as filename.axf and filename.bin

  • 7/27/2019 Arm Mannual

    11/30

  • 7/27/2019 Arm Mannual

    12/30

  • 7/27/2019 Arm Mannual

    13/30

    2 Setting up the KEIL1. Open KEIL uVISION 4

    2. Open a new uVision Project

    3. Choose Philips NXP , then select LPC 2148.

    4 Do not allow it to add default startup file by itself. Do it manually.

    5 Add groups to target and name them as source, docs and startup. (Do this by using manage

    components). Add file startup.s to the folder named source.

  • 7/27/2019 Arm Mannual

    14/30

    6 click on new , write your code , save as main.c, add main.c file to your source group and then build

    your target.

  • 7/27/2019 Arm Mannual

    15/30

    2.1 You can add groups by using manage components or directly as wellDirect method -

  • 7/27/2019 Arm Mannual

    16/30

  • 7/27/2019 Arm Mannual

    17/30

  • 7/27/2019 Arm Mannual

    18/30

  • 7/27/2019 Arm Mannual

    19/30

    3 Snapshots for using manage components tool

  • 7/27/2019 Arm Mannual

    20/30

    Now select source to add startup.s. Click on add files button.

  • 7/27/2019 Arm Mannual

    21/30

    Startup.s added

    Write your code and save it as main.c

  • 7/27/2019 Arm Mannual

    22/30

    Now add your main.c to your group source

  • 7/27/2019 Arm Mannual

    23/30

    Select your main.c and add it

    Adding lcd.h to group source for using lcd

  • 7/27/2019 Arm Mannual

    24/30

    Adding lcd.c to group source

    Copy the c compiler header file lcd.h to the folder in which you are saving your code.

  • 7/27/2019 Arm Mannual

    25/30

    Click on build target to build your binary/hex file.

  • 7/27/2019 Arm Mannual

    26/30

    Try.axf is used to make your try.bin which you have to load into your processor.

    The ones which we can use can be used in 4 ways which is programmable.

    The pins will be in general input/output configuration by default.

    There are 2 registers

    1) Register 0 has 32 and register 1 also has 32 bits.2) We can use all 32 pins of register 0 but we can use only 16thto 31stbit of register 1.3) PINSEL0 and PINSEL1 registers are used to define weather the pin is to be used as GPIO or anyother alternate function.4) IODIR can be used for defining as input/output.5) IOSET is used to write 1 to any output. (*defining 0 by IOSET doesnt mean making output 0)6) IOCLR is used to write 0 to any output. (*defining 0 by IOCLR doesnt mean making output 0)7) In order to use various peripherals like ADC , LCD etc you need to include headers and also add

    files to your source group.

  • 7/27/2019 Arm Mannual

    27/30

    8) The various .c and .h gives you the details of the various functions we are using informationabout their aruguements.

    4 Sample codes 4.1 LED blinking on any port

    include //Including the header

    void delay_sec(unsigned int x) //creating a function for delay using timer

    {

    T0MR0 = x; // x is number of seconds delay as the clock is set for 1 sec

    // which means that the timer counter will increase by 1 in 1 sec.

    T0MCR = 2; // Clear on match mode of timer is used

    T0PR = 0x00E4E1C0; // Prescaler for 1 sec (1 increament means 1 clock pulse in 1

    T0TCR = 0x1; // Enable the timer

    while(T0TC < T0MR0); //Wait till match between counter and number of seconds delay

    T0TCR = 0x0; // Disable the timer

    T0TC = 0x0; //Precautionally clear the counter of timer

    }

    int main (void)

    {

    IODIR1 = 0x00FF0000; //The bits corresponding to 1 will be output and 0 will be input.

    //Here pins 16 to 23 all are output

    while (1)

    {

    IOSET1= 0x00FF0000; // giving output high or 3.3 volts on pins 16 to 23

    delay_sec(100);

    IOCLR1=0x00F00000; // giving output low or 0 volts to pins 20 to 23

    // PSpins 16 to 19 still have 3.3 volts output

    delay_sec(100);

    }

    }

    4.2 using lcd#include //////**** Including the header******/////////////

    #include "lcd.h" //////header for lcd

    unsigned int z=0; //////variable declaretion

    char y = 'a';

  • 7/27/2019 Arm Mannual

    28/30

    void delay_sec(unsigned int x) //////creating a function for delay using timer

    {

    T0MR0 = x; ////// x is number of seconds delay as the clock is set for 1 sec

    //////which means that the timer counter will increase by 1 in 1 sec.

    T0MCR = 2; //////Clear on match mode of timer is used

    T0PR = 0x00E4E1C0; //////Prescaler for 1 sec (1 increament means 1 clock pulse in

    1 sec)

    T0TCR = 0x1; //////Enable the timer

    while(T0TC < T0MR0); //////Wait till match between counter and number of seconds

    delay

    T0TCR = 0x0; //////Disable the timer

    T0TC = 0x0; //////Precautionally clear the counter of timer

    }

    int main (void)

    {

    PINSEL1=0x00000000; //////declaring the ports to be used as GPIO which means as

    //////general purpose input output

    PINSEL0=0x00000000;

    IODIR0=0xFFFFFFFF; ////// The bits corresponding to 1 will be output and 0 will be

    //////input. Here all are output

    IODIR1=0x00FF0000; //////The bits of from 16 to 23 will be output rest as input.

    init_lcd(); //////Initializing the lcd

    lcd_clear(); ////// clearing the lcd

    while (1) /* Loop forever */

    {

    for(z=0;z

  • 7/27/2019 Arm Mannual

    29/30

    delay_sec(10);

    }

    4.3 Using ADC#include

    #include including headers

    #include "lcd.h"

    #include "adc.h"

    void wait(int count) another way to introduce a delay

    {

    int j=0,i=0;

    for(j=0;j

  • 7/27/2019 Arm Mannual

    30/30

    wait(100000);

    lcd_clear(); clear display

    while(1)

    {

    process_adc(); Read ADC value and display it on first

    line of LCD

    wait(30000);

    }

    }