You are on page 1of 33

Roll No: 04098039

INTRODUCTION
The platform of 8051 development kit is intended as a demonstration and evaluation of ATMEL Core 8051 Microcontroller. The kit is a general purpose, low cost and highly expandable micro controller system. It is based on the ATMEL 8051 single chip flash micro controller. Features of Development Board: 1. 16 x 2 Character LCD Display. 2. 32 Kbyte of External RAM. 3. On board RS232 compatible serial interface. 4. Temperature Sensor. 5. EPROM for storing non volatile parameters. 6. Real Time Clock. 7. 8-Channel (8-bit) A/D Converter. 8. 1-Channel (8-bit) D/A Converter. 9. 4 x 4 Matrix Keyboard (Optional). 10. 8 Push Button Switches. 11. 2 External Interrupts. 12. 2 16-bit Timers/Counters. 13. 7-Segment Displays. 14. Stepper Motor Interface.

Roll No: 04098039

ADDRESS TABLE:

7-SEGMENT LEDS SELECTION:

Roll No: 04098039

ADC Channel Selection:

ADC PINS:

Roll No: 04098039

1. Demonstration of LED using 8051 Microcontroller.

ALGORITHM:
STEP 1: STEP 2: STEP 3: STEP 4: STEP 5: STEP 6: Assign LED Address for Microcontroller Kit. While true. Write Data to LED Address. Delay for certain time. Clear Data at LED Address. Repeat Steps 3, 4, 5.

Roll No: 04098039

PROGRAM:
#include<REGX51.H> #define LED_ADDRESS 0x8600 data unsigned char xdata *LED = LED_ADDRESS; unsigned char prev; void led(unsigned char dat) { prev = dat; *LED = prev; } void delay(unsigned int count) { unsigned int i,j; for(i=0;i<count;i++) { for(j=0;j<count;j++) { } } } void setled(unsigned char dat) { prev |= (1<<dat); *LED = prev; } void clrled(unsigned char dat) { prev &= ~(1<<dat); *LED = prev;
5

Roll No: 04098039

} int main(void) { int c; while(1) { for(c=0;c<=7;c++) { setled(c); delay(1000); clrled(c); delay(1000); } for(c=7;c>=0;c--) { setled(c); delay(1000); clrled(c); delay(1000); } } }

Roll No: 04098039

2. Demonstration of LCD using 8051 Microcontroller. ALGORITHM:


STEP 1: STEP 2: STEP 3: STEP 4: STEP 5: STEP 6: STEP 7: Initialize Set of Commands. Check if LCD is Free or Busy. Initialize LCD with proper set of Commands. Write each Command to LCD Command Write Address. Repeat Step 4 till all commands are written. Check if LCD is Free or Busy. Write Data to LCD Data Write Address.

Commands which are used frequently while working on the LCD.

Address of cursor position for 16 x 2 LCD.

Roll No: 04098039

PROGRAM:
#include<REGX51.H> #define LCD_ENABLE 0x8000 #define LCD_DISPLAY 0x8900 #define LCD_CMDWR 0x8000 #define LCD_CMDRD 0x8002 #define LCD_DATAWR 0x8001 data unsigned char xdata *lcddisplay = LCD_DISPLAY; data unsigned char xdata *lcdcomwrite = LCD_CMDWR; data unsigned char xdata *lcdcomread = LCD_CMDRD; data unsigned char xdata *lcddatawrite = LCD_DATAWR; void LCDcheck(void); void LCDcheck(void) { unsigned char temp; do { temp = *lcdcomread; }while(temp & 0x80); *lcddisplay = 0x00; } void putcom(unsigned char command); void putcom(unsigned char command) { unsigned int i; LCDcheck(); *lcdcomwrite = command; for(i=0;i<1000;i++); *lcddisplay = 0x00; } void lcdinit(void) {
8

Roll No: 04098039

