0% found this document useful (0 votes)
320 views22 pages

Es Lab Manual-Jntuk

The document contains source code and output for several experiments conducted on an 8051 microcontroller board. The experiments include programs to read inputs from switches, make LEDs blink, implement serial communication, encryption/decryption, interface with sensors and displays, verify an RTOS on the board, and simulate elevator movement using RTOS.

Uploaded by

Melissa Guerra
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
320 views22 pages

Es Lab Manual-Jntuk

The document contains source code and output for several experiments conducted on an 8051 microcontroller board. The experiments include programs to read inputs from switches, make LEDs blink, implement serial communication, encryption/decryption, interface with sensors and displays, verify an RTOS on the board, and simulate elevator movement using RTOS.

Uploaded by

Melissa Guerra
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd

INDEX

S.No 1. 2. 3. 4. 5. Exp. No. 1.a 1.b 2 3 4 Date Name of Experiments Page .No. 1 2. 3. 5. 9. Remarks Signature

27-06-08 Write a program to Read inputs from switches. 10-07-08 Write a program to To make LEDs blink. 18-07-08 Write a Program for serial communication. 1-08-08 Write a program for encruption/decruption.

6. 7.

5. 6.

22-08-08 Develop necessary interfacing circuit to read data from a sensor and process using the 8051 board. The data has to be displayed on a board lcd screen. 19-09-08 Verifying mCOS on 89C51 board 3-10-08 Simulate on elevator movement using RTOs .

12 17

EXPERIMENT NO: 1 (a) AIM: write a program to read inputs from switches SOURCE CODE: #include<8051.h> __xdata __at (0xffc0) unsigned char ledptr; //led location __xdata __at (0xffc1) unsigned char swtptr; // switch location unsigned int switch_data; void main() { while(1) { ledptr=swtptr; } }

DATE: 27-06-08

OUTPUT:

PVP SIDDHARTHA INSTITUTE OF TECHNOLOGY

EXPERIMENT NO: 1(b) AIM: write a program to make LEDs blink SOURCE CODE: #include<8051.h> __xdata __at (0xffc0) unsigned char ledptr; //led location __xdata __at (0xffc1) unsigned char swtptr; // switch location __xdata __at (0xffc2) unsigned char segptr; __xdata __at (0xffc3) unsigned char seg2ptr; unsigned int switch_data; void main() { while(1) { ledptr=swtptr; seg2ptr=0x08; segptr=swtptr; } } OUTPUT:

DATE: 10-07-08

PVP SIDDHARTHA INSTITUTE OF TECHNOLOGY

EXPERIMENT NO: 2 AIM: Write a program for serial communication. SOURCE CODE: #include<8051.h> #include<serial_IO.h> unsigned char c; void serial_init() // Initialize UART baud rate to 9600 { TMOD = 0X20; TH1 = 0XFD; TI = 1; TR1 = 1; SCON = 0X52; //PCON =0x80; } void main() { serial_init(); while(1) { c = getchar(); putchar(c); } }

DATE: 18-07-08

PVP SIDDHARTHA INSTITUTE OF TECHNOLOGY

OUTPUT:

PVP SIDDHARTHA INSTITUTE OF TECHNOLOGY

EXPERIMENT NO: 3 AIM: Write a program for Encryption / Decryption. SOURCE CODE: #include <8051.H> #include<stdio.h> #include<serial_io.h> #include<string.h> void serial(); void encrypt(); void tx(); void delay(); void rx(); void arr(); void arr1(); unsigned char b[5]={0x38,0x01,0x06,0x0c,0x80}; unsigned char b1[]={"PVPSIT"}; unsigned char b2[7]; unsigned char b3[8]; int k,m,n;

DATE: 1-08-08

PVP SIDDHARTHA INSTITUTE OF TECHNOLOGY

unsigned char a[50]; unsigned int i,l,cnt=0; unsigned char key; void main() { serial(); while(1) { rx(); printf("\n \t ENTER THE PASSWORD:\t "); arr(); if(strcmp (b1,b2)==0) { tx(); delay(); return; } else printf("\n \r YOU ARE UNAUTHORISED PERSON "); } } void serial() { TMOD = 0X20; TH1 = 0XFD; TI = 1; TR1 = 1; SCON = 0X52; //PCON = 0x80; } void rx() { printf("\n\r----------------------------------------------------------------"); printf("\n\r ENCRYPTION "); printf("\n\r----------------------------------------------------------------\n\r"); printf("\n \t ENCRYPTED DATA: \t"); for(i=0;i<50;i++) { while(RI!=1); RI=0; a[i]=SBUF; if(a[i]==0x0d) break; PVP SIDDHARTHA INSTITUTE OF TECHNOLOGY 7

SBUF=SBUF+0x30; cnt++; } return; } void tx() { printf("\n\r----------------------------------------------------------------"); printf("\n\r DECRYPTION "); printf("\n\r----------------------------------------------------------------\n"); printf("\n DECRYPTED DATA: \t"); for(i=0;i<=50;i++) { SBUF=SBUF-0x30; SBUF=a[i]; while(TI!=1); TI=0; } cnt=0; return; } void delay() { unsigned int m; for(m=0;m<0x0f;m++); } void arr() { unsigned char i; for(i=0;i<=6;i++) { while(RI==0); b2[i]=SBUF; SBUF=0x2a; while(TI==0); TI=0; RI=0; } b2[i]='\0'; } OUTPUT:

PVP SIDDHARTHA INSTITUTE OF TECHNOLOGY

INCORRECT PASSWORD

PVP SIDDHARTHA INSTITUTE OF TECHNOLOGY

CORRECT PASSWORD

EXPERIMENT NO: 4

DATE: 22-08-08 10

PVP SIDDHARTHA INSTITUTE OF TECHNOLOGY

AIM: Develop necessary interfacing circuit to read data from sensor and process using the 8051 board. The data has to be displayed on a PC monitor. SOURCE CODE: #include "8051.h" /*--------------------------------------------*/ __xdata __at 0xffc5 unsigned char ledr; __xdata __at 0xffc3 unsigned char sel174; __xdata __at 0xffc4 unsigned char lcdsel; unsigned int s; /*--------------------------------------------*/ void delay() { int i,j; for(i=0;i<0x3f;i++) for(j=0;j<0xff;j++); } /*-------------------------------------------*/ void busycheck() { delay(); sel174 = 0x00; } /*--------------------------------------------*/ void lcd_write(unsigned char *temp,int cnt) { int i; for(i=0;i<cnt;i++) { busycheck(); sel174=0x01; lcdsel= *temp; temp++; } } /*-------------------------------------------*/ void main() { busycheck(); lcdsel = 0x38; // Configure Interface length, No of display lines busycheck(); lcdsel = 0x06; // Shift Cursor Position busycheck(); PVP SIDDHARTHA INSTITUTE OF TECHNOLOGY 11

lcdsel = 0x01; // Clear LCD busycheck(); lcdsel = 0x0f; // Turn On display,cursor and cursor blink busycheck(); lcdsel = 0x80; while(1) { s=ledr; s = ((s&0x20)>>0x05); if(s==0) { lcd_write("No Object",9); busycheck(); lcdsel = 0x01; } if(s==1) { lcd_write("Object Present",14); busycheck(); lcdsel = 0x01; } } } OUTPUT: (NO OBJECT IN SENSOR)

(OBJECT IN SENSOR) PVP SIDDHARTHA INSTITUTE OF TECHNOLOGY 12

EXPERIMENT NO: 5

DATE: 19-09-08 13

PVP SIDDHARTHA INSTITUTE OF TECHNOLOGY

AIM: Sort RTOS (mCOS) on to 89C51 board SOURCE CODE: #include "includes.h" #include "ucos_ii.h" #include "test.h" #include <at89c51ed2.h> #include <serial_IO.h> OS_STK Task1stk[100]; OS_STK Task2stk[100]; OS_STK Task3stk[100]; xdata at 0xffc0 unsigned char ledptr; xdata at 0xffc2 unsigned char segmentselPtr; xdata at 0xffc3 unsigned char sel174; xdata at 0xffc4 unsigned char lcdsel; void timer2_ISR ( void ) interrupt TIMER2_OVERFLOW { TF2 = 0; // Clear timer2 overflow flag. EXF2 = 0; // clear T2 Ext input flag. // disable Interrupts, Turn off the timer. EA = 0; TR2 = 0; //writeDataExt("begin timer0_isr\n"); OSIntSaveCtx(); //writeDataExt("timer0\n"); /* unnecessary auto-reload set*/ TH2 = RELOAD_HI; TL2 = RELOAD_LO; OSIntEnter(); //Read-modify-write increment of "OSIntNesting" OSTimeTick(); //Call process TR2 = 1; // start the timer again OSIntExit(); //Decrement OSIntNesting, and determine whether return to this //isr or a new Task PVP SIDDHARTHA INSTITUTE OF TECHNOLOGY 14

