ARM
ARM MANNUAL
VIKALP
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.
Here \Obj\serial.axf and \Obj\serial.bin are just your filenames. They can be interpreted as filename.axf and filename.bin
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 -
Startup.s added
Copy the c compiler header file lcd.h to the folder in which you are saving your code.
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); } }
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 }
//////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
/* Loop forever */
//////displaying at row 1 and column z position //////displaying the data stored in character variable y
delay_sec(10); }
including headers
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();
clear display