Vous êtes sur la page 1sur 30

2012

ARM
ARM MANNUAL
VIKALP

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

Contents
1 ARM TUTORIAL ..................................................................................................................................... 2 1.1 2 Steps to use KEIL U-Vision .......................................................................................................... 2

Setting up the KEIL .............................................................................................................................. 12 2.1 You can add groups by using manage components or directly as well ...................................... 14

3 4

Snapshots for using manage components tool................................................................................... 18 Sample codes ................................................................................................................................... 26 4.1 4.2 4.3 LED blinking on any port ............................................................................................................. 26 using lcd ...................................................................................................................................... 26 Using ADC .................................................................................................................................... 28

1 ARM TUTORIAL
SETTINGS OF KEIL with snapshots STEPS FOR USING KEIL TO PROGRAM with snapshots SAMPLE CODES

1) After loading USB boot-loader firmware (already done in our board) to the BlueBoard-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 device and 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 sample codes and their corresponding binary files are stored in 2 different folders. Copy the binary 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 the pre-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

Here \Obj\serial.axf and \Obj\serial.bin are just your filenames. They can be interpreted as filename.axf and filename.bin

2 Setting up the KEIL


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

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

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

3 Snapshots for using manage components tool

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

Startup.s added

Write your code and save it as main.c

Now add your main.c to your group source

Select your main.c and add it

Adding lcd.h to group source for using lcd

Adding lcd.c to group source

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

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

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 16th to 31st bit of register 1. 3) PINSEL0 and PINSEL1 registers are used to define weather the pin is to be used as GPIO or any other 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.

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

4 Sample codes
4.1 LED blinking on any port
include <LPC214x.h> void delay_sec(unsigned int x) { T0MR0 = x; //Including the header //creating a function for delay using timer

// 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 // PS pins 16 to 19 still have 3.3 volts output delay_sec(100); } }

4.2 using lcd


#include <LPC21xx.H> #include "lcd.h" unsigned int z=0; char y = 'a'; //////**** Including the header******///////////// //////header for lcd //////variable declaretion

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; PINSEL0=0x00000000; IODIR0=0xFFFFFFFF; IODIR1=0x00FF0000; init_lcd(); lcd_clear();

//////declaring the ports to be used as GPIO which means as //////general purpose input output ////// The bits corresponding to 1 will be output and 0 will be //////input. Here all are output ////// The bits of from 16 to 23 will be output rest as input. //////Initializing the lcd ////// clearing the lcd

while (1) { for(z=0;z<14;z++) { lcd_clear(); lcd_gotoxy(1,z); lcd_putchar(y); delay_sec(1000); } lcd_putstring(0,"HI");

/* Loop forever */

//////displaying at row 1 and column z position //////displaying the data stored in character variable y

////// displaying the string in on 0th (zeroth) row

delay_sec(10); }

4.3 Using ADC


#include <stdio.h> #include <LPC214x.H> #include "lcd.h" #include "adc.h"

including headers

void wait(int count) { int j=0,i=0; for(j=0;j<count;j++) { for(i=0;i<35;i++); } } void process_adc(void) {

another way to introduce a delay

it will read the analog value at channel 3 of adc 0 and store in the string buf and display it on line 1 of lcd

unsigned short adc_value = 0; unsigned char buf[16] = {0}; adc_value = adc_read(ADC0, CHANNEL_3); sprintf((char *)buf, "ADC:%d ", adc_value); lcd_putstring(LINE1, (char *)buf); } int main (void) { init_adc0(); init_lcd();

initialize ADC Initialize LCD

wait(100000); lcd_clear(); while(1) { process_adc(); wait(30000); } }

clear display

Read ADC value and display it on first line of LCD

Vous aimerez peut-être aussi