Programs

Published on July 2016 | Categories: Documents | Downloads: 53 | Comments: 0 | Views: 455
of 34
Download PDF   Embed   Report

Comments

Content

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); }

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

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

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

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

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

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

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

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

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

} x++; Segment_Disp(single); if (single > 9) { single = 0;

}

}

}

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

KEYPAD Utility File.C

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

{ *C = 1; } else if (N == 0x0B) { *C = 2; } else if (N == 0x07) { *C = 3; } else *C = 4; DelayMs(); *KeysPort = DelayMs(); }

0xF0 << D0;

SWAMY ABEDHANANDHA POLYTECHNIC COLLEGE, THELLAR – 604 406 ELECTRONICS AND COMMUNICATION DEPARTMENT VI SEMESTER / EMBEDDED SYSTEMS LAB PROGRAM 8: MULTIPLE DATA DISPLAY ON A 7 SEGMENT

#include <stdio.h> #include <LPC214x.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,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90}; unsigned int thou,hun,ten,single; unsigned int x; unsigned char D0; void DelayMs(unsigned int count) { unsigned int i,j; for(i=0;i<count;i++) { for(j=0;j<3000;j++); } } void Segment_Disp(int thou,int hun,int ten,int single) { if(n==1) { IOPIN1 = SEG1; IOPIN1 &= (~(0xFF << D0)); IOPIN1 |= a[single] << D0; n=2; DelayMs(5); } else if(n==2) { IOPIN1 = SEG2; IOPIN1 &= (~(0xFF << D0)); IOPIN1 |= a[ten] << D0; n=3; DelayMs(5); }

else if(n==3) { IOPIN1 = SEG3; IOPIN1 &= (~(0xFF << D0)); IOPIN1 |= a[hun] << D0; n=4; DelayMs(5); } else if (n==4)

{ IOPIN1 = SEG4; IOPIN1 &= (~(0xFF << D0)); IOPIN1 |= a[thou] << D0; n=1; DelayMs(5); } } void main(void) { PINSEL2 &= 0x0000000C; D0 = 24; IODIR1 |= 0xFFFF << 16; while(1) { thou = 0; hun = 1; ten = 2; single = 3; Segment_Disp(thou, hun, ten, single); } }

SWAMY ABEDHANANDHA POLYTECHNIC COLLEGE, 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.h> #include <stdio.h> void lcd_initialize(void); void delay(unsigned int);

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

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

for (i=0;i<50;i++) for (j=0;j<500;j++); } void Serial_Init () { PINSEL0 |= 0x00050000; U1LCR = 0x83; U1DLL = 195; U1LCR = 0x03; } void main () { unsigned long Val; VPBDIV = 0x02; Serial_Init (); PINSEL1 = 0x01 << 24; AD0CR = PRESET | 0x02; AD0CR |= START; while (1) { do { Val = AD0GDR; } while ((Val & DONE) == 0); Val = ((AD0GDR >> 6) & 0x3FF); printf (">> Current Temperature : %4d ", Val); printf ("°F \r"); } }

SWAMY ABEDHANANDHA POLYTECHNIC COLLEGE, THELLAR – 604 406 ELECTRONICS AND COMMUNICATION DEPARTMENT VI SEMESTER / EMBEDDED SYSTEMS LAB PROGRAM 11: I2C INTERFACE- 7 SEGMENT #include <LPC214x.h> #include <stdio.h> #define MAX6 #define AA 2 #define SI 3 #define STO 4 #define STA 5 #define I2EN 6 void I2C_ISR(void)__irq; void Wait (unsigned int);

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

I2C_Start (); for (i=0;i<30;i++) Wait(10000); I2C0CONCL = 1 << SI; while(1) { for (i=0;i<20;i++) Wait(10000); } } void I2C_ISR(void) __irq { if (I2C0CONSET & 0x08) { switch (I2C0STAT) { case (0x08) case (0x10) case (0x18)

:

I2C0CONCLR= I2C0DAT break; : I2C0CONCLR= I2C0DAT = break; : I2C0CONCLR I2C0DAT index++; break; : I2C0CONCLR I2C0DAT index++; break;

1 << STA; = 0x70; 1 << STA; 0x70; = = 0x20; Buff[index];

case (0x20)

= =

0x20; Buff[index];

case (0x28)

: I2C0CONCLR = 0x20; if (index < MAX) { I2C0DAT = Buff[index]; index++; } else { index = 0; I2C0CONSET = 0x10; } break;

case (0x30)

: I2C0CONCLR if (index < MAX) = 0x20;

{ I2C0DAT index++; } else { Index = 0; I2C0CONSET = 0x10; I2C_Start(); } break; case (0x38) } } I2C0CONCLR= VICVectAddr } : I2C0CONSET = break; 1 << SI; = 0x00; 0x20; = Buff[index];

