Tuesday, January 7, 2014

555 timer IC Inverter 12V to 220V

1 comment:
This article explains What is inverter? And how can you construct your own simple low cost 12V to 220V inverter circuit. An inverter is nothing but a DC to AC converter. Inverters are very useful electronics products for compensating emergency power failure, as it performs DC to AC conversion.
CBZ4DUQZD2JF
AC can’t be stored for future use but DC can be stored for future use in a battery. The stored DC can be converted back to AC by using power inverters.
Here is the simple inverter circuit diagram using 555 timer IC. The astable multivibrator mode operation of 555 timer utilized here for AC oscillations and these oscillations are switched via transistor 2SC4029 to a transformer. The transformer step ups the voltage to 220V AC. Use a 12V battery and Battery charger circuit for this project. Design of inverter circuit is also given. 

Circuit diagram of DC to AC inverter


Components required

  1. Power supply (12V)
  2. Resistors (3kΩ x 2; 1kΩ, 2W x 1)
  3. Capacitor (10µF)
  4. 555 timer IC
  5. Diode(1N4007)
  6. Transistor (2SC4029)
  7. 9V to 220V Step up transformer

Working of DC to AC inverter

  • This is a simple inverter circuit based on 555 timer IC. Here timer IC wired as an astable multivibrator mode.
  • The diode 1N4007 is used to get 50% duty cycle for the pulses from 555, it also reduces the design complexity.
  • The output pulse from the 555 astable multivibrator is fed to the base of power transistor 2N5192. The 2N5192 transistor works as a switch, so the 12V DC supply passed through the transformer at a rate of 50 times per second.
  • Transformer step up the 12V to 220V, thus we got 50Hz, 220VAC supply at the output of transformer secondary.

Design of Inverter circuit

555 timer Astable designed about to oscillate at 50Hz, line frequency.
Frequency of astable multivibrator is given by,
Choose C=10µF, then
Use R1=R=3kΩ 

El




******Related Topic ******



Simple Inverter

No comments:
Have you ever wanted to run a TV, stereo or other appliance while on the road or camping? Well, this inverter should solve that problem. It takes 12 VDC and steps it up to 120 VAC. The wattage depends on which tansistors you use for Q1 and Q2, as well as how "big" a transformer you use for T1. The inverter can be constructed to supply anywhere from 1 to 1000 (1 KW) watts. 
C1, C2    2              68 uf, 25 V Tantalum Capacitor  
R1, R2    2              10 Ohm, 5 Watt Resistor              
R3, R4    2              180 Ohm, 1 Watt Resistor            
D1, D2   2              HEP 154 Silicon Diode    
Q1, Q2  2              2N3055 NPN Transistor (see "Notes")    
T1           1              24V, Center Tapped Transformer (see "Notes")               
MISC     1              Wire, Case, Receptical (For Output)         



  1. Q1 and Q2, as well as T1, determine how much wattage the inverter can supply. With Q1,Q2=2N3055 and T1= 15 A, the inverter can supply about 300 watts. Larger transformers and more powerful transistors can be substituted for T1, Q1 and Q2 for more power.
  2. The easiest and least expensive way to get a large T1 is to re-wind an old microwave transformer. These transformers are rated at about 1KW and are perfect. Go to a local TV repair shop and dig through the dumpster until you get the largest microwave you can find. The bigger the microwave the bigger transformer. Remove the transformer, being careful not to touch the large high voltage capacitor that might still be charged. If you want, you can test the transformer, but they are usually still good. Now, remove the old 2000 V secondary, being careful not to damage the primary. Leave the primary in tact. Now, wind on 12 turns of wire, twist a loop (center tap), and wind on 12 more turns. The guage of the wire will depend on how much current you plan to have the transformer supply. Enamel covered magnet wire works great for this. Now secure the windings with tape. Thats all there is to it. Remember to use high current transistors for Q1 and Q2. The 2N3055's in the parts list can only handle 15 amps each.
  3. Remember, when operating at high wattages, this circuit draws huge amounts of current. Don't let your battery go dead :-).
  4. Since this project produces 120 VAC, you must include a fuse and build the project in a case.
  5. You must use tantalum capacitors for C1 and C2. Regular electrolytics will overheat and explode. And yes, 68uF is the correct value. There are no substitutions.
  6. This circuit can be tricky to get going. Differences in transformers, transistors, parts substitutions or anything else not on this page may cause it to not function.
  7. If you want to make 220/240 VAC instead of 120 VAC, you need a transformer with a 220/240 primary (used as the secondary in this circuit as the transformer is backwards) instead of the 120V unit specified here. The rest of the circuit stays the same. But it takes twice the current at 12V to produce 240V as it does 120V. 
  8. Electronics Lab Created By Muhammad Irfan
                                                  



Friday, January 3, 2014

Difference between Microcontroller and Microprocessor

1 comment:

The microprocessor is a chip which has only the CPU and Control Unit inside it. But microprocessor does not 

has any built-in Memory,RAM,IO Ports,Timers,Serial Ports etc. So these parts need to be connected from 

outside with the microprocessor. Some examples of microprocessors are our PC processors , Processors used 

in our mobiles,Gadgets etc. 

 

 

 

 

 

The microcontroller has some common features with microprocessor but it differs from it in many aspects. The 

microcontroller has built-in ROM,RAM,IO ports,Timers,Serial Ports etc. As the microcontroller has all those 

parts embedded in it so it requires less hardware to build a complete system,which is an advantage of 