unsigned int i; unsigned char lcdtable[6] = {0x01,0x06,0x0C,0x38,0x80}; for(i=0;i<=5;i++) putcom(lcdtable[i]); } void putchar(unsigned char tdata , unsigned char command) { unsigned int i; LCDcheck(); putcom(command); *lcddatawrite = tdata; for(i=0;i<1000;i++); *lcdcomwrite = command; for(i=0;i<1000;i++); } /void putchar1(unsigned char dat) { unsigned int i; LCDcheck(); *lcddatawrite = dat; for(i=0;i<3000;i++); *lcddisplay = 0x00; }/ int main(void) { lcdinit(); put_char('A', 0xc0); }

Roll No: 04098039

3. Demonstration of Relays using 8051 Microcontroller.

ALGORITHM:
STEP 1: STEP 2: STEP 3: STEP 4: STEP 5: STEP 6: Assign Relay Address for Microcontroller Kit. While true. Write Data to Relay Address. Delay for certain time. Clear Data at Relay Address. Repeat Steps 3, 4, 5.

10

Roll No: 04098039

PROGRAM:
#include<REGX51.H> #define ULN2803_ADDRESS 0x8500 data unsigned char xdata *ULN = ULN2803_ADDRESS; unsigned char pre; void relay1(bit relay) { if(relay) { pre |= (1<<0); *ULN = pre; } else { pre &= ~(1<<0); *ULN = pre; } } void relay2(bit relay) { if(relay) { pre |= (1<<1); *ULN = pre; } else { pre &= ~(1<<1); *ULN = pre; } }

11

Roll No: 04098039

void delay(unsigned int count) { unsigned int i,j; for(i=0;i<count;i++) for(j=0;j<109;j++); } int main(void) { while(1) { relay1(1);//relay2(1); delay(500); relay1(0);//relay2(0); delay(500); } }

12

Roll No: 04098039

4. Demonstration of Stepper Motor using 8051 Microcontroller. ALGORITHM:


STEP 1: Connect the Stepper Motor to Microcontroller Kit. STEP 2: To run Stepper Motor in Clockwise Direction send Data 0x10, 0x20, 0x40, 0x80 one at a time to the Stepper Motor Address. STEP 3: Delay for certain time. STEP 4: To run Stepper Motor in Anti-Clockwise Direction send Data 0x80, 0x40, 0x20, 0x10 one at a time to the Stepper Motor Address. STEP 5: Delay for certain time.

Coil Configuration for Stepper Motor:

Controlling Stepper Motor with Two Port Pins Only for Clockwise Direction:

To reverse the motor just reverse the above sequence viz. 11,10,01,00.
13

Roll No: 04098039

PROGRAM:
#include<REGX51.H> #define ULN2803_ADDRESS 0x8500 data unsigned char xdata *ULN = ULN2803_ADDRESS; unsigned char pre; void stepper(int count,bit direction) { unsigned int i,j; if(direction) { for(int i=0;i<count;i++) { for(int j=0x10;j<=0x80;j=j<1) { pre=j; *ULN=pre; delay(50); } } } else { for(int i=0;i<count;i++) { for(int j=0x80;j>0x10;j=j>>1) { pre=j; *ULN=pre; delay(50); } } }
14

Roll No: 04098039

} void delay(unsigned int count) { unsigned int i,j; for(i=0;i<count;i++) for(j=0;j<109;j++); } int main(void) { while(1) { stepper(8,1); } }

15

Roll No: 04098039

5. Demonstration of Keypad using 8051 Microcontroller.

ALGORITHM:
STEP 1: Configure connections to Keypad. STEP 2: Initialize keypad by loading the Interrupt Enable Register, Interrupt Priority Register and setting Interrupt Type (ITI is Connected to all keys). STEP 3: Wait for the Key to be pressed. STEP 4: When Key is pressed interrupt routing will be called returning the key pressed. STEP 5: Display the corresponding LED for the Key Pressed.

16

Roll No: 04098039

PROGRAM:
#include<REGX51.H> #define KEYINT8 P3_3 #define KEYE_ADDRESS 0x8200 #define LED_ADDRESS 0x8600 data unsigned char xdata *keydata = KEYE_ADDRESS; data unsigned char xdata *LED = LED_ADDRESS; unsigned char prev; volatile unsigned char keyflag = 0,keytemp = 0; void led(unsigned char dat) { Prev = dat; *LED = Prev; } void key8_ISR(void) interrupt 2 { keytemp = *keydata; keyflag = 1; } unsigned char getcharkey(void) { IE|=0x84; IP|=0x04; IT1=0; keyflag = 0; while(!keyflag); return ~keytemp; }

17

Roll No: 04098039

int main() { unsigned char val; while(1) { val = getcharkey(); led(val); } }

18

Roll No: 04098039

6. Demonstration of Temperature Controller using 8051 Microcontroller.

ALGORITHM:
STEP 1: Initialize LCD. STEP 2: Display TEMPERATURE on the LCD Screen. STEP 3: Using the Temperature Sensor present on the 8051 Microcontroller Kit. STEP 4: Record the temperature and depending upon that signal the relay. STEP 5: Display the temperature in degrees on the LCD Screen.

19

Roll No: 04098039

PROGRAM:
#include<REGX51.H> #include"adc.c" #include"relays.c" #include"lcd.c" #include"buzzer.c" int main( ) { unsigned char temp,*ptr; lcdInit(); putStrL("TEMPERATURE",0x01); relay1(0); relay2(0); buzzer1(0); buzzer2(0); while(1) { temp=getAdc(6); temp=(temp/5)*2; if(temp>30&&temp<35) { relay1(1); } else if(temp>36&&temp<40) { relay2(1); } else if(temp>41) { buzzer1(1); buzzer1(2); } else {
20

Roll No: 04098039

relay1(0); delay(100); relay2(0); delay(100); buzzer1(0); buzzer2(1); delay(100); buzzer2(0); } ptr=des2ascii(temp); putStrL(ptr,0xC4); putCharL(0xDF); } }

