SlideShare a Scribd company logo
1 of 73
Download to read offline
void main(void){
TMOD=0x20; //use Timer 1, mode 2
TH1=0xFD; //9600 baud rate
SCON=0x50;
TR1=1; //start timer
while (1) {
SerTx('Y');
SerTx('E');
SerTx('S');
}
}
void SerTx(unsigned char x){
SBUF=x; //place value in buffer
while (TI==0); //wait until transmitted
TI=0;
}
#include<reg51.h>
#include<stdio.h>
void DelayMs(unsigned int);
void serial_init(void);
void Transmit(unsigned char);
unsigned char Receive(void);
void uart_puts(unsigned char *str);
unsigned char i,RecDat;
code unsigned char x[]
={"Hello world!!!Press a Key:rn"};
void main()
{
DelayMs(10);
serial_init();
DelayMs(10);
uart_puts("Hello world!!!Press a
Key:rn");
while(1)
{
uart_puts("You Pressed:");
Transmit(Receive());
uart_puts("nr");
}
}
unsigned char Receive(void)
{
while(RI==0);
RI = 0;
return SBUF;
}
void uart_puts(unsigned char *str)
{
while(*str)
Transmit(*str++);
}
void DelayMs(unsigned int val)
{
int j=0;
while(val>0)
{
val--;
for(j=0;j<200;j++);
}
}
void serial_init(void)
{
SCON = 0x50;
TMOD = 0x20;
TH1 = 0xFD;
//9600
TR1 = 1;
TI = 1;
}
void Transmit(unsigned char dat)
{
while(TI==0);
TI = 0;
SBUF = dat;
}
1. Write an 8051 assembly program to transfer data serially at baud rate 9600 with 8 bit
data, one stop bit and observe the transmitted data in the serial window of the simulator.
org 0000H
XX: MOV DPTR,#MYDATA
MOV TMOD,#20H
MOV TH1,#-3
MOV SCON,#50H
SETB TR1
MOV R1,#14
AGAIN:CLR A
MOVC A,@A+DPTR
MOV SBUF,A
HERE: JNB TI,HERE
CLR TI
INC DPTR
DJNZ R1,AGAIN
SJMP XX
MYDATA: DB 'VIT UNIVERSITY'
END
3. Assume that the 8051 serial port is connected to the COM port of
IBM PC, P1 and P2 of the 8051 are connected to LEDs and switches, respectively.
Assume that XTAL-11.0592Mhz.
Write an 8051 assembly program to
(a) send to PC the message “We Are Ready”,
(b) receive any data send by PC and put it on LEDs connected to P1, and
(c) get data on switches connected to P2 and send it to PC serially. 4800 baud rate
END
Write an 8051 program to get data from port P0 and send it to port P1 continuously
while an interrupt will do the following: Timer 0 will toggle the P2.1 bit every 200
microseconds.
Program number: 1
ORG 0000H
LJMP MAIN // Jump to main.
ORG 000BH // timer 0 Interrupt vector label
CPL P2.1 // Toggle P2.1 pin
RETI // Return from ISR
ORG 0030H // After Vector Table Space
MAIN:MOV TMOD,#02H //set Timer 0 in mode 2
MOV P0,#0FFH // Set P0 an I/P port
MOV TH0,#-92 //
MOV IE,#10000010B // enable Timer 0
SETB TR0 // Start the Timer
BACK:MOV A,P0 // Get data from P0.
MOV P1,A // move data P0 to P1
SJMP BACK //Loop it Unless interrupted
END
Program 2 Assembly Language
Write an 8051 program to get data from a single bit of P1.2 and send it to P1.7
continuously while an interrupt will do the following:
A serial interrupt service routine will receive data from a PC and display it on P2 ports.
ORG 0000H
LJMP MAIN
ORG 0023H ; ----serial interrupt vector table
LJMP SERIAL
ORG 0030H ;-- after vector table space
MAIN:SETB P1.2 ; -- P1.2 made as input pin
MOV TMOD,#00100000B ; -- timer 1 mode 2
MOV TH1,#-3 ;-- set baud rate 9600
MOV SCON ,#01010000B ; -- one stop bit
MOV IE,#10010000B ; -- serial int. enabled.
SETB TR1 ;-- Timer 1 stared.
BACK:MOV C,P1.2
MOV P1.7,C
SJMP BACK
SERIAL:JB TI,TRANS
MOV A,SBUF
MOV P2,A
CLR RI
RETI
TRANS:CLR TI
RETI
END
Task
Write a 8051 ALP using interrupts to do the following:
(a) Receive data serially and sent it to P0, (UART p0)
(b) Have P1 port read and transmitted serially, and a copy given to P2, P1 UART
P1P2
(c) Make timer 0 mode 1 to generate a square wave of 5 Khz frequency on P3.2.
Assume that XTAL-11.0592Mhz. Set the baud rate at 4800.
#include <reg51.h>
sbit SW =P1^7;
sbit IND =P1^0;
sbit WAVE =P2^5;
void timer0(void) interrupt 1 {
WAVE=~WAVE; //toggle pin
}
void main() {
SW=1; //make switch input
TMOD=0x02;
TH0=0xA4; //TH0=-92
IE=0x82; //enable interrupt for timer 0
while (1) {
IND=SW; //send switch to LED
}
}
A) Write an 8051 assembly program to transfer data serially at baud rate 9600 with 8 bit
data, one stop bit and observe the transmitted data in the serial window of the
simulator.
org 0000H
XX: MOV DPTR,#MYDATA
MOV TMOD,#20H
MOV TH1,#-3
MOV SCON,#50H
SETB TR1
MOV R1,#14
AGAIN:CLR A
MOVC A,@A+DPTR
MOV SBUF,A
HERE: JNB TI,HERE
CLR TI
INC DPTR
DJNZ R1,AGAIN
SJMP XX
MYDATA: DB 'VIT UNIVERSITY'
END
B) Write a 8051 Assembly Language program to get data from the PC
and display it on P1. Assume 8051 is connected to PC and
observe the incoming characters. As you press a key on the PC's keyboard,
the character is sent to the 8051 serially at 4800 baud rate and is
displayed on LEDs. The characters displayed on LEDs are in ASCII (binary).
ORG 0000H
MOV TMOD ,#20H
MOV TH1,#-6
MOV SCON,#50H
SETB TR1
HERE:JNB RI,HERE
MOV A,SBUF
MOV P1,A
CLR RI
SJMP HERE
END
Assume that the 8051 serial port is connected to the COM port of
IBM PC, P1 and P2 of the 8051 are connected to LEDs and switches, respectively.
Write an 8051 assembly program to
(a) send to PC the message “We Are Ready”,
(b) receive any data send by PC and put it on LEDs connected to P1, and
(c) get data on switches connected to P2 and send it to PC serially.
P2 INPUT UART OUTPUT
baud rate 4800
Write an 8051 program to get data from a single bit of P1.3 and send it to P1.5
continuously while an interrupt will do the following: A serial interrupt service routine
will receive data from a PC and display it on P2 ports. set baud rate 9600
timer 1 mode 2…… Analyse and rectify the errors and specify the output.
ORG 0000H
LJMP MAIN
ORG 0032H ; ----serial interrupt vector table
LJMP SERIAL
ORG 0030H ;-- after vector table space
MAIN:SETB P1.3 ; -- P1.2 made as input pin
MOV TMOD,#10H ; -- timer 1 mode 2
MOV TH1,# a4h ;-- set baud rate 9600
MOV SCON ,#50H ; -- one stop bit
MOV IE,10010010B ; -- serial int. enabled.
SETB TR1 ;-- Timer 1 stared.
BACK:MOV C,P1.3
MOV P1.5,C
SJMP BACK
SERIAL:JNB TI,TRANS
MOV A,SBUF
MOV P2,A
RETI
TRANS:CLR TI
RETI
END
Write a program using interrupts to do the following:
(a) Receive data serially and sent it to P0,
(b) Have P1 port read and transmitted serially, and a copy given to P2,
(c) Make timer 0 generate a square wave of 5kHz frequency on P3.2.
Assume that XTAL-11.0592. Set the baud rate at 4800.
ORG 0H
LJMP MAIN
ORG 100H
MAIN:
MOV TMOD,#22H
MOV TH1,#-3
SETB TR1
MOV SCON,#50H
MOV TH0,#0A4H
SETB TR0
MOV IE,#10010010b
MOV P1,#0FFH
REP:MOV A,P1
MOV SBUF,A
MOV P2,A
LOOP1:JNB TI,LOOP1
CLR TI
SJMP REP
ORG 0BH
CPL P3.2
RETI
ORG 23H
MOV A,SBUF
MOV P0,A
CLR RI
RETI
END
```
Connect the LCD to your 8051 Kit. Then write and run a program to display your
name on line 1 of the LCD (first name followed by last name with a space in
between).
;P1.0-P1.7 are connected to LCD data pins D0-D7
;P2.0 is connected to RS pin of LCD
;P2.1 is connected to R/W pin of LCD
;P2.2 is connected to E pin of LCD
ORG 0000H
MOV A,#38H
ACALL CMNWRT
ACALL DELAY
MOV A,#0EH
ACALL CMNWRT
ACALL DELAY
MOV A,#01H
ACALL CMNWRT
ACALL DELAY
MOV A,#06H
ACALL CMNWRT
ACALL DELAY
MOV A,#80H
ACALL CMNWRT
ACALL DELAY
MOV A,#'V'
ACALL DATWRT
ACALL DELAY
MOV A,#'I'
ACALL DATWRT
ACALL DELAY
MOV A,#'T'
ACALL DATWRT
ACALL DELAY
AGAIN: SJMP AGAIN
CMNWRT:
MOV P1,A
CLR P2.0
CLR P2.1
SETB P2.2
CLR P2.2
RET
DATWRT:
MOV P1,A
SETB P2.0
CLR P2.1
SETB P2.2
CLR P2.2
RET
DELAY: MOV R3,#0FFH
MOV R4,#0FFH
MOV R5,#55H
HERE: DJNZ R5,HERE
HERE1: DJNZ R4, HERE1
HERE2: DJNZ R3,HERE2
RET
END
7Segment LED interfacing
ADC and DAC interfacing
Module 7
DAC 0808 Interfacing
• The digital-to-analog converter (DAC) is a device widely used
to convert digital pulses to analog signals.
• methods of creating a DAC: binary weighted and R/2R ladder.
• The first criterion for judging a DAC is its resolution, which is a
function of the number of binary inputs.
• The common ones are 8, 10, and 12 bits.
• The number of data bit inputs decides the resolution of the
DAC since the number of analog output levels is equal to 2″,
where n is the number of data bit inputs. Therefore, an 8-
input DAC
• DAC0808 provides 256 discrete voltage (or current) levels of
output.
• Similarly, the 12-bit DAC provides 4096 discrete voltage levels.
• There are also 16-bit DACs, but they are more expensive.
Problem
8051 TIMER COUNTER SERIAL COMM. INTERUPT PROGRAMMING.pdf
8051 TIMER COUNTER SERIAL COMM. INTERUPT PROGRAMMING.pdf

More Related Content

Similar to 8051 TIMER COUNTER SERIAL COMM. INTERUPT PROGRAMMING.pdf

m.tech esd lab manual for record
m.tech esd lab manual for recordm.tech esd lab manual for record
m.tech esd lab manual for recordG Lemuel George
 
Https _doc-0o-c4-apps-viewer.googleusercontent
Https  _doc-0o-c4-apps-viewer.googleusercontent Https  _doc-0o-c4-apps-viewer.googleusercontent
Https _doc-0o-c4-apps-viewer.googleusercontent vijaydeepakg
 
Library Book Locator
Library Book LocatorLibrary Book Locator
Library Book LocatorArun Joseph
 
Addressing mode and instruction set using 8051
Addressing mode and instruction set using 8051Addressing mode and instruction set using 8051
Addressing mode and instruction set using 8051logesh waran
 
8051 microcontroller
8051 microcontroller8051 microcontroller
8051 microcontrollerjokersclown57
 
Microcontroller 8051- soft.ppt
Microcontroller 8051- soft.pptMicrocontroller 8051- soft.ppt
Microcontroller 8051- soft.pptsteffydean
 
Serial communication in 8051 microcontroller
Serial communication in 8051 microcontrollerSerial communication in 8051 microcontroller
Serial communication in 8051 microcontrollerIshwarNirale2
 
Unit iv microcontrollers final
Unit iv microcontrollers finalUnit iv microcontrollers final
Unit iv microcontrollers finalSARITHA REDDY
 
What will be quantization step size in numbers and in voltage for th.pdf
What will be quantization step size in numbers and in voltage for th.pdfWhat will be quantization step size in numbers and in voltage for th.pdf
What will be quantization step size in numbers and in voltage for th.pdfSIGMATAX1
 
8051 C Assignments with all examples covered
8051 C Assignments with all examples covered8051 C Assignments with all examples covered
8051 C Assignments with all examples coveredAbdulMunaf52
 
8051 microcontroller
8051 microcontroller 8051 microcontroller
8051 microcontroller Gaurav Verma
 

Similar to 8051 TIMER COUNTER SERIAL COMM. INTERUPT PROGRAMMING.pdf (20)

m.tech esd lab manual for record
m.tech esd lab manual for recordm.tech esd lab manual for record
m.tech esd lab manual for record
 
12 mt06ped019
12 mt06ped019 12 mt06ped019
12 mt06ped019
 
8051 serial communication-UART
8051 serial communication-UART8051 serial communication-UART
8051 serial communication-UART
 
Https _doc-0o-c4-apps-viewer.googleusercontent
Https  _doc-0o-c4-apps-viewer.googleusercontent Https  _doc-0o-c4-apps-viewer.googleusercontent
Https _doc-0o-c4-apps-viewer.googleusercontent
 
Library Book Locator
Library Book LocatorLibrary Book Locator
Library Book Locator
 
020419.pdf
020419.pdf020419.pdf
020419.pdf
 
Addressing mode and instruction set using 8051
Addressing mode and instruction set using 8051Addressing mode and instruction set using 8051
Addressing mode and instruction set using 8051
 
Class10
Class10Class10
Class10
 
Jp
Jp Jp
Jp
 
Chapter5 dek3133
Chapter5 dek3133Chapter5 dek3133
Chapter5 dek3133
 
8051 microcontroller
8051 microcontroller8051 microcontroller
8051 microcontroller
 
Em s7 plc
Em s7 plcEm s7 plc
Em s7 plc
 
Microcontroller 8051- soft.ppt
Microcontroller 8051- soft.pptMicrocontroller 8051- soft.ppt
Microcontroller 8051- soft.ppt
 
Serial communication in 8051 microcontroller
Serial communication in 8051 microcontrollerSerial communication in 8051 microcontroller
Serial communication in 8051 microcontroller
 
Unit iv microcontrollers final
Unit iv microcontrollers finalUnit iv microcontrollers final
Unit iv microcontrollers final
 
What will be quantization step size in numbers and in voltage for th.pdf
What will be quantization step size in numbers and in voltage for th.pdfWhat will be quantization step size in numbers and in voltage for th.pdf
What will be quantization step size in numbers and in voltage for th.pdf
 
LCD_Example.pptx
LCD_Example.pptxLCD_Example.pptx
LCD_Example.pptx
 
Microcontroller 8051
Microcontroller 8051Microcontroller 8051
Microcontroller 8051
 
8051 C Assignments with all examples covered
8051 C Assignments with all examples covered8051 C Assignments with all examples covered
8051 C Assignments with all examples covered
 
8051 microcontroller
8051 microcontroller 8051 microcontroller
8051 microcontroller
 

Recently uploaded

CELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptxCELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptxJiesonDelaCerna
 
Hierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementHierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementmkooblal
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatYousafMalik24
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTiammrhaywood
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Educationpboyjonauth
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon AUnboundStockton
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxmanuelaromero2013
 
internship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developerinternship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developerunnathinaik
 
Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...jaredbarbolino94
 
DATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersDATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersSabitha Banu
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxNirmalaLoungPoorunde1
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...Marc Dusseiller Dusjagr
 
Final demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxFinal demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxAvyJaneVismanos
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxpboyjonauth
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Celine George
 
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfEnzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfSumit Tiwari
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdfssuser54595a
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsanshu789521
 

Recently uploaded (20)

CELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptxCELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptx
 
Hierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementHierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of management
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice great
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Education
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon A
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptx
 
internship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developerinternship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developer
 
Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...
 
DATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersDATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginners
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptx
 
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
 
Final demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxFinal demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptx
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptx
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17
 
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfEnzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha elections
 

8051 TIMER COUNTER SERIAL COMM. INTERUPT PROGRAMMING.pdf

  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10. void main(void){ TMOD=0x20; //use Timer 1, mode 2 TH1=0xFD; //9600 baud rate SCON=0x50; TR1=1; //start timer while (1) { SerTx('Y'); SerTx('E'); SerTx('S'); } } void SerTx(unsigned char x){ SBUF=x; //place value in buffer while (TI==0); //wait until transmitted TI=0; }
  • 11. #include<reg51.h> #include<stdio.h> void DelayMs(unsigned int); void serial_init(void); void Transmit(unsigned char); unsigned char Receive(void); void uart_puts(unsigned char *str); unsigned char i,RecDat; code unsigned char x[] ={"Hello world!!!Press a Key:rn"}; void main() { DelayMs(10); serial_init(); DelayMs(10); uart_puts("Hello world!!!Press a Key:rn"); while(1) { uart_puts("You Pressed:"); Transmit(Receive()); uart_puts("nr"); } }
  • 12. unsigned char Receive(void) { while(RI==0); RI = 0; return SBUF; } void uart_puts(unsigned char *str) { while(*str) Transmit(*str++); } void DelayMs(unsigned int val) { int j=0; while(val>0) { val--; for(j=0;j<200;j++); } } void serial_init(void) { SCON = 0x50; TMOD = 0x20; TH1 = 0xFD; //9600 TR1 = 1; TI = 1; } void Transmit(unsigned char dat) { while(TI==0); TI = 0; SBUF = dat; }
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18. 1. Write an 8051 assembly program to transfer data serially at baud rate 9600 with 8 bit data, one stop bit and observe the transmitted data in the serial window of the simulator. org 0000H XX: MOV DPTR,#MYDATA MOV TMOD,#20H MOV TH1,#-3 MOV SCON,#50H SETB TR1 MOV R1,#14 AGAIN:CLR A MOVC A,@A+DPTR MOV SBUF,A HERE: JNB TI,HERE CLR TI INC DPTR DJNZ R1,AGAIN SJMP XX MYDATA: DB 'VIT UNIVERSITY' END
  • 19. 3. Assume that the 8051 serial port is connected to the COM port of IBM PC, P1 and P2 of the 8051 are connected to LEDs and switches, respectively. Assume that XTAL-11.0592Mhz. Write an 8051 assembly program to (a) send to PC the message “We Are Ready”, (b) receive any data send by PC and put it on LEDs connected to P1, and (c) get data on switches connected to P2 and send it to PC serially. 4800 baud rate END
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
  • 27. Write an 8051 program to get data from port P0 and send it to port P1 continuously while an interrupt will do the following: Timer 0 will toggle the P2.1 bit every 200 microseconds. Program number: 1 ORG 0000H LJMP MAIN // Jump to main. ORG 000BH // timer 0 Interrupt vector label CPL P2.1 // Toggle P2.1 pin RETI // Return from ISR ORG 0030H // After Vector Table Space MAIN:MOV TMOD,#02H //set Timer 0 in mode 2 MOV P0,#0FFH // Set P0 an I/P port MOV TH0,#-92 // MOV IE,#10000010B // enable Timer 0 SETB TR0 // Start the Timer BACK:MOV A,P0 // Get data from P0. MOV P1,A // move data P0 to P1 SJMP BACK //Loop it Unless interrupted END
  • 28. Program 2 Assembly Language Write an 8051 program to get data from a single bit of P1.2 and send it to P1.7 continuously while an interrupt will do the following: A serial interrupt service routine will receive data from a PC and display it on P2 ports. ORG 0000H LJMP MAIN ORG 0023H ; ----serial interrupt vector table LJMP SERIAL ORG 0030H ;-- after vector table space MAIN:SETB P1.2 ; -- P1.2 made as input pin MOV TMOD,#00100000B ; -- timer 1 mode 2 MOV TH1,#-3 ;-- set baud rate 9600 MOV SCON ,#01010000B ; -- one stop bit MOV IE,#10010000B ; -- serial int. enabled. SETB TR1 ;-- Timer 1 stared. BACK:MOV C,P1.2 MOV P1.7,C SJMP BACK SERIAL:JB TI,TRANS MOV A,SBUF MOV P2,A CLR RI RETI TRANS:CLR TI RETI END
  • 29. Task Write a 8051 ALP using interrupts to do the following: (a) Receive data serially and sent it to P0, (UART p0) (b) Have P1 port read and transmitted serially, and a copy given to P2, P1 UART P1P2 (c) Make timer 0 mode 1 to generate a square wave of 5 Khz frequency on P3.2. Assume that XTAL-11.0592Mhz. Set the baud rate at 4800.
  • 30. #include <reg51.h> sbit SW =P1^7; sbit IND =P1^0; sbit WAVE =P2^5; void timer0(void) interrupt 1 { WAVE=~WAVE; //toggle pin } void main() { SW=1; //make switch input TMOD=0x02; TH0=0xA4; //TH0=-92 IE=0x82; //enable interrupt for timer 0 while (1) { IND=SW; //send switch to LED } }
  • 31. A) Write an 8051 assembly program to transfer data serially at baud rate 9600 with 8 bit data, one stop bit and observe the transmitted data in the serial window of the simulator. org 0000H XX: MOV DPTR,#MYDATA MOV TMOD,#20H MOV TH1,#-3 MOV SCON,#50H SETB TR1 MOV R1,#14 AGAIN:CLR A MOVC A,@A+DPTR MOV SBUF,A HERE: JNB TI,HERE CLR TI INC DPTR DJNZ R1,AGAIN SJMP XX MYDATA: DB 'VIT UNIVERSITY' END
  • 32. B) Write a 8051 Assembly Language program to get data from the PC and display it on P1. Assume 8051 is connected to PC and observe the incoming characters. As you press a key on the PC's keyboard, the character is sent to the 8051 serially at 4800 baud rate and is displayed on LEDs. The characters displayed on LEDs are in ASCII (binary). ORG 0000H MOV TMOD ,#20H MOV TH1,#-6 MOV SCON,#50H SETB TR1 HERE:JNB RI,HERE MOV A,SBUF MOV P1,A CLR RI SJMP HERE END
  • 33. Assume that the 8051 serial port is connected to the COM port of IBM PC, P1 and P2 of the 8051 are connected to LEDs and switches, respectively. Write an 8051 assembly program to (a) send to PC the message “We Are Ready”, (b) receive any data send by PC and put it on LEDs connected to P1, and (c) get data on switches connected to P2 and send it to PC serially. P2 INPUT UART OUTPUT baud rate 4800
  • 34.
  • 35.
  • 36. Write an 8051 program to get data from a single bit of P1.3 and send it to P1.5 continuously while an interrupt will do the following: A serial interrupt service routine will receive data from a PC and display it on P2 ports. set baud rate 9600 timer 1 mode 2…… Analyse and rectify the errors and specify the output. ORG 0000H LJMP MAIN ORG 0032H ; ----serial interrupt vector table LJMP SERIAL ORG 0030H ;-- after vector table space MAIN:SETB P1.3 ; -- P1.2 made as input pin MOV TMOD,#10H ; -- timer 1 mode 2 MOV TH1,# a4h ;-- set baud rate 9600 MOV SCON ,#50H ; -- one stop bit MOV IE,10010010B ; -- serial int. enabled. SETB TR1 ;-- Timer 1 stared. BACK:MOV C,P1.3 MOV P1.5,C SJMP BACK SERIAL:JNB TI,TRANS MOV A,SBUF MOV P2,A RETI TRANS:CLR TI RETI END
  • 37. Write a program using interrupts to do the following: (a) Receive data serially and sent it to P0, (b) Have P1 port read and transmitted serially, and a copy given to P2, (c) Make timer 0 generate a square wave of 5kHz frequency on P3.2. Assume that XTAL-11.0592. Set the baud rate at 4800. ORG 0H LJMP MAIN ORG 100H MAIN: MOV TMOD,#22H MOV TH1,#-3 SETB TR1 MOV SCON,#50H MOV TH0,#0A4H SETB TR0 MOV IE,#10010010b MOV P1,#0FFH REP:MOV A,P1 MOV SBUF,A MOV P2,A LOOP1:JNB TI,LOOP1 CLR TI SJMP REP ORG 0BH CPL P3.2 RETI ORG 23H MOV A,SBUF MOV P0,A CLR RI RETI END
  • 38.
  • 39.
  • 40.
  • 41.
  • 42.
  • 43.
  • 44.
  • 45.
  • 46.
  • 47.
  • 48.
  • 49.
  • 50.
  • 51.
  • 52.
  • 53. ```
  • 54. Connect the LCD to your 8051 Kit. Then write and run a program to display your name on line 1 of the LCD (first name followed by last name with a space in between). ;P1.0-P1.7 are connected to LCD data pins D0-D7 ;P2.0 is connected to RS pin of LCD ;P2.1 is connected to R/W pin of LCD ;P2.2 is connected to E pin of LCD ORG 0000H MOV A,#38H ACALL CMNWRT ACALL DELAY MOV A,#0EH ACALL CMNWRT ACALL DELAY MOV A,#01H ACALL CMNWRT ACALL DELAY MOV A,#06H ACALL CMNWRT ACALL DELAY MOV A,#80H ACALL CMNWRT ACALL DELAY MOV A,#'V' ACALL DATWRT ACALL DELAY MOV A,#'I' ACALL DATWRT ACALL DELAY MOV A,#'T' ACALL DATWRT ACALL DELAY AGAIN: SJMP AGAIN CMNWRT: MOV P1,A CLR P2.0 CLR P2.1 SETB P2.2 CLR P2.2 RET DATWRT: MOV P1,A SETB P2.0 CLR P2.1 SETB P2.2 CLR P2.2 RET DELAY: MOV R3,#0FFH MOV R4,#0FFH MOV R5,#55H HERE: DJNZ R5,HERE HERE1: DJNZ R4, HERE1 HERE2: DJNZ R3,HERE2 RET END
  • 55.
  • 56.
  • 58.
  • 59. ADC and DAC interfacing Module 7
  • 60.
  • 61.
  • 62.
  • 63.
  • 64.
  • 65.
  • 66.
  • 67.
  • 69. • The digital-to-analog converter (DAC) is a device widely used to convert digital pulses to analog signals. • methods of creating a DAC: binary weighted and R/2R ladder. • The first criterion for judging a DAC is its resolution, which is a function of the number of binary inputs. • The common ones are 8, 10, and 12 bits. • The number of data bit inputs decides the resolution of the DAC since the number of analog output levels is equal to 2″, where n is the number of data bit inputs. Therefore, an 8- input DAC
  • 70. • DAC0808 provides 256 discrete voltage (or current) levels of output. • Similarly, the 12-bit DAC provides 4096 discrete voltage levels. • There are also 16-bit DACs, but they are more expensive.