Posts

10. interrupts

#include< LPC21xx.h>  void enable_interrupts(void) { __asm { MRS RO, CPSR // Move the current program status register to RO  BIC RO, RO, #0x80 // Clear the I bit in CPSR (enables IRQ)  MSR CPSR_C, RO // Move the modified value back to CPSR } } void disable_interrupts(void) { __asm { MRS RO, CPSR // Move the current program status register to RO  ORR RO, RO, #0x80 // Set the I bit in CPSR (disables IRQ)  MSR CPSR_c, RO // Move the modified value back to CPSR } } int main (void) { disable_interrupts(); // Disable interrupts enable_interrupts(); // Enable interrupts }

9. caseConversion

  PROGRAM: # include <lpc21xx.h> char src[ ] = "rns institute of technology"; char dest[ ] = ""; OR dest[50]; void caseConvert(){ unsigned int i; for (i = 0; src[i]!='\0'; i++){ if(src[i] >= 'a' && src[i] <= 'z') { dest[i] = src[i] - 32; } if(src[i] >= 'A' && src[i] <= 'Z') { dest[i] = src[i] + 32; } } } int main(){ caseConvert(); return 0; }

8. factorial

 EXPT 8(a) : // Factorial included in the main function #include <lpc21xx.h> int main(){ unsigned int num = 5, i; unsigned long fact = 1; for(i = 1; i<=num; i++) fact = fact * i; return 0; } EXPT 8.B – Factorial using a recursive function 8.b recursion   #include <lpc21xx.h> int main(){ int num = 7; int factorial; factorial = fact (num); return 0; }   //Recursice function to find the factorial of a number int fact (int y){ if (y == 0) return 1; return y*fact (y-1); }

7. bubble sort

#include <lpc21xx.h> void swap(unsigned int* arr, unsigned int i, unsigned int j) { unsigned int temp = arr[i]; arr[i] = arr[j]; arr[j] = temp; } // function to implement bubble sort void bubbleSort(unsigned int arr[], unsigned int n) { unsigned int i, j; for (i = 0; i < n - 1; i++) for (j = 0; j < n - i - 1; j++) if (arr[j] > arr[j + 1]) swap(arr, j, j + 1); }   int main() { unsigned int arr[] = { 5, 1, 4, 2, 8 }; unsigned int N = sizeof(arr) / sizeof(arr[0]); bubbleSort(arr, N); return 0; }