SWAMY ABEDHANANDHA POLYTECHNIC COLLEGE, THELLAR – 604 406 ELECTRONICS AND COMMUNICATION DEPARTMENT VI SEMESTER / EMBEDDED SYSTEMS LAB

PROGRAM 1: Assembly language #include <stdio.h> extern void init_serial (void); #pragma save #pragma arm int ArmAdd (int s1, int s2) { __asm { LDAV R7,R4,s1 LDAV R6,R4,s2 ADD R7,R7,R6 STAV R7,R6,s1 } return (s1); } int ArmSub (int s1, int s2) { __asm { LDAV R7,R4,s1 LDAV R6,R4,s2 SUB R7,R7,R6 STAV R7,R6,s1 } return (s1); } int ArmMul (int s1, int s2) { __asm { LDAV R7,R4,s1 LDAV R6,R4,s2 MUL R7,R6 STAV R7,R6,s1 } return (s1); } int ArmDiv (int s1, int s2) { int lVar;

__asm { LDAV

R7,R4,s1 LDAV R6,R4,s2 MOV R0,#0 DIF: SUBS R7,R7,R6 ADD R0,R0,#1 BHI DIF STAV R0,R6,lVar } return (lVar); } #pragma restore int main (void) { int sum, Diff, Product, Quotient; init_serial(); printf ("Inline-Assembly Example\n"); sum = ArmAdd (10, 20); Diff = ArmSub (25, 13); Product = ArmMul (5, 17); Quotient = ArmDiv (128, 4); printf (" --> ArmAdd (10,20): Sum = %d\n", sum); printf (" --> ArmSub (25,13): Difference = %d\n", Diff); printf (" --> ArmMul (5,17) : Product = %d\n", Product); printf (" --> ArmDiv (128,4): Quotient = %d\n", Quotient); printf ("_._._._._._._._._._._._._._._._._._._._._._._._._._\n"); while (1); return (0); }

SERIAL.C: #pragma INTERWORK #include <LPC21xx.H> #define CR 0x0D void init_serial (void) { PINSEL0 = 0x00050000; U1LCR = 0x83; U1DLL = 97; U1LCR = 0x03; } int putchar (int ch) { if (ch == '\n') { while (!(U1LSR & 0x20)); U1THR = CR; } while (!(U1LSR & 0x20)); return (U1THR = ch); } int getchar (void) { while (!(U1LSR & 0x01)); return (U1RBR); }

int main(void) { unsigned char Status=1.p<n. IO1DIR |= 0xFF << LED. IOSET1 = 0xFF << LED. } } . THELLAR – 604 406 ELECTRONICS AND COMMUNICATION DEPARTMENT VI SEMESTER / EMBEDDED SYSTEMS LAB PROGRAM 2: LED AND SWITCH INTERFACE #include <LPC214x.SWAMY ABEDHANANDHA POLYTECHNIC COLLEGE. Delay (10). IO1DIR = 0x00 << Switch. while(1) { Status = 1. while (~Status) { Status = ((IO1PIN & (0xFF << Switch)) >> Switch). IO1PIN = ((~Status) << LED).h> #include <stdio. Delay (10).p++) { for(q=0.q++). } } } void Delay(int n) { int p. Delay (10). Delay (10). for(p=0. Delay (10). Delay (10). IOCLR1 = 0xFF << LED.q.q<0x9990.h> #define LED 24 #define Switch 16 void Delay(int). PINSEL2 &= 0xFFFFFFF3.

