SlideShare ist ein Scribd-Unternehmen logo
1 von 23
8051 Programming
Assembly language----- includes mnemonics
Example: ADD, SUB, MUL, RR…
Assembly Language-----Assembler---Binary
Disadvantage:
We should know about architecture of microcontroller or
microcontroller
Higher level languages : c ,java
( c, c++,java)------compiler----binary
Advantage:
No need to consider about architecture of µp/µc….just
few features are considered
STEPS FOLLOWED IN CONVERTING SOURCE FILE TO HEX. FILE
EMBEDDED C
DATA TYPES USED IN EMBEDDED C
Integer int x;
Unsigned integer unsigned int x;
Char char x;
Unsigned char unsigned char x;
1) BASIC PORT PROGRAMMING
P0 -------
P0=____________?
MSB LSB
BASIC PORT PROGRAMMING……………………
P0-------
8 4 2 1 8 4 2 1
ANS: P0=0X55
Syntax to be followed:
Pin declaration:
sbit variablename = PX ^Y;
Where,
x=0,1,2,3 port
y=0,1,2,3,4,5,6,7 pins
Example: sbit led = P1^0;
WAP to blink a led which is connected to port2 , pin 0
#include<reg52.h>
sbit led = P2^0;
unsigned int i;
void main()
{
P2=0x00;
led =1;
for(i=0; i<1000; i++);
led =0;
for(i=0; i<1000; i++);
}
Syntax to be followed:
port declaration:
#define variablename Px
Where,
x=0,1,2,3
Example: #define segment P1
WAP to blink all led’s connected to port2
#include<reg52.h>
#define leds P2
unsigned int i;
void main()
{
leds=0x00;
for(i=0; i<1000; i++);
leds =0xFF;
for(i=0; i<1000; i++);
}
INTRODUCTION
TO
KEIL IDE
FOR
80XX PROGRAMMING
PROGRAM 1:
WAP to blink a led which is connected to port1 , pin 0
PROGRAM 2:
WAP to blink the led’s which are connected to port1
PROGRAM 3:
WAP to blink the led’s alternatively which are
connected to port1
Practice examples
pin7 pin6 pin5 pin4 pin3 pin2 pin1 pin0
0 0 0 0 0 0 0 1
0 0 0 0 0 0 1 0
0 0 0 0 0 1 0 0
0 0 0 0 1 0 0 0
0 0 0 1 0 0 0 0
0 0 1 0 0 0 0 0
0 1 0 0 0 0 0 0
1 0 0 0 0 0 0 0
PROGRAM 4:
WAP to shift a bit of port1 from pin0 to pin7
PROGRAM 5:
WAP to shift a bit of port1 from pin7 to pin0
Pin7 pin6 pin5 pin4 pin3 pin2 pin1 pin0
1 0 0 0 0 0 0 0
0 1 0 0 0 0 0 0
0 0 1 0 0 0 0 0
0 0 0 1 0 0 0 0
0 0 0 0 1 0 0 0
0 0 0 0 0 1 0 0
0 0 0 0 0 0 1 0
0 0 0 0 0 0 0 1
PROGRAM 6:
WAP to shift a bit of port1 from pin0 to pin7
pin7 pin6 pin5 pin4 pin3 pin2 pin1 pin0
0 0 0 0 0 0 0 1
0 0 0 0 0 0 1 1
0 0 0 0 0 1 1 1
0 0 0 0 1 1 1 1
0 0 0 1 1 1 1 1
0 0 1 1 1 1 1 1
0 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1
16X2 LCD Display
 8 data pins