microcontroller. Some commercially available microcontrollers are DS1804Z- 

010,MAX5391MATE+T,MAX5391NATE+T,TPL0401B-10DCKR , MCP41050-I/P . 

The microprocessor stores program and data in same memory but microcontroller stores program and data in 

different memory.

 

 

 

 

Now you are thinking that if microcontroller has all the required hardwares in a single chip and they saves 

system space so why someone will use microprocessor. The microcontroller has few amount of built-in ROM 

and RAM . If you go for an expensive microcontorller then you will get hardly 1mb of ROM and RAM. But as you 

can connect external RAM and ROM with microprocessor so microprocessor based system can have huge 

RAM and ROM.

 

 

 

The highest frequency microcontroller available in the market is 400 MHZ - 800 MHZ. So for high speed 

operations microcontollers are not suitable. But the microprocessor can run up to few GHZ range. 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Electronics Lab created By Muhammad Irfan

Arduino Tre vs. Raspberry Pi Model B – 5 major differences

No comments:
 Arduino Tre vs. Raspberry Pi Model B – 5 major differences


Comparing the Arduino Tre with the Raspberry Pi is the subject of this article, and we have to specify that the comparison is based on the preliminary specifications of the Arduino Tre. In the following, you can discover up to five major differences between the Tre and Pi.



The most important difference between Tre and Pi are:
  • Arduino Tre has three microcontrollers dedicated for real-time applications;
  • one USB 2.0 device port and 4 USB 2.0 host ports are available for Tre board, while the Pi has two USB 2.0 host ports;
  • Tre has an on-board LCD expansion interface, while the Pi requires an expansion shield for LCD screens;
  • the processor of the Tre has a clock speed of 1 GHz, while the Pi processor has a clock speed of 700 MHz;
  • both electronic boards support different programming languages;
Arduino Tre vs. Raspberry Pi Model B
Arduino Tre vs. Raspberry Pi Model B
Arduino Tre Raspberry Pi Model B
Processor 1 GHz – Texas Instrument Sitara AM3359AZCZ100 (ARM Cortex-A8) 700 MHz – ARM1176JZ-F Applications Processor
Microcontroller 3x PRU 32-bit microcontrollers
Memory 512MB DDR3L 512MB SDRAM
Digital I/O Pins 14(5V logic) + 12 (3.3V logic) 26-pin from which 8 GPIO (3.3V logic)
Networking Ethernet 10/100 Ethernet 10/100
USB ports 1 USB 2.0 device port, 4 USB 2.0 host ports 2 USB 2.0 host ports
Video Output HDMI (1920×1080) HDMI (1920×1200)
Audio Output HDMI HDMI
MicroSD card Yes Yes
Software Linux Linux
Programming languages C, C++ Python, Java
Android support ? Yes
Power 5V 5V
Dimensions ? 85.60mm x 56mm x 21mm

What is an Arduino Tre?

Arduino is above of all a community of engineers, hobbyists, or students around open source hardware platforms that comes in different versions. The first board was released in 2005 aiming to simplify the process of prototyping DIY electronic devices. Since then, few Arduino boards were released with significant improvements, but the biggest improvement for an Arduino board will be in 2014 when the Arduino Tre is planned to be released.
Arduino Tre will be the most powerful Arduino board, a mini computer with realistic features to run a full version of Linux. The Tre will be the first electronic Arduino board manufactured in the U.S., and the main reason is that the electronic device is the result of collaboration with BeagleBoard.org foundation.
The Arduino Tre is designed to encapsulate the experience and benefits of both Arduino and BeagleBoard communities, and this makes the technology more accessible to engineers, designers, students, or hobbyists.
Integrating a processor with 100 times more performance than any other Arduino boards, the Arduino Tre is able to run desktop applications, complex algorithms or to maintain high-speed communications.

What is a Raspberry Pi?

The Raspberry Pi was sold over time in more than 2 million exemplars, a remarkable number for a tiny electronic board with high performances and a price of about US $35.
This minicomputer is a powerful and inexpensive device for engineers, designers, students, or hobbyists involved in DIY projects or try to learn programming and building wonderful robotic applications.
Like Arduino boards, the Raspberry Pi was designed to be used especially in education, and also is a platform based on Linux and opened to write your own software to run on it.
The device comes in two models called A and B. Between the two models are small differences including here 512MB RAM for model B instead 256MB RAM of model A, 2 USB ports for model B instead only one USB port for model A, and no Ethernet connectivity for model A.
As a conclusion, the Raspberry Pi is a cheap, flexible and opened for experimentation minicomputer that can be useful for a large area of DIY projects.

Measures

The dimensions of the Arduino Tre are not listed, while the Raspberry Pi Model B measures are 85.60mm x 56mm x 21mm, which define a little electronic board. Based on the idea that the Arduino Tre is based on an Arduino and BeagleBoard boards, we suppose that this will keep the same measures.

Graphics

Arduino Tre – in this section the most important feature is the HDMI support, which means that the board can be used in several applications for digital or analog TV. The maximum resolution supported by the Tre for video files is 1920×1080 pixels. Any data could be displayed on an LCD screen due to the LCD expansion interface.
Raspberry Pi Model B – the Pi model B has also HDMI support, while for VGA support is required to use an adaptor. To display images on an LCD screen it is also required to use an LCD expansion shield for Raspberry Pi.

Audio