SWAMY ABEDHANANDHA POLYTECHNIC COLLEGE, THELLAR – 604 406 ELECTRONICS AND COMMUNICATION DEPARTMENT VI SEMESTER / EMBEDDED SYSTEMS LAB PROGRAM 12: I2C INTERFACE - EEPROM #include <LPC214x.h> #include <stdio.h> #include <string.h> #include "UART.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

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

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

Wait (1000); Ready = 'F'; } while (!(IOPIN1 & SW4)); Wait (5000);Wait (5000);Wait (5000);Wait (5000); } if ((IOPIN1 & SW5) == 0) { ii = 2; while (ii < MAX) { Buff[ii]= ii++; } flag = 'W'; Erase = 1; I2C_Start (0x70); for (i=0;i<30;i++) I2C0CONCLR=

0xFF;

Wait(10000); 1 << SI;

while (!(IOPIN1 & SW5)); Wait (5000);Wait (5000);Wait (5000);Wait (5000); } } } 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); = 0xA0;

1 << STO; 1 << STA; 0xA0; 1 << SI;

I2C0CONCLR= } index = break; case (0x10) : I2C0CONCLR = if (flag == 'W') I2C0DAT = else if (flag == 'R') { I2C0CONCLR I2C0CONCLR I2C0DAT I2C0CONCLR index = 0; } break; case (0x18) : 0;

1 << SI;

1 << STA; 0xA0; = = = = 1 << STA; 1 << STO; 0xA1; 1 << SI;

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

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

=

Buff[index];

= =

0x10; 1 << SI;

case (0x40)

: I2C0CONSET I2C0CONCLR= I2C0CONCLR= I2C0CONCLR= break; = 1 << AA; 1 << STA; 1 << STO; 1 << SI;

case (0x48)

: I2C0CONSET break; = 1 << STA;

case (0x50)

: I2C0CONSET if (index < MAX) { Rec [index] index++; } else { I2C0CONSET I2C0CONCLR index = 0; Ready } break; = = 1 << AA; I2C0DAT;

= = =

1 << STO; 1 << SI; 'T';

case (0x58)

: Rec [index] I2C0CONCLR= I2C0CONCLR= break; = I2C0DAT; 1 << STA; 1 << STO;

} } I2C0CONCLR= VICVectAddr } UTILITY.C #include <LPC213x.h> #include "UART.h" #define _PCLK 30000000 void DelayMS(void) { unsigned int i,j; for(i=0;i<20;i++) for(j=0;j<300;j++);

1 << SI; = 0x00;

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

SWAMY ABEDHANANDHA POLYTECHNIC COLLEGE, 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.H> void init_serial (void); int putchar (int ch); int getchar (void); unsigned char test; int main(void) { char *Ptr = "*** UART0 Demo ***\n\n\rType Characters to be echoed!!\n\n\r"; VPBDIV = 0x02; init_serial(); while(1) { while (*Ptr) { putchar(*Ptr++); } putchar(getchar()); } } void init_serial (void) { PINSEL0 = 0x00000005; U0LCR = 0x00000083; U0DLL = 0x000000C3; U0LCR = 0x00000003; }

int putchar (int ch) { if (ch == '\n') { while (!(U0LSR & 0x20)); U0THR = CR; } while (!(U0LSR & 0x20)); return (U0THR = ch); } int getchar (void) { while (!(U0LSR & 0x01)); return (U0RBR); } SWAMY ABEDHANANDHA POLYTECHNIC COLLEGE, THELLAR – 604 406 ELECTRONICS AND COMMUNICATION DEPARTMENT VI SEMESTER / EMBEDDED SYSTEMS LAB
PROGRAM 14: GENERATION OF PWM SIGNALS

#include <LPC214x.H> #include <stdio.h> void PWM0_isr(void) __irq { PWMIR |= 0x00000001; VICVectAddr = 0x00000000; } void init_PWM (void) { VICVectAddr8 = (unsigned)PWM0_isr; VICVectCntl8 = 0x00000028; VICIntEnable = 0x00000100; VPBDIV = 0x02; PINSEL0 |= 0x00008008; PWMPR = 0x00000000; PWMPCR = 0x00000C0C; PWMMCR = 0x00000003; PWMMR0 = 0x400; PWMMR1 = 0; PWMMR2 = 0x200; PWMMR3 = 0x100; PWMLER = 0xF; PWMTCR = 0x00000002; PWMTCR = 0x00000009; } void Delay () {

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

Sponsor Documents

Or use your account on DocShare.tips

Hide

Forgot your password?

Or register your new account on DocShare.tips

Hide

Lost your password? Please enter your email address. You will receive a link to create a new password.

Back to log-in

Close