3 control pins
supply pins and a potentiometer
1. Two modes
-----Command mode (RS=0)
-----Data mode (RS=1)
2. RW is always logic zero
3. EN=1 to EN=0 for data transfer
LCD INITIALIZATION Using commands
0X38 =========2 lines and 5x7 matrix
0x01 ========= clear the display
0x06 ========= shift cursor to right i.e. increment cursor
0x05 ========= shift display right
0x0E ========= display on, cursor blinking
0x80 ========= force cursor to beginning of first line
0xC0 ========= force cursor to beginning of first line
To pass command to lcd
8datapins = data
RS=0
RW=0
EN=1
Delay()
EN=0
To pass command to lcd
8datapins = data
RS=1
RW=0
EN=1
Delay()
EN=0
void lcd_cmd(unsigned char d)
{
dataport =d;
rs= 0;
rw=0;
e=1;
delay(150);
e=0;
delay(150);
}
void lcd_data(unsigned char f)
{
dataport =f;
rs= 1;
rw=0;
e=1;
delay(150);
e=0;
delay(150);
}
Sample code:
WAP to display your name on LCD
Program6:
#include<reg51.h>
#define dataport P2 // for LCD
void delay(int a);
void lcd_cmd(unsigned char d);
void lcd_data(unsigned char f);
sbit rs =P1^0; // rs pin of LCD
sbit rw =P1^2; // rw pin of LCD
sbit e = P1^1; // enable pin of LCD
void delay(int a)
{
int i;
for(i=0;i<a;i++);
}
void main(void)
{
lcd_cmd(0x38); //function set
delay(50);
lcd_cmd(0x0C); //display on,cursor off,blink off
delay(50);
lcd_cmd(0x80); //first row
delay(50);
lcd_cmd(0x06); //entry mode, set increment
delay(50);
lcd_cmd(0x80); //first row
delay(10);
dataport=0;
P1=0X00;
lcd_data('E');
delay(10);
lcd_data('C');
delay(10);
lcd_data('E');
delay(1500);
}

Weitere ähnliche Inhalte

Was ist angesagt?

Stack and subroutine
Stack and subroutineStack and subroutine
Stack and subroutine
Ashim Saha
 
Chp7 pic 16 f84 interfacing - copy
Chp7 pic 16 f84 interfacing - copyChp7 pic 16 f84 interfacing - copy
Chp7 pic 16 f84 interfacing - copy
mkazree
 
Embedded system (Chapter 2) part 2
Embedded system (Chapter 2) part 2Embedded system (Chapter 2) part 2
Embedded system (Chapter 2) part 2
Ikhwan_Fakrudin
 
Embedded system (Chapter 3) io_port_programming
Embedded system (Chapter 3) io_port_programmingEmbedded system (Chapter 3) io_port_programming
Embedded system (Chapter 3) io_port_programming
Ikhwan_Fakrudin
 
Stack in microprocessor 8085(presantation)
Stack in microprocessor 8085(presantation)Stack in microprocessor 8085(presantation)
Stack in microprocessor 8085(presantation)
Safin Biswas
 

Was ist angesagt? (20)

8051 programming skills using EMBEDDED C
8051 programming skills using EMBEDDED C8051 programming skills using EMBEDDED C
8051 programming skills using EMBEDDED C
 
8051 programming in c
8051 programming in c8051 programming in c
8051 programming in c
 
Stack and subroutine
Stack and subroutineStack and subroutine
Stack and subroutine
 
Class10
Class10Class10
Class10
 
Chapter 9
Chapter 9Chapter 9
Chapter 9
 
Stacks & subroutines 1
Stacks & subroutines 1Stacks & subroutines 1
Stacks & subroutines 1
 
Microprocessor and Microcontroller Lab Manual!
Microprocessor and Microcontroller Lab Manual!Microprocessor and Microcontroller Lab Manual!
Microprocessor and Microcontroller Lab Manual!
 
Class2
Class2Class2
Class2
 
8051 Programming Instruction Set
 8051 Programming Instruction Set 8051 Programming Instruction Set
8051 Programming Instruction Set
 
Chp7 pic 16 f84 interfacing - copy
Chp7 pic 16 f84 interfacing - copyChp7 pic 16 f84 interfacing - copy
Chp7 pic 16 f84 interfacing - copy
 
Microcontrollers 80 Marks Sample Question Paper
Microcontrollers   80 Marks Sample Question PaperMicrocontrollers   80 Marks Sample Question Paper
Microcontrollers 80 Marks Sample Question Paper
 
8051 instruction set
8051 instruction set8051 instruction set
8051 instruction set
 
Uc 2(vii)
Uc 2(vii)Uc 2(vii)
Uc 2(vii)
 
8085 Paper Presentation slides,ppt,microprocessor 8085 ,guide, instruction set
8085 Paper Presentation slides,ppt,microprocessor 8085 ,guide, instruction set8085 Paper Presentation slides,ppt,microprocessor 8085 ,guide, instruction set
8085 Paper Presentation slides,ppt,microprocessor 8085 ,guide, instruction set
 