Arduino Tre – the board has HDMI support and stereo analog audio I/O.
Raspberry Pi Model B – it has also HDMI supported and for output uses a standard 3.5mm jack.

Power

Arduino Tre – the board requires a 5V power jack to run.
Raspberry Pi Model B – the Pi board requires the same voltage as Tre – 5V.

Hardware

Arduino Tre – the Tre is based on ARM Cortex-A8 processor by Texas Instrument Sitara with 1 GHz clock speed and 512MB RAM DDR3. A plus compared with Raspberry Pi Model B is that the Tre dedicated microcontrollers for real-time applications.
Raspberry Pi Model B – the B model is based on a low power ARM1176JZ-F processor with a working frequency of 700 MHz and 512MB of SDRAM.

Software

Arduino Tre – it is expected to use the same Arduino IDE written in Java and with support for C or C++ programming language. The operating system that runs on Tre is a full version of Linux.
Raspberry Pi Model B – it is recommended to run on Pi the Linux Debian OS version, while for programming its support Python or Java. Compared with Tre, the Pi can run a customized version of Android, while for Tre we just can suppose that the device can run also the Android OS.

Storage

Arduino Tre – it supports SD cards, but we don’t have any information about the maximum capacity of the memory card supported.
Raspberry Pi Model B – this minicomputer support memory card with up to 32GB memory space, while it is recommended to be used a card with at least 4GB space for storage.

Networking, USB and Wireless

Arduino Tre – the electronic board includes 10/100 wired Ethernet, and an increased number of USB ports are available.
Raspberry Pi Model B – the device has also support for 10/100 wired Ethernet, and dual USB connector.



******Related Topics *****




 Electronics Lab Created By Muhammad Irfan

Thursday, January 2, 2014

Ultrasonic range finder using 8051

2 comments:

Ultrasonic range finder using 8051

Ultrasonic range finder using 8051 .

A simple ultrasonic range finder using 8051 microcontroller is presented in this article. This ultrasonic rangefinder can measure distances up to  2.5 meters at an accuracy of 1 centi meter. AT89s51 microcontroller and the ultrasonic transducer module HC-SR04 forms the basis of this circuit. The ultrasonic module sends a signal to the object, then picks up its echo and outputs a wave form whose time period is proportional to the distance. The microcontroller accepts this signal, performs necessary processing and displays the corresponding distance on the 3 digit seven segment display. This circuit finds a lot of application in projects like automotive parking sensors, obstacle warning systems, terrain monitoring robots, industrial distance measurements etc.

HC-SR04 ultrasonic module.

HC-SR04 is an  ultrasonic ranging module designed for embedded system projects like this. It has a resolution of 0.3cm and the ranging distance is from 2cm to 500cm. It operates from a 5V DC supply and the standby current is less than 2mA. The module transmits an ultrasonic signal, picks up its echo, measures the time elapsed between the two events and outputs a waveform whose high time is modulated by the measured time which is proportional to the distance.  .The photograph of an HC-SR04 module is shown below.



The supporting circuits fabricated on the module makes it almost stand alone and what the programmer need to do is to send a trigger signal to it  for initiating transmission and receive the echo signal from it for distance calculation. The HR-SR04 has four pins namely Vcc, Trigger, Echo, GND and they are explained in detail below.
1) VCC : 5V DC supply voltage is connected to this pin.
2) Trigger: The trigger signal for starting the transmission is given to this pin. The trigger signal must be a pulse with 10uS high time. When the module receives a valid trigger signal it issues 8 pulses of 40KHz ultrasonic sound from the transmitter. The echo of this sound is picked by the receiver.
3)Echo: At this pin, the  module outputs a waveform with high time proportional to the distance.
4) GND: Ground is connected to this pin.
HC-SR04 timing diagram.


From the timing diagram, you can see that the 40KHz pulse train is transmitted just after the 10uS triggering pulse and the  echo output is obtained after some more time. The next triggering pulse can be given only after the echo is faded away and this time period is called cycle period. The cycle period for HC-SR04 must not be below 50mS. According to datasheet, the distance can be calculated from the echo pulse width using the following equations.
Distance in cm = echo pulse width in uS/58
Distance in inch = echo pulse width in uS/148

Ultrasonic range finder using 8051- Circuit diagram.





The ultrasonic module is interfaced to the microcontroller through P3.0 and P3.1 pins. Port0 used for transmitting the 8 bit display data to the display and port pins P1.0, P1.1, P1.2 are used for transmitting display drive signals for the corresponding display units D1, D2, D3. Push button switch S1, capacitor C3 and resistor R9 forms a de-bouncing reset circuitry. Capacitors C1,C2 and crystal X1 are associated with the clock circuit.

Program.

ORG 00H                // origin
MOV DPTR,#LUT          // moves the address of LUT to DPTR
MOV P1,#00000000B      // sets P1 as output port
MOV P0,#00000000B      // sets P0 as output port
CLR P3.0               // sets P3.0 as output for sending trigger
SETB P3.1              // sets P3.1 as input for receiving echo
MOV TMOD,#00100000B    // sets timer1 as mode 2 auto reload timer
MAIN: MOV TL1,#207D    // loads the initial value to start counting from
      MOV TH1,#207D    // loads the reload value
      MOV A,#00000000B // clears accumulator
      SETB P3.0        // starts the trigger pulse
      ACALL DELAY1     // gives 10uS width for the trigger pulse
      CLR P3.0         // ends the trigger pulse
