EMBEDDED C PROGRAMS USING KEIL

25
KEIL PROGRAMMING

description

EMBEDDED C PROGRAMMES USING KEIL TOOL FOR EMBEDDED LAB

Transcript of EMBEDDED C PROGRAMS USING KEIL

Page 1: EMBEDDED C PROGRAMS USING KEIL

KEIL PROGRAMMING

Page 2: EMBEDDED C PROGRAMS USING KEIL

PROGRAM:

Flash the output without delay

# include <REG52.h># include <intrins.h>void main (void){int i = 0;while (1){while (i<=25){_nop_ ( );i++;}if ( p1 = 0x00){p1 = 0xff;}else{p1 = 0x00;}}}

Page 3: EMBEDDED C PROGRAMS USING KEIL

Expt. No. : 02

Date :

FLASH THE OUTPUT WITH DELAYAIM:

To perform Flash The Output With Delay operation using 8051 simulation environment KEIL C.

COMPONENTS REQUIRED:

KEIL C simulation software..

ALGORITHM:

Step 1: Put the value to port 1 as 0xFF.

Step 2: Run a delay loop.

Step 3: Put the value to port 1 as 0xDD.

Page 4: EMBEDDED C PROGRAMS USING KEIL

PROGRAM:

Flash the output with delay

# include <REG52.h>void sfr p2 = 0x00;void main ( ){unsigned char x;p2 = 0xff;for (x = 0; x <= 150; x++)delay ( );while (1){p2 =~ p2;for (x = 0; x <= 20; x++)delay ( );}}

Delay subroutine

Void delay (void){TMOD = 0x100;TL1 = 0xFE;TH1 = 0xA5;While (TF1 == 0);TR1 = 0;TH1 = 0;}

Page 5: EMBEDDED C PROGRAMS USING KEIL
Page 6: EMBEDDED C PROGRAMS USING KEIL

OUTPUT:

Page 7: EMBEDDED C PROGRAMS USING KEIL

RESULT:

Thus the Flash Output With Delay operation using 8051 simulation environment KEIL C was performed and verified successfully.

Page 8: EMBEDDED C PROGRAMS USING KEIL

PROGRAM:

Rotate Right

#include<reg52.h>#include<intrins.h>#include<stdio.h>void main(void){ int i=0; int a,b; P1= 0xFF; while(1){ while(i<5){ _nop_(); i++;}a^=0xA5;P0=a;b^=_cror_(a,1);P1=b;}}

Page 9: EMBEDDED C PROGRAMS USING KEIL

Expt. No. : 03(a)

Date :

ROTATE RIGHT WITH DELAYAIM:

To perform Rotate Right With Delay operation using 8051 simulation environment KEIL C.

COMPONENTS REQUIRED:

KEIL C simulation software..

ALGORITHM:

Step 1: Start the program.

Step 2: Put the value of Port 0 as 100101(A5).

Step 3: Shift the bit towards right continously.

Step 4: Call Delay routine.

Step 5: get the value of port 1 as 11010010(D2).

Step 6: End the program.

Page 10: EMBEDDED C PROGRAMS USING KEIL

OUTPUT:

Page 11: EMBEDDED C PROGRAMS USING KEIL

RESULT:

Thus the Rotate Right With Delay operation using 8051 simulation environment KEIL C was performed and verified successfully.

Page 12: EMBEDDED C PROGRAMS USING KEIL

PROGRAM:

Rotate Left

#include<reg52.h>#include<intrins.h>#include<stdio.h>

void main(void){ int i=0; int a,b; P1= 0xff; while(1){ while(i<5){ _nop(); i++;}a^=0xA5;P0=a;b^=_cror_(a,3);P1=b;}}

Page 13: EMBEDDED C PROGRAMS USING KEIL

Expt. No. : 03(b)

Date :

ROTATE LEFT WITH DELAYAIM:

To perform Rotate Left With Delay operation using 8051 simulation environment KEIL C.

COMPONENTS REQUIRED:

KEIL C simulation software..

ALGORITHM:

Step 1: Start the program.

Step 2: Put the value of Port 0 as 1001010(A5).

Step 3: Shift the bit towards right continously.

Step 4: Call Delay routine.

Step 5: get the value of port 1 as 11010010(D2).

Step 6: End the program.

Page 14: EMBEDDED C PROGRAMS USING KEIL

OUTPUT:

Page 15: EMBEDDED C PROGRAMS USING KEIL

RESULT:

Thus the Rotate Left With Delay operation using 8051 simulation environment KEIL C was performed and verified successfully.

Page 16: EMBEDDED C PROGRAMS USING KEIL

PROGRAM:

Code locking

# include <REG52.h># include <stdio.h>char_get key (void);void main (void){char i;int j = 0;SCON = 0x50;TMOD = 0x20;TH1 = 221;TD1 = 1;TI = 1;While (1){if (j>3){i = _get key ( );if (j = = ‘a’){printf (“ code correct \n”);}else{i++;printf (“ code not correct\n”);if (i = = 3)printf (“ code locked”);}}}}

Page 17: EMBEDDED C PROGRAMS USING KEIL

Expt. No. : 04

Date :

CODE LOCKINGAIM:

To perform Code Locking operation using 8051 simulation environment KEIL C.

COMPONENTS REQUIRED:

KEIL C simulation software..

ALGORITHM:

Step 1: Start the program.

Step 2: Write program in IDE.

Step 3: Compile the program.

Step 4: Run the Simulator.

Step 5: End the program.

Page 18: EMBEDDED C PROGRAMS USING KEIL

OUTPUT:

Page 19: EMBEDDED C PROGRAMS USING KEIL

RESULT:

Thus the Code Locking operation using 8051 simulation environment KEIL C was performed and verified successfully.