Embedded system (Chapter 2) part 2
Embedded system (Chapter 2) part 2Embedded system (Chapter 2) part 2
Embedded system (Chapter 2) part 2
 
Embedded system (Chapter 3) io_port_programming
Embedded system (Chapter 3) io_port_programmingEmbedded system (Chapter 3) io_port_programming
Embedded system (Chapter 3) io_port_programming
 
Unit 5 assembly language programming
Unit 5   assembly language programmingUnit 5   assembly language programming
Unit 5 assembly language programming
 
8051assembly language
8051assembly language8051assembly language
8051assembly language
 
8051 Addressing Modes
8051 Addressing Modes8051 Addressing Modes
8051 Addressing Modes
 
Stack in microprocessor 8085(presantation)
Stack in microprocessor 8085(presantation)Stack in microprocessor 8085(presantation)
Stack in microprocessor 8085(presantation)
 

Ähnlich wie 8051 basic programming

Micro controller(pratheesh)
Micro controller(pratheesh)Micro controller(pratheesh)
Micro controller(pratheesh)
Pratheesh Pala
 
Applications of microcontroller(8051)
Applications of microcontroller(8051) Applications of microcontroller(8051)
Applications of microcontroller(8051)
vijaydeepakg
 
Microcontroller
MicrocontrollerMicrocontroller
Microcontroller
Spitiq
 
Moving message display
Moving message displayMoving message display
Moving message display
viraj1989
 
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
 

Ähnlich wie 8051 basic programming (20)

PIC16F877A interfacing with LCD
PIC16F877A interfacing with LCDPIC16F877A interfacing with LCD
PIC16F877A interfacing with LCD
 
W10: Interrupts
W10: InterruptsW10: Interrupts
W10: Interrupts
 
Micro controller(pratheesh)
Micro controller(pratheesh)Micro controller(pratheesh)
Micro controller(pratheesh)
 
Micro c lab6(lcd)
Micro c lab6(lcd)Micro c lab6(lcd)
Micro c lab6(lcd)
 
Buy Embedded Systems Projects Online,Buy B tech Projects Online
Buy Embedded Systems Projects Online,Buy B tech Projects OnlineBuy Embedded Systems Projects Online,Buy B tech Projects Online
Buy Embedded Systems Projects Online,Buy B tech Projects Online
 
Applications of microcontroller(8051)
Applications of microcontroller(8051) Applications of microcontroller(8051)
Applications of microcontroller(8051)
 
PIC introduction + mapping
PIC introduction + mappingPIC introduction + mapping
PIC introduction + mapping
 
LCD_Example.pptx
LCD_Example.pptxLCD_Example.pptx
LCD_Example.pptx
 
Microcontroller
MicrocontrollerMicrocontroller
Microcontroller
 
Moving message display
Moving message displayMoving message display
Moving message display
 
Customizable Microprocessor design on Nexys 3 Spartan FPGA Board
Customizable Microprocessor design on Nexys 3 Spartan FPGA BoardCustomizable Microprocessor design on Nexys 3 Spartan FPGA Board
Customizable Microprocessor design on Nexys 3 Spartan FPGA Board
 
Mpi lab manual eee
Mpi lab manual eeeMpi lab manual eee
Mpi lab manual eee
 
Addressing modes
Addressing modesAddressing modes
Addressing modes
 
Assembler4
Assembler4Assembler4
Assembler4
 
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
 
Microcontroller part 4
Microcontroller part 4Microcontroller part 4
Microcontroller part 4
 
Microcontroller 8051
Microcontroller 8051Microcontroller 8051
Microcontroller 8051
 
Microcontroller 8051- soft.ppt
Microcontroller 8051- soft.pptMicrocontroller 8051- soft.ppt
Microcontroller 8051- soft.ppt
 
Lcd interfacing
Lcd interfacingLcd interfacing
Lcd interfacing
 
Sap 2 OF MICROPROCESSOR
Sap 2 OF MICROPROCESSORSap 2 OF MICROPROCESSOR
Sap 2 OF MICROPROCESSOR
 