HERE: JNB P3.1,HERE    // loops here until echo is received
BACK: SETB TR1         // starts the timer1
HERE1: JNB TF1,HERE1   // loops here until timer overflows (ie;48 count)
      CLR TR1          // stops the timer
      CLR TF1          // clears timer flag 1
      INC A            // increments A for every timer1 overflow
      JB P3.1,BACK     // jumps to BACK if echo is still available
      MOV R4,A         // saves the value of A to R4
      ACALL DLOOP      // calls the display loop
      SJMP MAIN        // jumps to MAIN loop

DELAY1: MOV R6,#2D     // 10uS delay
LABEL1: DJNZ R6,LABEL1
        RET     

DLOOP: MOV R5,#100D    // loads R5 with 100D
BACK1: MOV A,R4        // loads the value in R4 to A
       MOV B,#100D     // loads B with 100D
       DIV AB          // isolates the first digit
       SETB P1.0       // activates LED display unit D1
       ACALL DISPLAY   // calls DISPLAY subroutine
       MOV P0,A        // moves digit drive pattern for 1st digit to P0
       ACALL DELAY     // 1mS delay
       ACALL DELAY
       MOV A,B         // moves the remainder of 1st division to A
       MOV B,#10D      // loads B with 10D
       DIV AB          // isolates the second digit
       CLR P1.0        // deactivates LED display unit D1
       SETB P1.1       // activates LED display unit D2
       ACALL DISPLAY
       MOV P0,A        // moves digit drive pattern for 2nd digit to P0
       ACALL DELAY
       ACALL DELAY
       MOV A,B         // moves the remainder of 2nd division to A
       CLR P1.1        // deactivates LED display unit D2
       SETB P1.2       // activates LED display unit D3
       ACALL DISPLAY
       MOV P0,A     // moves the digit drive pattern for 3rd digit to P0
       ACALL DELAY
       ACALL DELAY
       CLR P1.2       // deactivates LED display unit D3
       DJNZ R5,BACK1  // repeats the display loop 100 times
       RET

DELAY: MOV R7,#250D        // 1mS delay
LABEL2: DJNZ R7,LABEL2
        RET

DISPLAY: MOVC A,@A+DPTR // gets the digit drive pattern for the content in A
         CPL A          // complements the digit drive pattern (see Note 1)
         RET
LUT: DB 3FH               // look up table (LUT) starts here
     DB 06H
     DB 5BH
     DB 4FH
     DB 66H
     DB 6DH
     DB 7DH
     DB 07H
     DB 7FH
     DB 6FH
END

About the program.

The first part of the program sets the initial conditions. Port 0 and P0rt 1 are set as output ports for sending digit drive patterns and digit drive signals respectively. Port pin 3.0 is set as an output pin for sending the trigger signal to the ultrasonic module for starting transmission and port pin 3.1 is set as an input pin for receiving the echo. TMOD register of the microcontroller is so loaded that the Timer 1 operates in mode2 8 bit auto-reload mode. Timer 0 of the microcontroller is not used here. In the next part of the program (loop MAIN) the TL1 and TH1 registers of Timer1 are loaded with the initial values. TL1 is loaded with the initial value to start counting from and TH1 is loaded with the reload value. This is how timer 1 in mode 2 works: When TR1 bit of the TCON register is set the TL1 starts counting from the initial value loaded into it and keeps counting untill roll over (ie; 255D). When roll over occurs, TF1 flag is set and TL1 is automatically loaded with the reload value stored in TH1 and the sequence is repeated until TR1 is made low by the program. The TF1 goes high at the first roll over and if you want it as an indicator for each roll over,  you have to clear it using the program  after each roll over. In the next part of the MAIN loop P3.0 is set high for 10uS and then cleared to make 10uS triggering pulse. The ultrasonic module issues a 40Khz pulse wave form after receiving this trigger and the program waits until a valid echo is received at P3.1. The pulse width of the echo signal is proportional to the distance to the obstacle and so the next job of the program is to measure the pulse width. Whenever there is a valid echo pulse at P3.1, the Timer1 starts and it counts from the initial value to 255 ie: 255-207= 48 counts. Then the counter restarts and accumulator increments by one for every restart. This sequence is repeated until the echo signal at P3.1 vanishes (ie; P3.1 goes low). Now the content in A will be equal to the number of  Timer1 reloads which is in fact proportional to the distance. From the datasheet it is clear that 58uS echo pulse width indicates 1cM distance. When the processor is clocked by a 12MHz crystal, 58 counts of Timer1 indicates 1cM. That means 1 reload is equal to 1cM. But here we are letting the Timer1 to count only 48 times before reload and this is done in order to compensate for the time lags caused by the branching instructions used for checking the status of P3.0 and P3.1 pins. If this trick is not done, the individual time lags caused by the branching instructions will be cumilatively added to the observed pulse width and the range finder will show a reading higher than the original distance. Some trial and error was required for getting the correct Timer1 reload value and with the 207D  (ie; 48 counts) used here the error was found to be less than half a centimeter which  is quite fine in this context. The next part of the program does necessary mathematics on the current content in A and displays it as 3 digit readout on the display.

Notes.

1) The LUT used here was originally made for a common cathode seven segment display and here we are using common anode displays. The CPL A instruction will just complement the obtained digit drive pattern and make is suitable for the common anode scheme. If you have time ,then cook up an LUT for common anode scheme and replace the current one using it. By this  you can avoid the extra CPL A instruction and it is the correct method.
2)The entire circuit can be powered from 5V DC.
3) Be careful while handling the Ultrasonic module. There are a lot of sensitive surface mount devices fabricated on its back side.



 