21

Roll No: 04098039

7. Demonstration of Analog to Digital Converter (ADC) using 8051 Microcontroller. ALGORITHM:


STEP 1: STEP 2: STEP 3: STEP 4: STEP 5: STEP 6: Check how many channels are connected. Initialize LCD for displaying data. Select ADC Input Channel. Read Data from Selected Channel. Provide some time delay. Write Data to LCD Data Write Address.

Channel Addresses:

22

Roll No: 04098039

PROGRAM:
#include<REGX51.H> #include "lcdstring.c" #define ADC_ADDRESS 0x8400 //ADC definitions #define ch0 0x8F00 #define ch1 0x8F01 #define ch2 0x8F02 #define ch3 0x8F03 #define ch4 0x8F04 #define ch5 0x8F05 #define ch6 0x8F06 #define ch7 0x8F07 #define start 0x8B00 data unsigned char xdata *CH0=ch0; data unsigned char xdata *CH1=ch1; data unsigned char xdata *CH2=ch2; data unsigned char xdata *CH3=ch3; data unsigned char xdata *CH4=ch4; data unsigned char xdata *CH5=ch5; data unsigned char xdata *CH6=ch6; data unsigned char xdata *CH7=ch7; data unsigned char xdata *START=start; data unsigned char *ADC_DATA=ADC_ADDRESS; void delay(unsigned int count) { unsigned int i,j; for(i=0;i<count;i++) for(j=0;j<109;j++); } unsigned char* des2ascii(unsigned char val) { static unsigned char dat[4]; unsigned char p,q,r;
23

Roll No: 04098039

p=val/100; p=p+0x30; dat[0]=p; val=val%100; q=val/10; q=q+0x30; dat[1]=q; val=val%10; r=val; r=r+0x30; dat[2]=r; dat[3]='\0'; return dat; } unsigned char getADC(unsigned char chn) { unsigned char val; unsigned int j; switch(chn) { case 0: *CH0=0x00; break; case 1: *CH1=0x00; break; case 2: *CH2=0x00; break; case 3: *CH3=0x00; break; case 4: *CH4=0x00; break;
24

Roll No: 04098039

case 5: *CH5=0x00; break; case 6: *CH6=0x00; break; case 7: *CH7=0x00; break; } for(j=0;j<10000;j++); *START=0x00; for(j=0;j<10000;j++); val=*ADC_DATA; return val; } int main() { unsigned char val,*ptr; lcdinit(); putstring("Welcome",0x01); delay(1000); putstring("ADC channel",0x01); while(1) { val=getADC(6); val=(val/5)*2; ptr=des2ascii(val); putstring(ptr,0x12); delay(10000); } }