Kürzlich hochgeladen

Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak HamilCara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Kandungan 087776558899
 
Standard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power PlayStandard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power Play
Epec Engineered Technologies
 

Kürzlich hochgeladen (20)

Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak HamilCara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
 
data_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdfdata_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdf
 
HAND TOOLS USED AT ELECTRONICS WORK PRESENTED BY KOUSTAV SARKAR
HAND TOOLS USED AT ELECTRONICS WORK PRESENTED BY KOUSTAV SARKARHAND TOOLS USED AT ELECTRONICS WORK PRESENTED BY KOUSTAV SARKAR
HAND TOOLS USED AT ELECTRONICS WORK PRESENTED BY KOUSTAV SARKAR
 
Hazard Identification (HAZID) vs. Hazard and Operability (HAZOP): A Comparati...
Hazard Identification (HAZID) vs. Hazard and Operability (HAZOP): A Comparati...Hazard Identification (HAZID) vs. Hazard and Operability (HAZOP): A Comparati...
Hazard Identification (HAZID) vs. Hazard and Operability (HAZOP): A Comparati...
 
Generative AI or GenAI technology based PPT
Generative AI or GenAI technology based PPTGenerative AI or GenAI technology based PPT
Generative AI or GenAI technology based PPT
 
Employee leave management system project.
Employee leave management system project.Employee leave management system project.
Employee leave management system project.
 
Hostel management system project report..pdf
Hostel management system project report..pdfHostel management system project report..pdf
Hostel management system project report..pdf
 
DC MACHINE-Motoring and generation, Armature circuit equation
DC MACHINE-Motoring and generation, Armature circuit equationDC MACHINE-Motoring and generation, Armature circuit equation
DC MACHINE-Motoring and generation, Armature circuit equation
 
Online food ordering system project report.pdf
Online food ordering system project report.pdfOnline food ordering system project report.pdf
Online food ordering system project report.pdf
 
School management system project Report.pdf
School management system project Report.pdfSchool management system project Report.pdf
School management system project Report.pdf
 
Learn the concepts of Thermodynamics on Magic Marks
Learn the concepts of Thermodynamics on Magic MarksLearn the concepts of Thermodynamics on Magic Marks
Learn the concepts of Thermodynamics on Magic Marks
 
Design For Accessibility: Getting it right from the start
Design For Accessibility: Getting it right from the startDesign For Accessibility: Getting it right from the start
Design For Accessibility: Getting it right from the start
 
Engineering Drawing focus on projection of planes
Engineering Drawing focus on projection of planesEngineering Drawing focus on projection of planes
Engineering Drawing focus on projection of planes
 
2016EF22_0 solar project report rooftop projects
2016EF22_0 solar project report rooftop projects2016EF22_0 solar project report rooftop projects
2016EF22_0 solar project report rooftop projects
 
Standard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power PlayStandard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power Play
 
Block diagram reduction techniques in control systems.ppt
Block diagram reduction techniques in control systems.pptBlock diagram reduction techniques in control systems.ppt
Block diagram reduction techniques in control systems.ppt
 
HOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptx
HOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptxHOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptx
HOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptx
 
Rums floating Omkareshwar FSPV IM_16112021.pdf
Rums floating Omkareshwar FSPV IM_16112021.pdfRums floating Omkareshwar FSPV IM_16112021.pdf
Rums floating Omkareshwar FSPV IM_16112021.pdf
 
Thermal Engineering Unit - I & II . ppt
Thermal Engineering  Unit - I & II . pptThermal Engineering  Unit - I & II . ppt
Thermal Engineering Unit - I & II . ppt
 
S1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptx
S1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptxS1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptx
S1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptx
 