Electronics Lab Created By Muhammad Irfan

Thursday, December 26, 2013

8051 Programming Tutorial

No comments:

8051 Programming Tutorial

 

This article series is developed to teach you 8051 micro controller programming. I have divided this programming tutorial into a series of chapters as shown below. So you can start with Chapter 1 and then move to chapter 2 and chapter 3 and so on. So let’s begin the journey right now! 
Note: Next chapters 1,2,3.. are under development phase. Please visit this page again for updates.
Note: To test any of these program or to write one your own and test, you dont need to buy a microcontroller board now. You can test your program using an 8051 simulator. Here is a big list of 8051 simulators available. In the beginning try the first one given in the list, Edsim51. Its an easy to use tool. 
To program any microcontroller available in this world, first you need to learn and understand it’s instruction sets. Instruction set contains a set of instructions that is available for the programmer to create any kind of program he likes. Or in another way, using the instruction set a programmer can create the program required for the specific application he is making. So first of all one needs to master all available instructions, how an instruction works, how the execution of an instruction affects the microcontroller (affecting the registers, psw, stack etc) and the way it is used in a program. Once the instruction set is mastered, you can start playing with programs. Before getting into programming, there are some prerequisites. If you are really new to micro controller and if 8051 is the first one you are playing with, please read the following articles first.
1. Difference between Microprocessor and Micro controller
2. Basics of 8051 Microcontroller – Pin diagram – Architecture – Memory Organization
3. Addressing modes of 8051 You must read this article before writing any program for 8051 as this documents the root of instruction handling.
4.  8051 Special Function Registers and I/O Ports
Now lets come to instruction sets of 8051 micro controller.  The 8051 instruction set can be classified as shown below.
  • Instructions for data transfer/ data move
  • Instructions for arithmetic operations
  • Instructions for branching a program
  • Instruction for creating subroutines
  • Instructions for logical operations
  • Instructions for boolean operations 
  • Special purpose instructions
Follow the given link, where you can access the complete list of instructions for 8051 micro controller – 8051 Instruction Set  (see the heading Alphabetical order below first table).
Note:- 8051 micro controller belongs to the MCS-51 family of micro controllers.  This basically means,any 8051 variant micro controller (that comes under the MCS-51 family) made by any other manufacturer must use the same set of instructions made for MCS-51. So the “instruction decoder” part of all micro controllers under MCS-51 family is same. Example: Atmels AT89c2051 is one such micro controller that falls under MCS-51 family. So a program written for Intel 8051 can be used to run AT89C2051 too (you may have to make slight modifications to match hardware disparities).

1. Instructions for data transfer includes – MOV, MOVC, MOVX, PUSH, POP, XCH, XCHD
2.Instructions for arithmetic operations are – ADD, ADDC, SUBB, MUL, DIV, INC, DEC, DA A
3. Instructions for branching and subroutines – LJMP, AJMP, SJMP, LCALL, ACALL, JZ, JNZ, CJNE, DJNZ, JMP, NOP, RET, RETI
4. Instructions for logical operations – ANL, ORL, XRL, CLR, CPL, RL, RLC, RR, RRC, SWAP
5. Instructions for boolean variable operations – SETB, MOV, CLR, JB, JNB, JBC, ANL, ORL, CPL, JC, JNC
6. Special purpose instructions involves – MOVC, MOVX, SWAP, XCH, XCHD, JBC, RETI, DA A
You may learn about all instructions in detail by following that link given above. There are 44 instructions in 8051 or MCS-51 instruction set.
I assume you have gone through data transfer/arithmetic/branching and subroutine instructions by now. Now lets write a very simple program.

A program to find sum of N natural numbers and store the sum


Program description:-

  The number “N” is stored in location 35H. Natural numbers generated from 0 to N must be stored from location 55H. The sum of natural numbers must be stored in location 36H.
Analyzing the program description, we need 3 registers. R0 to store the value of “N”  (given in location 35H)and to act as a counter for generating natural numbers upto N. R5 is used to save the value of first storage location of natural numbers and then R5 is incremented by one each to store each newly generated natural number. R7 is initiated as 0 and is incremented by 1 to generate natural numbers.

The Program:-

MOV PSW, #00H // Register bank '0' is selected by executing this instruction.
MOV R0, 35H // The value of 'N' stored in location 35H is transfered to R0.
MOV R5, #55H// The starting location for storing natural numbers '#55H' is transfered to R5
MOV A, #00H// Accumulator is initiated with value 0 for adding natural numbers cumulatively.
MOV R7, #00H// R7 is initialized to '0' to generate natural numbers. Note: '0' is not a natural number.
LOOP: INC R7// R7 is incremented by 1 to generate next natural number.
MOV @R5, 07H// This is indirect addressing mode used here.It is not possible to transfer data from one register to another register directly. So an instruction like MOV R5, R7 is invalid.Instead we use the direct address (07) of register R7 of register bank #00 to transfer the generated natural number to it's storage location in register R5.Indirect addressing is used as we need to save the generated natural number directly to memory address. R5 holds the starting location address (of the storage area) as its value i.e #55H.By indirectly addressing, we can save what ever value in R7 directly to location #55H.
INC R5// The storage location is incremented by 1 from #55H to #56H to store the next generated natural number
ADD A, R7// The generated natural number is added to contents in accumulator.
DJNZ R0, LOOP// The value of register Ro (value of 'N') is decremented by 1. It is checked against stopping condition zero. If its R0 is not equal to zero, the program control will move to label LOOP again and the steps from INC R7 will be executed again until R0 is equal to zero. When R0 is equal to zero, program control will exit the loop and move to next instruction given below.
MOV 36H,A// The sum of natural numbers in accumulator is moved to storage location 36H.
STOP: SJMP STOP// An infinite loop written at the end of the program. When this instruction is reached program control will get stuck at this instruction as it's an infinite loop.To get out of this infinite loop system reset must be applied.

 