OSIntRestoreCtx(); EA = 1; } void delay() { unsigned int i,j; for(i=0;i<0xff;i++) for(j=0;j<0xff;j++); } void initStartTimersInterrupts() { T2CON = 0x00; //0000,0000 T2CON: Timer2 T2MOD = 0x00; RCAP2H = RELOAD_HI; RCAP2L = RELOAD_LO; TH2 = RELOAD_HI; TL2 = RELOAD_LO; TR0 = TR1 = TR2 = 0; //Stop all 3 timers TF2 = 0; PT2 = 1; //Timer2 gets highest priority, system time // Clear timer2 overflow flag. //Timer2 Interrupt enabled //all interrupts

TF2 = 0; ET2 = 1; EA = 1; TR2 = 1;

} void serial_init()reentrant { TMOD = 0X20; TH1 = 0XFD; TI = 1; TR1 = 1; SCON = 0X52; //PCON =0x80; }

PVP SIDDHARTHA INSTITUTE OF TECHNOLOGY

15

void delay2() { int i,j; for(i=0;i<0xf;i++) for(j=0;j<0xff;j++); } void busycheck() { delay2(); sel174 = 0x00; }

void task1(void *ptr) { ptr=ptr; initStartTimersInterrupts(); while(1) { ledptr = 0x00; delay(); ledptr = 0x0f; delay(); ledptr = 0x00; OSTimeDly(300); } } void task2(void *ptr) { unsigned char array[] ={"uC/OS II Welcome"}; unsigned char array1[] ={" by Vi MicroSys "}; unsigned char i; ptr=ptr; while(1) { busycheck(); lcdsel = 0x38; busycheck(); lcdsel = 0x06; PVP SIDDHARTHA INSTITUTE OF TECHNOLOGY 16

busycheck(); lcdsel = 0x01; busycheck(); lcdsel = 0x0f; busycheck(); lcdsel = 0x80; for (i=0;i<16;i++) { busycheck(); delay2(); sel174 = 0x01; lcdsel = array[i]; } busycheck(); lcdsel = 0xC0; for (i=0;i<16;i++) { busycheck(); delay2(); sel174 = 0x01; lcdsel = array1[i]; } OSTimeDly(200); } } void task3(void *ptr) { ptr=ptr; ledptr = 0x00; delay(); ledptr = 0xf0; delay(); ledptr = 0x00; OSTimeDly(50); } void main(void) { OSInit(); OSTaskCreate(task1, 0, &Task1stk[49], 4); // LED -0f OSTaskCreate(task2, 0, &Task2stk[49], 5); // LCD PVP SIDDHARTHA INSTITUTE OF TECHNOLOGY 17

OSTaskCreate(task3, 0, &Task3stk[49], 6); // ledf0 OSStart(); } OUTPUT:

EXPERIMENT NO: 6

DATE: 3-10-08 18

PVP SIDDHARTHA INSTITUTE OF TECHNOLOGY

AIM: Simulate on Elevator movement using RTOS on 89C51 board. SOURCE CODE: #include "includes.h" #include "ucos_ii.h" #include <P89c51RD2.h> #include <stdio.h> OS_STK Task1stk[100]; OS_STK Task2stk[100]; unsigned int cur=0; unsigned char temp; __xdata __at 0xffc0 unsigned char led; __xdata __at 0xffc5 unsigned char swt; __xdata __at 0xffc6 unsigned char ledptr; __xdata __at 0xffcc unsigned char wheel; // assigned led address // address for elevator switches // address for elevator leds // address for elevator thumb wheel //task stack creation

void TimerInitiate(unsigned char Crystal,unsigned char Frequency); data INT16U TickCount; void UserTickTimer(void) { TickCount++; } /*---- Timer0 ISR----*/ void timer0_ISR ( void ) interrupt 1 { EA = 0; TR0 = 0; temp=IE; OSIntEnter(); UserTickTimer(); OSTimeTick(); TimerInitiate(12,1000); OSIntExit(); IE=temp; EA = 1; } void TimerInitiate(unsigned char Crystal,unsigned char Frequency) { unsigned long temporary = 0; temporary = 1000000 / (12 * Frequency); PVP SIDDHARTHA INSTITUTE OF TECHNOLOGY 19

temporary = 65535 - Crystal * temporary; TMOD = (TMOD & 0XF0) | 0X01; /* Timer 0 working in MODE 1 */ TL0 = (unsigned char )temporary; TH0 = (unsigned char )(temporary >> 8); TR0 = 1; ET0 = 1; } /*----Task1 Routine for elevator simulation----*/ void task1 (void) { char floor[6] = { 0x10,0x08,0x04,0x02,0x01}; char ref[6] = { 0x1F,0x1E,0x1D,0x1C,0x1B}; char cur = 0; char req,k; ledptr = 0x10; while(1) { k = (swt & 0x1f); req = (wheel & 0x1F); if(k == 0x0F && req > 0x1A ) { if(ref[cur] == req) { ledptr = floor[cur]; } else if(ref[cur] < req) { while(ref[cur] != req) { cur = cur - 1; ledptr = floor[cur]; OSTimeDly(40); } } else if(ref[cur] > req) { while(ref[cur] != req) { cur = cur + 1; ledptr = floor[cur]; OSTimeDly(40); } } } OSTimeDly(40); } PVP SIDDHARTHA INSTITUTE OF TECHNOLOGY 20

} void task2(void) { while(1) { ledptr = 0x00; OSTimeDly(20); ledptr = 0x0f; OSTimeDly(20); ledptr = 0x00; OSTimeDly(20); } } void main(void) { OSInit(); TimerInitiate(12,1000); OSTaskCreate(task1, 0, &Task1stk[99], 4); OSTaskCreate(task2, 0, &Task1stk[99], 2); OSStart(); } OUTPUT:

// Call OS Initialization // Call timer initilization // Task creation // Start Multitasking

PVP SIDDHARTHA INSTITUTE OF TECHNOLOGY

21

PVP SIDDHARTHA INSTITUTE OF TECHNOLOGY

22

You might also like