h> #define BUZZ1 6 #define BUZZ2 7 void Delay(void). Delay(). j++). } } . IOSET0 = 2 << BUZZ1.i++) for (j=0. Delay(). } void main() { PINSEL0 = 0x00. THELLAR – 604 406 ELECTRONICS AND COMMUNICATION DEPARTMENT VI SEMESTER / EMBEDDED SYSTEMS LAB PROGRAM 3(A): BUZZER INTERFACE #include <LPC214x. IOCLR0 = 1 << BUZZ1.h> #include <stdio. while(1) { IOSET0 = 1 << BUZZ1. i<500. j<700. void Delay() { unsigned int i. Delay(). IODIR0 |= 1 << BUZZ2. j. for (i=0. IODIR0 = 1 << BUZZ1. IOCLR0 = 2 << BUZZ1.SWAMY ABEDHANANDHA POLYTECHNIC COLLEGE. Delay().

} } void main(void) { unsigned char Status = 0. IODIR1 = 0x00 << Switch. } } } .SWAMY ABEDHANANDHA POLYTECHNIC COLLEGE.p<n. PINSEL2 &= 0xFFFFFFF3. Delay(10). IOSET0 = 0x01. Delay (10).p++) { for(q=0. IOCLR0 = 0x01.q<0x9990. IO0PIN = ((~Status) << RLY1). Delay(10). Delay(10). IOSET0 = 0x02.Delay(10).q. for(p=0. THELLAR – 604 406 ELECTRONICS AND COMMUNICATION DEPARTMENT VI SEMESTER / EMBEDDED SYSTEMS LAB PROGRAM 3(B): RELAY INTERFACE #include <lpc21xx. Delay(10). Status = 1.Delay(10) IOCLR0 = 0x02. PINSEL0 = 0. Delay (10). while (~Status) { Status = ((IO1PIN & (0xFF << Switch)) >> Switch).q++).h> #include <stdio.h> #define RLY1 0 #define Switch 24 void Delay(int n) { int p. IODIR0 = 0x3F << RLY1. while(1) { Status = 1.

0x02. void delay(int). 0x06. delay(1).i++) { IOSET0 = STEP[i] << COIL_A.i++) { for(j=0. IOCLR0 = STEP[i] << COIL_A. for(i=0. unsigned char STEP[] = {0x09. void delay(int n) { int i.i--) { IOSET0 = STEP[i] << COIL_A. for (i=0. void motor_ccw(void).i<n. IOCLR0 = STEP[i] << COIL_A. for (i=7.h> #include <stdio. delay(1). } } . 0x03. delay(1).i>=0.j.j<0x3FF0.h> #define SW1 24 #define SW2 25 #define SW3 26 #define COIL_A 0 void motor_cw(void). } } void motor_ccw(void) { int i.} } } void motor_cw(void) { unsigned int i=0.SWAMY ABEDHANANDHA POLYTECHNIC COLLEGE. 0x01}.j++) {. 0x04. 0x08.STEP[i] != '\0'. THELLAR – 604 406 ELECTRONICS AND COMMUNICATION DEPARTMENT VI SEMESTER / EMBEDDED SYSTEMS LAB PROGRAM 3(C): STEPPER MOTOR INTERFACE #include <lpc21xx. delay(1). 0x0C.

while(1) { if (!(IOPIN1 & (1<<SW1))) motor_cw(). PINSEL0 = 0. else if (!(IOPIN1 & (1<<SW3))) { while (i < 9) { motor_cw (). PINSEL2 &= 0xFFFFFFF3. else if (!(IOPIN1 & (1<<SW2))) motor_ccw().void main(void) { unsigned char i = 0. IODIR0 &= ~(7<<SW1). i++. } } . } } else i = 0. IODIR0 = 0x0000FF.

VICIntEnable |= 0x00000010. T0TCR = 1. .SWAMY ABEDHANANDHA POLYTECHNIC COLLEGE. T0MCR = 3. while (1). VICVectAddr4 = (unsigned)T0isr. T0MR0 = 14999999. = 0x00000000. } void T0isr (void) { IOPIN T0IR VICVectAddr } __irq =~(IOPIN0 & 0x00FF0000). |= 0x00000001. IODIR0 = 0xFF << 16. int main(void) { VPBDIV = 0x00000002. VICVectCntl4 = 0x00000024. THELLAR – 604 406 ELECTRONICS AND COMMUNICATION DEPARTMENT VI SEMESTER / EMBEDDED SYSTEMS LAB PROGRAM 4: TIMER #include <LPC214x.H> void T0isr(void) __irq. PINSEL1 |= 0x01.

THELLAR – 604 406 ELECTRONICS AND COMMUNICATION DEPARTMENT VI SEMESTER / EMBEDDED SYSTEMS LAB PROGRAM 5: EXTERNAL INTERRUPT #include <lpc214x.j++). EXTPOLAR = 0.j<1000. PINSEL0 |= 0x20000000.i<count. VICVectAddr0 = (unsigned long) ExtInt_Serve1. U0DLL = 0x00000061. VICIntEnable |= 1<<15. VICIntEnable |= 1<<16. } } .h> #include <stdio. U0LCR = 0x00000083.i++) { for(j=0. int volatile EINT2 = 0. for(i=0.j. } void ExtInt_Init1(void) { EXTMODE |= 2. U0LCR = 0x00000003. } void DelayMs(unsigned int count) { unsigned int i. VICVectCntl1 = 0x20 | 16. EXTPOLAR = 0. void ExtInt_Serve2(void)__irq.h> int volatile EINT1 = 0. PINSEL0 |= 0x80000000. VICVectCntl0 = 0x20 | 15. void ExtInt_Init2(void) { EXTMODE |= 4. void ExtInt_Serve1(void)__irq. } void Serial_Init(void) { PINSEL0 |= 0X00000005.SWAMY ABEDHANANDHA POLYTECHNIC COLLEGE. VICVectAddr1 = (unsigned long) ExtInt_Serve2.

ExtInt_Init1(). } } void ExtInt_Serve1(void)__irq { ++EINT1. } . DelayMs(500).C #include <LPC21xx. } SERIAL. while(1) { DelayMs(500). EINT1. printf (">>> Press Interrupt Keys SW2(INT1) and SW3(INT2) for Output. } void ExtInt_Serve2(void)__irq { ++EINT2. } int getchar (void) { while (!(U0LSR & 0x01)). } while (!(U0LSR & 0x20)). DelayMs(100).. EXTINT |= 2. EINT2). \n\n\n\r"). U0THR = CR. putchar(0x0C).void main(void) { Serial_Init().H> #define CR 0x0D int putchar (int ch) { if (ch == '\n') { while (!(U0LSR & 0x20)). DelayMs(100). return (U0THR = ch). ExtInt_Init2(). printf ("***************** External Interrupt Demo ***********************\n\n\r"). return (U0RBR).. VICVectAddr = 1. VICVectAddr = 0. EXTINT |= 4. printf("INT1 Generated : %d | INT2 Generated : %d \r".

unsigned int thou. IOPIN1 &= (~(0xFF << 24)).h> #include <LPC214x. for(i=0.0x99.ten.0xb0.0x92.0x90}. IODIR1 |= 0xFFFF << 16 while(1) { n = 1. } } void main(void) { PINSEL2 &= 0x0000000C.i<count.hun. } } void Segment_Disp(int single) { if(n==1) { IOPIN1 = SEG1.0xf9. if (single > 9) { single = 0.j<3000.i++) { for(j=0.0x80. n=1.0xf8.0x82.H> #define SEG1 1<<16 #define SEG2 1<<17 #define SEG3 1<<18 #define SEG4 1<<19 unsigned int n=1. unsigned char a[10]={0xc0. } } } . unsigned int x. Segment_Disp(single). if(x == 300) { x=0. } x++.j++). void DelayMs(unsigned int count) { unsigned int i.single. DelayMs(15).0xa4. THELLAR – 604 406 ELECTRONICS AND COMMUNICATION DEPARTMENT VI SEMESTER / EMBEDDED SYSTEMS LAB PROGRAM 6: SINGLE DATA DISPLAY ON A 7 SEGMENT #include <stdio.j. IOPIN1 |= a[single] << 24.SWAMY ABEDHANANDHA POLYTECHNIC COLLEGE. single++.

for(i=0.i<35.'2'.'6'. while (1) { Delay().'E'.j. if (Row_Data < 4 && Col_Data < 4) { U0THR = Msg[Row_Data][Col_Data]. Delay().'3'. &Row_Data.SWAMY ABEDHANANDHA POLYTECHNIC COLLEGE.'B'.'5'. unsigned char Msg[4][4] = { '0'. '4'.16. PINSEL2 |= 0x0.i++) for(j=0. void Delay(void) { unsigned int i. U0LCR = 0x03.'F' }. U0DLL = 0x61. '8'. Col_Data.h> #include <stdio. Delay(). } void main(void) { U0LCR = 0x83.h" extern void Delay(void).'9'. U0THR = '\n'.'1'. Delay().C . 'C'.h> #include "Keypad. KeyScan(&IOPIN1.&Col_Data). unsigned char Row_Data. PINSEL0 |= 0x05. } } } KEYPAD Utility File.j<1234.'D'.j++).'A'.'7'. U0THR = 'A'. THELLAR – 604 406 ELECTRONICS AND COMMUNICATION DEPARTMENT VI SEMESTER / EMBEDDED SYSTEMS LAB PROGRAM 7: 4X4 MATRIX KEYPAD #include <LPC214x.

if (N == 0x0E) { *C = 0. if (M == 0xE0) { *R = 0. } else if (N == 0x0D) .j<2000. *(KeysPort+2) = (0xF0 << D0).j++). for(i=0. } else if (M == 0xD0) { *R = 1. unsigned char M. unsigned char *R. unsigned char *C) { Delay(). *(KeysPort) = (0xF0 << D0).N.i++) for(j=0. Delay(). void DelayMs() { unsigned int i. *KeysPort = 0x0F << D0.#include <LPC214x. M = (*KeysPort) >> D0. } else if (M == 0x70) { *R = 3. while ((((*KeysPort)>>D0)&0x00F0) == 0xF0). *(KeysPort) = (0x0F << D0). } else *R = 4. } else if (M == 0xB0) { *R = 2.j. while ((((*KeysPort)>>D0)&0x000F) == 0x0F). unsigned char D0.h> extern void Delay().i<300. } void KeyScan (unsigned long *KeysPort. *(KeysPort+2) = (0x0F << D0). Delay(). N = ((*KeysPort) >> D0).

} 0xF0 << D0. THELLAR – 604 406 ELECTRONICS AND COMMUNICATION DEPARTMENT VI SEMESTER / EMBEDDED SYSTEMS LAB PROGRAM 8: MULTIPLE DATA DISPLAY ON A 7 SEGMENT . SWAMY ABEDHANANDHA POLYTECHNIC COLLEGE. } else if (N == 0x07) { *C = 3.{ *C = 1. *KeysPort = DelayMs(). } else *C = 4. } else if (N == 0x0B) { *C = 2. DelayMs().

DelayMs(5).H> #define SEG1 1<<16 #define SEG2 1<<17 #define SEG3 1<<18 #define SEG4 1<<19 unsigned int n=1. IOPIN1 &= (~(0xFF << D0)). } else if (n==4) .hun.int single) { if(n==1) { IOPIN1 = SEG1. n=2. IOPIN1 &= (~(0xFF << D0)).j. } else if(n==3) { IOPIN1 = SEG3. for(i=0.ten.0x82. n=4.j<3000.0xf8. unsigned int x.i++) { for(j=0.0x99.int hun. IOPIN1 |= a[hun] << D0.h> #include <LPC214x.0xa4. void DelayMs(unsigned int count) { unsigned int i. IOPIN1 |= a[ten] << D0. unsigned char a[10]={0xc0.#include <stdio. unsigned int thou.j++). DelayMs(5). unsigned char D0. n=3.0x92.single.0xf9.i<count.0x80. DelayMs(5).0xb0.0x90}. IOPIN1 |= a[single] << D0. } } void Segment_Disp(int thou. IOPIN1 &= (~(0xFF << D0)).int ten. } else if(n==2) { IOPIN1 = SEG2.

} } SWAMY ABEDHANANDHA POLYTECHNIC COLLEGE. while(1) { thou = 0. IOPIN1 &= (~(0xFF << D0)). single = 3. IOPIN1 |= a[thou] << D0. ten = 2. IODIR1 |= 0xFFFF << 16. THELLAR – 604 406 ELECTRONICS AND COMMUNICATION DEPARTMENT VI SEMESTER / EMBEDDED SYSTEMS LAB PROGRAM 9: DISPLAYING A MESSAGE ON A 2LINE X 16 CHARACTERS LCD DISPLAY #include <lpc214x. } } void main(void) { PINSEL2 &= 0x0000000C. void delay(unsigned int).{ IOPIN1 = SEG4. n=1. . hun = 1. DelayMs(5). single).h> void lcd_initialize(void).h> #include <stdio. Segment_Disp(thou. hun. ten. D0 = 24.

extern void LCD_Write_Animate (void). IOCLR1 = 0xFF000000. const unsigned char msg[] = ("PS-ARM TYRO KITS"). IOCLR1 |= 0x10000. void lcd_initialize(void) { int i. lcd_cmd(cmd[i]). i++. } void lcd_display(void) { char i. lcd_cmd(0x80). const unsigned char msg1[] = (" ::LCD DEMO:: "). .0x06. IOCLR1 |= 0x20000. i=0. while(msg[i]!='\0') { IOCLR1 = 0xFF000000. delay(15). delay(15). } } void lcd_cmd(unsigned char data) { IOPIN1 = data << 24.0x01}. IOCLR1 |= 0x40000.0x0c. delay(15). IOSET1 |= 0x10000. for(i=0. lcd_data(msg[i]).i<4. delay(15).i++) { IOCLR0 = 0xFF000000. IOCLR1 |= 0x40000. IOSET1 |= 0x40000. IOSET1 |= 0x40000. lcd_cmd(0xc0). const unsigned char cmd[4] = {0x38. delay(15). } void lcd_data(unsigned char data) { IOPIN1 = data << 24. } delay(15). delay(15).void lcd_cmd(unsigned char). void lcd_data(unsigned char). IOCLR1 |= 0x20000.

for(i=0.h> #define DONE0x80000000 #define START 0x01000000 #define PRESET 0x00230600 void Delay () { unsigned int i. lcd_data(msg1[i]). while(msg1[i]!='\0') { IOCLR1 = 0xFF000000. lcd_display(). while(1) { delay(15). lcd_initialize(). } delay(15). i++. delay(15).j++).j.j. } void delay(unsigned int n) { int i. THELLAR – 604 406 ELECTRONICS AND COMMUNICATION DEPARTMENT VI SEMESTER / EMBEDDED SYSTEMS LAB PROGRAM 10: TEMPERATURE SENSOR #include <LPC214x. IODIR1 = 0XFFFF0000. PINSEL2 &= 0X0000000C.j<0x2700. } } void main(void) { PINSEL0 = 0. } } SWAMY ABEDHANANDHA POLYTECHNIC COLLEGE. delay(15).i++) { for(j=0.i<n. PINSEL1 = 0.i=0.h> #include <stdio. . delay(10). while(1). delay(10).

for (i=0. } } SWAMY ABEDHANANDHA POLYTECHNIC COLLEGE.7 SEGMENT #include <LPC214x.i<50. AD0CR = PRESET | 0x02. VPBDIV = 0x02.h> #include <stdio. printf ("°F \r"). PINSEL1 = 0x01 << 24. U1LCR = 0x03.j<500. } while ((Val & DONE) == 0). Serial_Init (). U1DLL = 195. Val = ((AD0GDR >> 6) & 0x3FF). THELLAR – 604 406 ELECTRONICS AND COMMUNICATION DEPARTMENT VI SEMESTER / EMBEDDED SYSTEMS LAB PROGRAM 11: I2C INTERFACE.h> #define MAX6 #define AA 2 #define SI 3 #define STO 4 #define STA 5 #define I2EN 6 void I2C_ISR(void)__irq. while (1) { do { Val = AD0GDR. . printf (">> Current Temperature : %4d ". Val). void Wait (unsigned int). } void main () { unsigned long Val. } void Serial_Init () { PINSEL0 |= 0x00050000. U1LCR = 0x83.i++) for (j=0.j++). AD0CR |= START.

void I2C_Init (void). VPBDIV = 0x02. } void Wait (unsigned int Delay) { while(Delay--). for(i=0. unsigned char index = 0. } void I2C_Init (void) { I2C0SCLH = 150. } int I2C_Write (unsigned char *Buff. unsigned int Count) { while(Count--) { I2C0DAT = *Buff++. int I2C_Write (unsigned char *Buff. VICIntEnable = 1<<9. I2C0SCLL = 150. unsigned char Buff[] = {0x00. U0DLM = 0x00.0x27. U0DLL = 97. I2C_Init().j++).i++) for(j=0. VICVectCntl0 = 0x020 | 9 . int I2C_Start (void). } return 0. U0LCR = 0x03. U0LCR = 0x83.i<20. I2C0CONCLR = 1 << AA. return 0. PINSEL0 = 0x00000055.0x4F/*4*/}.j<200.0x3F/*0*/. I2C0CONSET = 1 << I2EN. .j. VICVectAddr0= (unsigned long)I2C_ISR. unsigned int Count). } int I2C_Start (void) { I2C0CONCLR = 1 << STO.0x06/*1*/. void Delay(void) { unsigned int i. } void main() { unsigned int i. VICIntSelect = 0<<9.0x5B/*3*/. I2C0CONSE = 1 << STA.

case (0x28) : I2C0CONCLR = 0x20. . Buff[index]. } break. = = 0x20. 1 << STA. if (index < MAX) { I2C0DAT = Buff[index]. 1 << STA.I2C_Start (). case (0x30) : I2C0CONCLR if (index < MAX) = 0x20. } else { index = 0.i++) Wait(10000).i<30.i++) Wait(10000). Buff[index].i<20. : I2C0CONCLR I2C0DAT index++. case (0x20) = = 0x20. break. I2C0CONSET = 0x10. break. 0x70. : I2C0CONCLR I2C0DAT index++. : I2C0CONCLR= I2C0DAT = break. = 0x70. index++. } } void I2C_ISR(void) __irq { if (I2C0CONSET & 0x08) { switch (I2C0STAT) { case (0x08) case (0x10) case (0x18) : I2C0CONCLR= I2C0DAT break. while(1) { for (i=0. I2C0CONCL = 1 << SI. for (i=0.

EEPROM #include <LPC214x. = 0x00. I2C0CONSET = 0x10.{ I2C0DAT index++. 0x20. 1 << SI. THELLAR – 604 406 ELECTRONICS AND COMMUNICATION DEPARTMENT VI SEMESTER / EMBEDDED SYSTEMS LAB PROGRAM 12: I2C INTERFACE . I2C_Start().h> #include <stdio.h> #include <string. } break.h> #include "UART. } else { Index = 0. case (0x38) } } I2C0CONCLR= VICVectAddr } : I2C0CONSET = break. SWAMY ABEDHANANDHA POLYTECHNIC COLLEGE.h" #define SW3 1<<24 #define SW4 1<<25 #define SW5 1<<26 #define SW6 1<<27 #define SW7 1<<28 #define MAX 10 #define AA 2 #define SI 3 #define STO 4 #define STA 5 #define I2EN 6 . = Buff[index].

} int main() { unsigned int i.'T'.0x00.i++) for(j=0. char Buff[MAX] = {0x00. for(i=0.'7'.0x00.'7'.j++).'Y'. PINSEL2 = 0xFFFFFFF3.'O'}.'M'. Ready=0.'R'.'Y'.j<900. unsigned int Count).'O'}. I2C0SCLH = 150. void Wait (unsigned int). void I2C_Init (void). } int I2C_Start (unsigned int Slave_Addr) { I2C0CONCLR = 1 << STO. unsigned char Rec[MAX] = {"NO-DATA!"}.void I2C_ISR(void)__irq. int I2C_Write (unsigned char *Buff. } return 0.'A'. PINSEL0 = 0x00000055. I2C0CONSET = 1 << STA. I2C0CONSET = 1 << I2EN.'R'.j. VPBDIV = 0x02.i<150. unsigned char Erase = 0.'A'.'T'. unsigned int Count) { while(Count--) { I2C0DAT = *Buff++. } int I2C_Write (unsigned char *Buff. unsigned char index = 0. return 0. IO1DIR = 0x00 << SW3. . char ReLoad[MAX] = {0x00. int I2C_Start (unsigned int Slave_Addr).'R'. } void Wait (unsigned int Delay) { while(Delay--). ii. unsigned char flag = 0.'M'. void Delay(void) { unsigned int i. I2C0SCLL = 150. I2C0CONSET = 1 << AA.'R'. } void I2C_Init (void) { PINSEL0 = 0x00000055.

} UART0_PutC ('\n'). UART0_PutS ("********* ARM Tyro LPc2148 I2C EEPROM Demo **********\n\n\r"). I2C0CONCLR= 1 << SI. UART0_PutS (">>> Connect I2C Add-On Card to J11 on ARM Tyro Board . I2C_Init().i++) Wait(10000). . Erase = 0. for (i=0. while (Ready == 'F').UART0_Init (9600). flag = 'W'.i<30. I2C_Start (0x70). for (i=0. UART0_PutS ("\n\r The Read Data are: \t"). while (1) { if ((IOPIN1 & SW3) == 0) { ii = 0. VICVectAddr0 = (unsigned long)I2C_ISR. while (ii<MAX) { //U0THR = '\n'. UART0_PutS ("[~] Turn SW4 ON to Read and Display data from EEPROM! \n\r"). ii++. Wait (1000). I2C0CONCLR= 1 << SI. \n\n\r"). VICIntEnable = 1<<9. VICVectCntl0 = 0x020 | 9 .i++) Wait(10000). while (ii < MAX) { Buff [ii] = ReLoad [ii]. Wait (5000). ii++. if (Ready == 'T') { ii=0. } Wait (5000). Wait (1000). } else if ((IOPIN1 & SW4) == 0) { flag = 'R'. UART0_PutS ("[~] Turn SW3 ON to Write default data to EEPROM! \n\r"). VICIntSelect = 0<<9. U0THR = Rec[ii].Wait (5000). UART0_PutS ("[~] Turn SW5 ON to Erase data from EEPROM \n\r")..i<30. while (!(IOPIN1 & SW3)). I2C_Start (0x70).

Wait (5000). 0xA0. 1 << SI. } while (!(IOPIN1 & SW4)). . Wait (5000). while (!(IOPIN1 & SW5)). while (ii < MAX) { Buff[ii]= ii++.Wait (1000). I2C_Start (0x70).Wait (5000).Wait (5000). 1 << STA. 1 << STO. Wait(10000). } } } void I2C_ISR(void) __irq { if (I2C0CONSET & 0x08) { switch (I2C0STAT) { case (0x08) : if (flag == 'W') { I2C0CONCLR= I2C0CONCLR= I2C0DAT = I2C0CONCLR = } else if (flag == 'R') { I2C0DAT I2C_Start (0xA1).Wait (5000).i++) I2C0CONCLR= 0xFF. } flag = 'W'. 1 << SI. Erase = 1.i<30. Wait (5000).Wait (5000). } if ((IOPIN1 & SW5) == 0) { ii = 2.Wait (5000). = 0xA0. for (i=0. Ready = 'F'.

I2C0CONCLR = 0x38. I2C0CONCLR = 0x20. } else . index++. 1 << SI. break. index++. } else if ((index > 1) && flag == 'R') { I2C0CONCLR = 0x18. 1 << SI. = = = = 1 << STA. case (0x10) : I2C0CONCLR = if (flag == 'W') I2C0DAT = else if (flag == 'R') { I2C0CONCLR I2C0CONCLR I2C0DAT I2C0CONCLR index = 0. case (0x18) : 0. I2C0CONCLR= 0x20. I2C0CONCLR= 0x38. I2C0DAT = Buff[index]. 1 << STO. 0xA1. break. I2C0CONCLR = 0x38. I2C0DAT = Buff[index]. 0xA0. 1 << STA. } break.I2C0CONCLR= } index = break. case (0x28) : if (index < MAX) { if (flag == 'W') { I2C0DAT = Buff[index]. I2C0CONSET = 1 << STA. case (0x20) : I2C0CONCLR = 0x20.

.. 0x20. 0x20. 1 << SI. 0x38. I2C0CONCLR= 1 << SI. flag = 0. if (Erase == 1) { UART0_PutS ("\n\r Memory Erase Successfull. 0x20. = = = Buff[index].!\n"). } else { index = 0. } I2C0CONCLR= 1 << STA. = = 0x10. } break. = Buff[index]. I2C0CONSET I2C0CONCLR } break. } else { index = 0.. flag = 'R'. } else { UART0_PutS ("\n\r Data Successfully Written on Memory!\n"). case (0x38) : I2C0CONSET = break. case (0x30) : I2C0CONCLR= if (index < MAX) { if (flag == 'W') { I2C0DAT } index++. I2C0CONSET = 1 << STO...{ I2C0DAT I2C0CONCLR I2C0CONCLR } index++.

1 << SI. case (0x58) : Rec [index] I2C0CONCLR= I2C0CONCLR= break. 1 << SI. I2C0DAT.i<20.h> #include "UART. } else { I2C0CONSET I2C0CONCLR index = 0. 1 << STO. case (0x50) : I2C0CONSET if (index < MAX) { Rec [index] index++. Ready } break. case (0x48) : I2C0CONSET break. 1 << STA.h" #define _PCLK 30000000 void DelayMS(void) { unsigned int i.C #include <LPC213x. = = 1 << AA.case (0x40) : I2C0CONSET I2C0CONCLR= I2C0CONCLR= I2C0CONCLR= break. } } I2C0CONCLR= VICVectAddr } UTILITY. 1 << STA. = 1 << AA.j. = 0x00. . 'T'. = I2C0DAT. 1 << SI. for(i=0. = 1 << STA.j++). 1 << STO.j<300.i++) for(j=0. = = = 1 << STO.

U0LCR = 0x00000003. } } void UART0_Init(unsigned int _baudrate) { unsigned short u0dl. U0DLM = (u0dl>>8). } void UART0_PutC(char c) { while(!(U0LSR & 0x20)). U1DLL = u1dl & 0xFF. DelayMS(). U1LCR = 0x00000003. U0THR = c. DelayMS(). U0DLL = u0dl & 0xFF. } void UART1_PutS(char *p) { while(*p) { UART1_PutC(*p++). PINSEL0 |= 0x00050000. U1THR = c. U1LCR = 0x00000083. U0LCR = 0x00000083. } } . u0dl = _PCLK/(16*_baudrate). } void UART0_PutS(char *p) { while(*p) { UART0_PutC(*p++). PINSEL0 |= 0x00000005. U1DLM = (u1dl>>8). } void UART1_PutC(char c) { while(!(U1LSR & 0x20)).} void UART1_Init(unsigned int _baudrate) { unsigned short u1dl. u1dl = _PCLK/(16*_baudrate).

} } void init_serial (void) { PINSEL0 = 0x00000005. int putchar (int ch).H> void init_serial (void). } . } putchar(getchar()). U0LCR = 0x00000003. THELLAR – 604 406 ELECTRONICS AND COMMUNICATION DEPARTMENT VI SEMESTER / EMBEDDED SYSTEMS LAB PROGRAM 13: TRANSMISSION FROM KIT& RECEPTION FROM PC USING SERIAL PORT #define CR 0x0D #include <LPC21xx. VPBDIV = 0x02. U0DLL = 0x000000C3. init_serial(). unsigned char test.SWAMY ABEDHANANDHA POLYTECHNIC COLLEGE. U0LCR = 0x00000083. int main(void) { char *Ptr = "*** UART0 Demo ***\n\n\rType Characters to be echoed!!\n\n\r". while(1) { while (*Ptr) { putchar(*Ptr++). int getchar (void).

VICIntEnable = 0x00000100. PWMTCR = 0x00000009. PWMPCR = 0x00000C0C. PWMTCR = 0x00000002. PWMMR0 = 0x400.h> void PWM0_isr(void) __irq { PWMIR |= 0x00000001. } void Delay () { . PWMMR2 = 0x200. } while (!(U0LSR & 0x20)). PWMMR3 = 0x100. U0THR = CR. VPBDIV = 0x02. PWMPR = 0x00000000. } int getchar (void) { while (!(U0LSR & 0x01)). PWMMR1 = 0. THELLAR – 604 406 ELECTRONICS AND COMMUNICATION DEPARTMENT VI SEMESTER / EMBEDDED SYSTEMS LAB PROGRAM 14: GENERATION OF PWM SIGNALS #include <LPC214x. PWMLER = 0xF. VICVectAddr = 0x00000000. VICVectCntl8 = 0x00000028.int putchar (int ch) { if (ch == '\n') { while (!(U0LSR & 0x20)). return (U0THR = ch). PINSEL0 |= 0x00008008. } void init_PWM (void) { VICVectAddr8 = (unsigned)PWM0_isr.H> #include <stdio. PWMMCR = 0x00000003. } SWAMY ABEDHANANDHA POLYTECHNIC COLLEGE. return (U0RBR).

if (val != oldval) { PWMMR2 = val. while (1) { do { val = AD0GDR.j. PINSEL1 = 0x15400000. } } } . U1LCR = 0x83. unsigned long oldval = 0. VPBDIV = 0x02. Delay(). U1LCR = 0x03.unsigned int i.i++) for (j=0. AD0CR &= ~0x01000000. U1DLL = 0xC3. } while ((val & 0x80000000) == 0). AD0CR = 0x00230608. PWMLER = 0xF. } int main (void) { unsigned long val. for (i=0. val = ((val >> 6) & 0x3FF).j++). val). printf ("Val : %4d \n\r".j<700. Delay (). oldval = val. init_PWM().i<250. PINSEL0 |= 0x00050000. AD0CR |= 0x01000000.

Sign up to vote on this title
UsefulNot useful