A simple program to copy a block of data from one location to another

Program Description:-

10 bytes of data stored from 30H is to be copied to another location staring from 50H.
Analyzing the program, we see, we need two registers to store starting locations of source and destination. Lets say we take R0 as the source and R2 as the destination registers. Now we need a counter to count 10 bytes of data transfered from source to destination. Lets take R3 for that. It is not possible to transfer data from one register to another register directly by using any kind of addressing mode. So we need accumulator to stand in between as a temporary register. So here is it:

The Program:

MOV R0,#30H // Address of the starting location of source data is moved to R0.
MOV R1,#50H // Address of the starting location of destination is moved to R1
MOV R3,#OAH// Set the counter R3 with 10. You can also use decimal number as MOV R3,#10d.
LOOP: MOV A, @R0// Indirect addressing mode is used. Contents at the location of Ro (30H) is copied to accumulator.
MOV @R1, A// Contents in accumulator is copied to location pointed by Ra (that is 50H).
INC R0 // Ro is incremented by 1 to point to next location.
INC R1// R1 is incremented by 1 to point to next location.
DJNZ R3, LOOP // Counter register R3 is decremented by 1 and checked against zero. See the explanation DJNZ in the first program "sum of natural numbers"
STOP: SJMP STOP // Infinite loop to terminate programh



 

 

The Program:- 

BEGIN: MOV R1,30H // Getting the value of "N"
MOV R7,#40H // The first number '0' of series is stored here.
MOV @R7,#00H // Loading value 'o' to address 40H using indirect addressing
INC R7 // Incrementing value of R7 from 40H to 41H to store next number '1'
MOV @R7, #01H // Storing value '1' to location 41H. Note that 'o' and '1' are seed values of a fibonacci series and has to be generated manually.
MOV R5,#42H // New register R5 is loaded with location address 42H to store next values of series, generated by adding the 2 previously generated numbers.
DEC R1
DEC R1 // The count value "N" is decremented by 2, as we have already generated and stored 1st two numbers.
DEC R7 // R7 is now reduced from 41H to 40H. We need to add contents of 40H and 41 H to get the number that is to be stored in 42H.
LOOP: MOV A, @R7 // Contents in R7 is moved to accumulator.
INC R7 // R7 is incremented to get the next value.
ADD A,@R7 // The two values are added and stored in Acc.
MOV @R5,A // The newly generated value of the series is stored in the address held by R5.
INC R5 // R5 is incremented to store next value.
DJNZ R1,LOOP // The count "N" is checked to zero (to know if all the numbers upto N are generated).
STOP: SJMP STOP // Run infinitely here or end of program execution. 


 These 3 programs will be enough for a “kick start” in 8051 programming. More programs and concepts will be explained in upcoming articles. I recommend you to download Edsim51 simulator (or any other one you prefer) and try out these programs. Make changes to these codes and write simple codes based on your ideas – like Multiplying 2 numbers, Generating a particular series, Arithmetic calculator etc. Only by doing yourself, you can master the art of programming!

Electronics Lab Created By Muhammad Irfan
 

8051 Microcontroller/8051 Microcontroller Architecture

No comments:

8051 Microcontroller/8051 Microcontroller Architecture

A micro controller is an integrated circuit or a chip with a processor and other support devices like program memory, data memory, I/O ports, serial communication interface etc integrated together. Unlike a microprocessor (ex: Intel 8085), a microcontroller does not require any external interfacing of support devices. Intel 8051 is the most popular microcontroller ever produced in the world market. Now lets talk about 8051 microcontroller in detail.
Before going further, it will be interesting for you to understand the difference between a Microprocessor and Microcontroller. We have a detailed article which describes the basic difference between both.


Here is a Quick Access to various sections of this article:-



Introduction

Intel first produced a microcontroller in 1976 under the name MCS-48, which was an 8 bit microcontroller. Later in 1980 they released a further improved version (which is also 8 bit), under the name MCS-51. The most popular microcontroller 8051 belongs to the MCS-51 family of microcontrollers by Intel. Following the success of 8051, many other semiconductor manufacturers released microcontrollers under their own brand name but using the MCS-51 core. Global companies and giants in semiconductor industry like Microchip, Zilog, Atmel, Philips, Siemens released products under their brand name. The specialty was  that all these devices could be programmed using the same MCS-51 instruction sets. They basically differed in support device configurations like improved memory, presence of an ADC or DAC etc. Intel then released its first 16 bit microcontroller in 1982, under name MCS-96

8051 Microcontroller Packaging

There is no need of explaining what each package means, you already know it. So I will skim through mainly used packaging for 8051. See, availability of various packages change from device to device. The most commonly used is Dual Inline Package (40 pins) – known popularly as DIP. 8051 is also available in QFP (Quad Flat Package), TQFP (Thin Quad Flat Package), PQFP (Plastic Quad Flat Package) etc. For explaining the pin diagram, we have used a 40 pin DIP IC as model.