8. Demonstration of Traffic Controller using 8051 Microcontroller.


25

Roll No: 04098039

ALGORITHM:
STEP 1: STEP 2: STEP 3: STEP 4: STEP 5: STEP 6: Assign LED Address for Microcontroller Kit. While true. Write Data to LED Address. Delay for certain time. Clear Data at LED Address. Repeat Steps 3, 4, 5.

PROGRAM:

26

Roll No: 04098039

#include<REGX51.H> #define LED_ADDRESS 0x8600 data unsigned char xdata *LED = LED_ADDRESS; unsigned char prev; void led(unsigned char dat) { prev = dat; *LED = prev; } void delay(unsigned int count) { unsigned int i,j; for(i=0;i<count;i++) { for(j=0;j<count;j++) { } } } void setled(unsigned char dat) { prev |= (1<<dat); *LED = prev; } void clrled(unsigned char dat) { prev &= ~(1<<dat); *LED = prev; }

27

Roll No: 04098039

int main(void) { while(1) { led(0xA9); delay(150); led(0xA6); delay(150); led(0x9A); delay(150); led(0x6A); delay(150); } }

9. Demonstration of Elevator Controller using 8051 Microcontroller.


28

Roll No: 04098039

ALGORITHM:
STEP 1: STEP 2: STEP 3: STEP 4: Initially Elevator is at GRND FLR so LED 1 is made to glow. While True. Press the Keypad Switches to go to that floor. Depending upon the Key Pressed the Stepper Motor either rotates Clockwise or Anti-Clockwise. STEP 5: Simultaneously, LED of that particular floor glows. STEP 6: Repeat 3, 4, and 5.

PROGRAM:

29

Roll No: 04098039

#include<REGX51.h> #include "keypad.c" #include "led.c" #include "stepper.c" int main() { unsigned char loc,prev; loc = 0x01; prev = loc; led(0x01); while(1) { loc = getchar8(); if(loc<prev) { while(!(loc==prev)) {prev = prev>>1; led(prev); step(4,0);} } else if(loc>prev) { while(!(loc==prev)) { prev = prev<<1; led(prev); step(4,1); } } else if(loc==prev) { prev = loc; }}}

10. Demonstration of RS232 Serial Communication.

30

Roll No: 04098039

ALGORITHM:
STEP 1: STEP 2: STEP 3: STEP 4: STEP 5: STEP 6: Initialize Serial Data Communication. Put the string UARTO TEST. while true. Read Character. Display Character. Repeat 4 and 5.

PROGRAM:
31

Roll No: 04098039

#include<LPC214X.H> #define Fpclk 60000000.0 void InitSerial0(unsigned long baudrate); void putCharS0(unsigned char ch); void putStrS0(unsigned char *string); unsigned char getCharS0(void); void InitSerial0(unsigned long baudrate) { int val; //PINSEL0&=0xFFFFFFF0; PINSEL0|=0x00000005; //Enable pin 0.0 as TX and RX VPBDIV|=0x00000001; val=Fpclk/(16*baudrate); U0LCR=0x83; /*8bits,no Parity,1 Stop bit*/ U0DLM=(val&0xFF00)>>8; U0DLL=(val&0xFF); U0LCR=0x03; /*DLAB=0*/ } void putCharS0(unsigned char ch) { while(!(U0LSR&0x20)); U0THR=ch; } void putStrS0(unsigned char *string) { while(*string) { putCharS0(*string++); } }
32

Roll No: 04098039

unsigned char getCharS0(void) { while(!(U0LSR&0x01)); return(U0RBR); } int main(void) { unsigned char ch; InitSerial0(9600); putStrS0("UARTO test"); while(1) { ch=getCharS0(); putCharS0(ch); } }

33

You might also like