es lab manual-jntuk
TRANSCRIPT
INDEX
S.No Exp.No.
Date Name of Experiments Page.No.
Remarks Signature
1. 1.a 27-06-08 Write a program to Read inputs from switches.
1
2. 1.b 10-07-08 Write a program to To make LEDs blink. 2.
3. 2 18-07-08 Write a Program for serial communication.
3.
4. 3 1-08-08 Write a program for encruption/decruption.
5.
5. 4 22-08-08 Develop necessary interfacing circuit to read data from a sensor and process using the 8051board. The data has to be displayed on a board lcd screen.
9.
6. 5. 19-09-08 Verifying mCOS on 89C51 board 12
7. 6. 3-10-08 Simulate on elevator movement using RTOs .
17
EXPERIMENT NO: 1 (a) DATE: 27-06-08
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;}
}
OUTPUT:
PVP SIDDHARTHA INSTITUTE OF TECHNOLOGY 1
EXPERIMENT NO: 1(b) DATE: 10-07-08
AIM: write a program to make LED’s 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:
PVP SIDDHARTHA INSTITUTE OF TECHNOLOGY 2
EXPERIMENT NO: 2 DATE: 18-07-08
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);
}}
PVP SIDDHARTHA INSTITUTE OF TECHNOLOGY 3
OUTPUT:
PVP SIDDHARTHA INSTITUTE OF TECHNOLOGY 4
EXPERIMENT NO: 3 DATE: 1-08-08
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;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 ");}}
PVP SIDDHARTHA INSTITUTE OF TECHNOLOGY 5
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; 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;
PVP SIDDHARTHA INSTITUTE OF TECHNOLOGY 6
} 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:
INCORRECT PASSWORD
PVP SIDDHARTHA INSTITUTE OF TECHNOLOGY 7
CORRECT PASSWORD
PVP SIDDHARTHA INSTITUTE OF TECHNOLOGY 8
EXPERIMENT NO: 4 DATE: 22-08-08
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
PVP SIDDHARTHA INSTITUTE OF TECHNOLOGY 9
busycheck();lcdsel = 0x06; // Shift Cursor Positionbusycheck();lcdsel = 0x01; // Clear LCD busycheck();lcdsel = 0x0f; // Turn On display,cursor and cursor blinkbusycheck();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)
PVP SIDDHARTHA INSTITUTE OF TECHNOLOGY 10
(OBJECT IN SENSOR)
PVP SIDDHARTHA INSTITUTE OF TECHNOLOGY 11
EXPERIMENT NO: 5 DATE: 19-09-08
PVP SIDDHARTHA INSTITUTE OF TECHNOLOGY 12
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 13
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
TF2 = 0; // Clear timer2 overflow flag.
ET2 = 1; //Timer2 Interrupt enabled EA = 1; //all interrupts TR2 = 1;
}void serial_init()reentrant{
TMOD = 0X20;TH1 = 0XFD;TI = 1;TR1 = 1;SCON = 0X52;//PCON =0x80;
}
PVP SIDDHARTHA INSTITUTE OF TECHNOLOGY 14
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 15
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 -0fOSTaskCreate(task2, 0, &Task2stk[49], 5); // LCD
PVP SIDDHARTHA INSTITUTE OF TECHNOLOGY 16
OSTaskCreate(task3, 0, &Task3stk[49], 6); // ledf0
OSStart();}
OUTPUT:
EXPERIMENT NO: 6 DATE: 3-10-08
PVP SIDDHARTHA INSTITUTE OF TECHNOLOGY 17
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]; //task stack creation OS_STK Task2stk[100];
unsigned int cur=0;unsigned char temp;
__xdata __at 0xffc0 unsigned char led; // assigned led address__xdata __at 0xffc5 unsigned char swt; // address for elevator switches__xdata __at 0xffc6 unsigned char ledptr; // address for elevator leds__xdata __at 0xffcc unsigned char wheel; // address for elevator thumb wheel
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 18
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 19
}void task2(void) {
while(1){
ledptr = 0x00;OSTimeDly(20);ledptr = 0x0f;OSTimeDly(20);ledptr = 0x00;OSTimeDly(20);
}}
void main(void){
OSInit(); // Call OS InitializationTimerInitiate(12,1000); // Call timer initilizationOSTaskCreate(task1, 0, &Task1stk[99], 4); // Task creation
OSTaskCreate(task2, 0, &Task1stk[99], 2);OSStart(); // Start Multitasking
}OUTPUT:
PVP SIDDHARTHA INSTITUTE OF TECHNOLOGY 20
PVP SIDDHARTHA INSTITUTE OF TECHNOLOGY 21