8051 Microcontroller Architecture

Its possible to explain microcontroller architecture to a great detail, but we are limiting scope of this article to internal architecture, pin configuration, program memory and data memory organization. The basic architecture remains same for the MCS-51 family. In general all microcontrollers in MCS- 51 family are represented by XX51, where XX can take values like 80, 89 etc.

Schematic and Features


 

8051 Microcontroller


A micro controller is an integrated circuit or a chip with a processor and other support devices like program memory, data memory, I/O ports, serial communication interface etc integrated together. Unlike a microprocessor (ex: Intel 8085), a microcontroller does not require any external interfacing of support devices. Intel 8051 is the most popular microcontroller ever produced in the world market. Now lets talk about 8051 microcontroller in detail.
Before going further, it will be interesting for you to understand the difference between a Microprocessor and Microcontroller. We have a detailed article which describes the basic difference between both.
Microprocessor vs Microcontroller 

Here is a Quick Access to various sections of this article:-

Pin Diagram :-  Internal Architecture  :-  Program Memory Organization  :- Data Memory Organization :-8051 System Clock  :- 8051 Reset Circuit

Introduction

Intel first produced a microcontroller in 1976 under the name MCS-48, which was an 8 bit microcontroller. Later in 1980 they released a further improved version (which is also 8 bit), under the name MCS-51. The most popular microcontroller 8051 belongs to the MCS-51 family of microcontrollers by Intel. Following the success of 8051, many other semiconductor manufacturers released microcontrollers under their own brand name but using the MCS-51 core. Global companies and giants in semiconductor industry like Microchip, Zilog, Atmel, Philips, Siemens released products under their brand name. The specialty was  that all these devices could be programmed using the same MCS-51 instruction sets. They basically differed in support device configurations like improved memory, presence of an ADC or DAC etc. Intel then released its first 16 bit microcontroller in 1982, under name MCS-96

8051 Microcontroller Packaging

There is no need of explaining what each package means, you already know it. So I will skim through mainly used packaging for 8051. See, availability of various packages change from device to device. The most commonly used is Dual Inline Package (40 pins) – known popularly as DIP. 8051 is also available in QFP (Quad Flat Package), TQFP (Thin Quad Flat Package), PQFP (Plastic Quad Flat Package) etc. For explaining the pin diagram, we have used a 40 pin DIP IC as model.

8051 Microcontroller Architecture

Its possible to explain microcontroller architecture to a great detail, but we are limiting scope of this article to internal architecture, pin configuration, program memory and data memory organization. The basic architecture remains same for the MCS-51 family. In general all microcontrollers in MCS- 51 family are represented by XX51, where XX can take values like 80, 89 etc.

Schematic and Features


The general schematic diagram of 8051 microcontroller is shown above. We can see 3 system inputs, 3 control signals and 4 ports (for external interfacing). A Vcc power supply and ground is also shown. Now lets explain and go through each in detail. System inputs are necessary to make the micro controller functional. So the first and most important of this is power, marked as Vcc with a GND  (ground potential). Without proper power supply, no electronic system would work. XTAL 1 and XTAL 2 are for the system clock inputs from crystal clock circuit. RESET input is required to initialize microcontroller to default/desired values and to make a new start.
There are 3 control signals, EA,PSEN and ALE. These signals known as External Access (EA), Program Store Enable (PSEN), and Address Latch Enable (ALE) are used for external memory interfacing.
Take a look at the schematic diagram below (a functional microcontroller)




As mentioned above, control signals are used for external memory interfacing. If  there is no requirement of external memory interfacing then, EA pin is pulled high (connected to Vcc) and two others PSEN and ALE are left alone. You can also see a 0.1 micro farad decoupling capacitor connected to Vcc (to avoid HF oscillations at input).
There are four ports numbered 0,1,2,3 and called as Port 0, Port 1, Port 2 and Port 3 which are used for external interfacing of devices like DAC, ADC, 7 segment display, LED etc. Each port has 8 I/O lines and they all are bit programmable.

8051 Pin Diagram & Description

 

 

For describing pin diagram and pin configuration of 8051, we are taking into consideration a 40 pin DIP (Dual inline package). Now lets go through pin configuration in detail.
Pin-40 : Named as Vcc is the main power source. Usually its +5V DC.
You may note some pins are designated with two signals (shown in brackets).
Pins 32-39: Known as Port 0 (P0.0 to P0.7) – In addition to serving as I/O port, lower order address and data bus signals are multiplexed with this port (to serve the purpose of external memory interfacing). This is a bi directional I/O port (the only one in 8051) and external pull up resistors are required to function this port as I/O.
Pin-31:- ALE aka Address Latch Enable is used to demultiplex the address-data signal of port 0 (for external memory interfacing.)  2 ALE pulses are available for each machine cycle.
Pin-30:- EA/ External Access input is used to enable or disallow external memory interfacing. If there is no external memory requirement, this pin is pulled high by connecting it to Vcc.
Pin- 29:- PSEN or Program Store Enable is used to read signal from external program memory.
Pins- 21-28:- Known as Port 2 (P 2.0 to P 2.7) – in addition to serving as I/O port, higher order address bus signals are multiplexed with this quasi bi directional port.
Pin 20:- Named as Vss – it represents ground (0 V) connection.
Pins 18 and 19:- Used for interfacing an external crystal to provide system clock.
Pins 10 – 17:- Known as Port 3. This port also serves some other functions like interrupts, timer input, control signals for external memory interfacing RD and WR , serial communication signals RxD and TxD etc. This is a quasi bi directional port with internal pull up.
Pin 9:- As explained before RESET pin is used to set the 8051 microcontroller to its initial values, while the microcontroller is working or at the initial start of application. The RESET pin must be set high for 2 machine cycles.
Pins 1 – 8:- Known as Port 1. Unlike other ports, this port does not serve any other functions. Port 1 is an internally pulled up, quasi bi directional I/O port.

 