8051 basic programming

  • 2. Assembly language----- includes mnemonics Example: ADD, SUB, MUL, RR… Assembly Language-----Assembler---Binary Disadvantage: We should know about architecture of microcontroller or microcontroller
  • 3. Higher level languages : c ,java ( c, c++,java)------compiler----binary Advantage: No need to consider about architecture of µp/µc….just few features are considered
  • 4. STEPS FOLLOWED IN CONVERTING SOURCE FILE TO HEX. FILE
  • 5. EMBEDDED C DATA TYPES USED IN EMBEDDED C Integer int x; Unsigned integer unsigned int x; Char char x; Unsigned char unsigned char x;
  • 6. 1) BASIC PORT PROGRAMMING P0 ------- P0=____________? MSB LSB
  • 8. Syntax to be followed: Pin declaration: sbit variablename = PX ^Y; Where, x=0,1,2,3 port y=0,1,2,3,4,5,6,7 pins Example: sbit led = P1^0;
  • 9. WAP to blink a led which is connected to port2 , pin 0 #include<reg52.h> sbit led = P2^0; unsigned int i; void main() { P2=0x00; led =1; for(i=0; i<1000; i++); led =0; for(i=0; i<1000; i++); }
  • 10. Syntax to be followed: port declaration: #define variablename Px Where, x=0,1,2,3 Example: #define segment P1
  • 11. WAP to blink all led’s connected to port2 #include<reg52.h> #define leds P2 unsigned int i; void main() { leds=0x00; for(i=0; i<1000; i++); leds =0xFF; for(i=0; i<1000; i++); }
  • 13. PROGRAM 1: WAP to blink a led which is connected to port1 , pin 0 PROGRAM 2: WAP to blink the led’s which are connected to port1 PROGRAM 3: WAP to blink the led’s alternatively which are connected to port1 Practice examples
  • 14. pin7 pin6 pin5 pin4 pin3 pin2 pin1 pin0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 1 0 0 0 0 0 0 1 0 0 0 0 0 0 1 0 0 0 0 0 0 1 0 0 0 0 0 0 1 0 0 0 0 0 0 1 0 0 0 0 0 0 1 0 0 0 0 0 0 0 PROGRAM 4: WAP to shift a bit of port1 from pin0 to pin7
  • 15. PROGRAM 5: WAP to shift a bit of port1 from pin7 to pin0 Pin7 pin6 pin5 pin4 pin3 pin2 pin1 pin0 1 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 1
  • 16. PROGRAM 6: WAP to shift a bit of port1 from pin0 to pin7 pin7 pin6 pin5 pin4 pin3 pin2 pin1 pin0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 1 1 0 0 0 0 0 1 1 1 0 0 0 0 1 1 1 1 0 0 0 1 1 1 1 1 0 0 1 1 1 1 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
  • 18.  8 data pins 3 control pins supply pins and a potentiometer 1. Two modes -----Command mode (RS=0) -----Data mode (RS=1) 2. RW is always logic zero 3. EN=1 to EN=0 for data transfer
  • 19. LCD INITIALIZATION Using commands 0X38 =========2 lines and 5x7 matrix 0x01 ========= clear the display 0x06 ========= shift cursor to right i.e. increment cursor 0x05 ========= shift display right 0x0E ========= display on, cursor blinking 0x80 ========= force cursor to beginning of first line 0xC0 ========= force cursor to beginning of first line
  • 20. To pass command to lcd 8datapins = data RS=0 RW=0 EN=1 Delay() EN=0 To pass command to lcd 8datapins = data RS=1 RW=0 EN=1 Delay() EN=0
  • 21. void lcd_cmd(unsigned char d) { dataport =d; rs= 0; rw=0; e=1; delay(150); e=0; delay(150); } void lcd_data(unsigned char f) { dataport =f; rs= 1; rw=0; e=1; delay(150); e=0; delay(150); } Sample code:
  • 22. WAP to display your name on LCD Program6: #include<reg51.h> #define dataport P2 // for LCD void delay(int a); void lcd_cmd(unsigned char d); void lcd_data(unsigned char f); sbit rs =P1^0; // rs pin of LCD sbit rw =P1^2; // rw pin of LCD sbit e = P1^1; // enable pin of LCD void delay(int a) { int i; for(i=0;i<a;i++); }
  • 23. void main(void) { lcd_cmd(0x38); //function set delay(50); lcd_cmd(0x0C); //display on,cursor off,blink off delay(50); lcd_cmd(0x80); //first row delay(50); lcd_cmd(0x06); //entry mode, set increment delay(50); lcd_cmd(0x80); //first row delay(10); dataport=0; P1=0X00; lcd_data('E'); delay(10); lcd_data('C'); delay(10); lcd_data('E'); delay(1500); }