8051 Internal Architecture

 


There is no need of any detailed explanation to understand internal architecture of 8051 micro controller. Just look at the diagram above and you observer it carefully. The system bus connects all the support devices with the central processing unit. 8051 system bus composes of an 8 bit data bus and a 16 bit address bus and bus control signals. From the figure you can understand that all other devices like program memory, ports, data memory, serial interface, interrupt control, timers, and the central processing unit are all interfaced together through the system bus. RxD and TxD (serial port input and output) are interfaced with port 3.

8051 Memory Organization

Before going deep into the memory architecture of 8051, lets talk a little bit about two variations available for the same. They are Princeton architecture and Harvard architecture. Princeton architecture treats address memory and data memory as a single unit (does not distinguish between two) where as Harvard architecture treats program memory and data memory as separate entities. Thus Harvard architecture demands address, data and control bus for accessing them separately where as Princeton architecture does not demand any such separate bus.
Example:- 8051 micro controller is based on Harvard architecture and 8085 micro processor is based on Princeton architecture.
Thus 8051 has two memories :- Program memory and Data memory

Program memory organization

 

Now lets dive into the program memory organization 0f 8051. It has an internal program of 4K size and if needed an external memory can be added (by interfacing ) of size 60K maximum. So in total 64K size memory is available for 8051 micro controller.  By default, the External Access (EA) pin should be connected Vcc so that instructions are fetched from internal memory initially. When the limit of internal memory (4K) is crossed, control will automatically move to external memory to fetch remaining instructions. If the programmer wants to fetch instruction from external memory only (bypassing the internal memory), then he must connect External Access (EA) pin to ground (GND).
You may already know that 8051 has a special feature of locking the program memory (internal) and hence protecting against software piracy. This feature is enable by program lock bits. Once these bits are programmed, contents of internal memory can not be accessed using an external circuitry. How ever locking the software is not possible if external memory is also used to store the software code. Only internal memory can be locked and protected.  Once locked, these bits can be unlocked only by a memory-erase operation, which in turn will erase the programs in internal memory too.
8051 is capable of pipelining. Pipelining makes a processor capable of fetching the next instruction while executing previous instruction. Its some thing like multi tasking, doing more than one operation at a time. 8051 is capable of fetching first byte of the next instruction while executing the previous instruction.

 

Data memory organization



 In the MCS-51 family, 8051 has 128 bytes of internal data memory and it allows interfacing external data memory of maximum size up to 64K. So the total size of data memory in 8051 can be upto 64K (external)  +  128 bytes (internal).  Observe the diagram carefully to get more understanding. So there are 3 separations/divisions of the data memory:- 1) Register banks 2) Bit addressable area 3) Scratch pad area.




Register banks form the lowest 32 bytes on internal memory and there are 4 register banks designated bank #0,#1, #2 and #3. Each bank has 8 registers which are designated as R0,R1…R7. At a time only one register bank is selected for operations and the registers inside the selected bank are accessed using mnemonics R0..R1.. etc. Other registers can be accessed simultaneously only by direct addressing.  Registers are used to store data or operands during executions.  By default register bank #0 is selected (after a system reset).
The bit addressable ares of 8051 is usually used to store bit variables. The bit addressable area is formed by the 16 bytes next to register banks. They are designated from address 20H to 2FH (total 128 bits). Each bits can be accessed from 00H to 7FH within this 128 bits from 20H to 2FH. Bit addressable area is mainly used to store bit variables from application program, like status of an output device like LED or Motor (ON/OFF) etc. We need only a bit to store this status and using a complete byte addressable area for storing this is really bad programming practice, since it results in wastage of memory.
The scratch pad area is the upper 80 bytes which is used for general purpose storage. Scratch pad area is from 30H to 7FH  and this includes stack too.

 

8051 System Clock



An 8051 clock circuit is shown above.  In general cases, a quartz crystal is used to make the clock circuit. The connection is shown in figure (a) and note the connections to XTAL 1 and XTAL 2.  In some cases external clock sources are used and you can see the various connections above. Clock frequency limits (maximum and minimum) may change from device to device. Standard practice is to use 12MHz frequency. If serial communications are involved then its best to use 11.0592 MHz frequency.




Okay, take a look at the above machine cycle waveform. One complete oscillation of the clock source is called a pulse. Two pulses forms a state and six states forms one machine cycle. Also note that, two pulses of ALE are available for 1 machine cycle.

8051 Reset Circuit



 8051 can be reset in two ways 1) is power-on reset – which resets the 8051 when power is turned ON and 2) manual reset – in which a reset happens only when a push button is pressed manually. Two different  reset circuits are shown above. A reset doesn’t affect contents of internal RAM. For reset to happen, the reset input pin (pin 9) must be active high for atleast 2 machine cycles.  During a reset operation :- Program counter is cleared and it starts from 00H, register bank #0 is selected as default, Stack pointer is initialized to 07H, all ports are written with FFH.