Most viewed

31 May 2011

Create Folders And Files With NO! Name


             Create Folders And Files With NO! Name


This trick will allow you to create files and folders without any name.

Just follow the steps as given below :-



1) Select any file or folder.

2) Right click on it, select 'Rename' or simply press 'F2'.

30 May 2011


Chapter 7

8051 Microcontroller - Timers

 Timers
 Measuring Time
 How Long do Timers Take to Count? 
 Initializing a Timer
 Reading a Timer
 Reading a Timer Value
 Detecting a Timer Overflow
 How Timers Count
 Timer SFRs
  • TMOD SFR
    • Mode 0 - 13-bit Timer
    • Mode 1 - 16-bit Timer
    • Mode 2 - Auto-reload Timer
    • Mode 3 - Split Timer
  • TCON SFR
 Timing the Length of an Event
 Timers as Event Counters



051 Tutorial: Timers



The 8051 comes equipped with two timers, both of which may be controlled, set, read, and configured individually. The 8051 timers have three general functions: 1) Keeping time and/or calculating the amount of time between events, 2) Counting the events themselves, or 3) Generating baud rates for the serial port.The three timer uses are distinct so we will talk about each of them separately. The first two uses will be discussed in this chapter while the use of timers for baud rate generation will be discussed in the chapter relating to serial ports.
How does a timer count?
How does a timer count? The answer to this question is very simple: A timer always counts up. It doesnt matter whether the timer is being used as a timer, a counter, or a baud rate generator: A timer is always incremented by the microcontroller.

Programming Tip: Some derivative chips actually allow the program to configure whether the timers count up or down. However, since this option only exists on some derivatives it is beyond the scope of this tutorial which is aimed at the standard 8051. It is only mentioned here in the event that you absolutely need a timer to count backwards, you will know that you may be able to find an 8051-compatible microcontroller that does it.
USING TIMERS TO MEASURE TIMEObviously, one of the primary uses of timers is to measure time. We will discuss this use of timers first and will subsequently discuss the use of timers to count events. When a timer is used to measure time it is also called an "interval timer" since it is measuring the time of the interval between two events.
How long does a timer take to count?
First, its worth mentioning that when a timer is in interval timer mode (as opposed to event counter mode) and correctly configured, it will increment by 1 every machine cycle. As you will recall from the previous chapter, a single machine cycle consists of 12 crystal pulses. Thus a running timer will be incremented:

    11,059,000 / 12 = 921,583
921,583 times per second. Unlike instructions--some of which require 1 machine cycle, others 2, and others 4--the timers are consistent: They will always be incremented once per machine cycle. Thus if a timer has counted from 0 to 50,000 you may calculate:

Chapter 8 8051 Microcontroller - Serial Port Operations / Communication



Chapter 8

8051 Microcontroller -
Serial Port Operations / Communication

 Serial Port Operations
 Setting the Serial Port Mode
 Writing to the Serial Port
 Setting the Serial Baud Rate
 Reading from the Serial Port




8051 Tutorial: Serial Communication



One of the 8051s many powerful features is its integrated UART, otherwise known as a serial port. The fact that the 8051 has an integrated serial port means that you may very easily read and write values to the serial port. If it were not for the integrated serial port, writing a byte to a serial line would be a rather tedious process requring turning on and off one of the I/O lines in rapid succession to properly "clock out" each individual bit, including start bits, stop bits, and parity bits.
However, we do not have to do this. Instead, we simply need to configure the serial ports operation mode and baud rate. Once configured, all we have to do is write to an SFR to write a value to the serial port or read the same SFR to read a value from the serial port. The 8051 will automatically let us know when it has finished sending the character we wrote and will also let us know whenever it has received a byte so that we can process it. We do not have to worry about transmission at the bit level--which saves us quite a bit of coding and processing time.
Setting the Serial Port Mode
The first thing we must do when using the 8051s integrated serial port is, obviously, configure it. This lets us tell the 8051 how many data bits we want, the baud rate we will be using, and how the baud rate will be determined.
First, lets present the "Serial Control" (SCON) SFR and define what each bit of the SFR represents:
    Bit
    Name
    Bit Addres
    Explanation of Function
    7
    SM0
    9Fh
    Serial port mode bit 0
    6
    SM1
    9Eh
    Serial port mode bit 1.
    5
    SM2
    9Dh
    Mutliprocessor Communications Enable (explained later)
    4
    REN
    9Ch
    Receiver Enable. This bit must be set in order to receive characters.
    3
    TB8
    9Bh
    Transmit bit 8. The 9th bit to transmit in mode 2 and 3.
    2
    RB8
    9Ah
    Receive bit 8. The 9th bit received in mode 2 and 3.
    1
    TI
    99h
    Transmit Flag. Set when a byte has been completely transmitted.
    0
    RI
    98h
    Receive Flag. Set when a byte has been completely received.
Additionally, it is necessary to define the function of SM0 and SM1 by an additional table:
    SM0
    SM1
    Serial Mode
    Explanation
    Baud Rate
    0
    0
    0
    8-bit Shift Register
    Oscillator / 12
    0
    1
    1
    8-bit UART
    Set by Timer 1 (*)
    1
    0
    2
    9-bit UART
    Oscillator / 64 (*)
    1
    1
    3
    9-bit UART
    Set by Timer 1 (*)
(*) Note: The baud rate indicated in this table is doubled if PCON.7 (SMOD) is set.
The SCON SFR allows us to configure the Serial Port. Thus, well go through each bit and review its function.
The first four bits (bits 4 through 7) are configuration bits.
Bits SM0 and SM1 let us set the serial mode to a value between 0 and 3, inclusive. The four modes are defined in the chart immediately above. As you can see, selecting the Serial Mode selects the mode of operation (8-bit/9-bit, UART or Shift Register) and also determines how the baud rate will be calculated. In modes 0 and 2 the baud rate is fixed based on the oscillators frequency. In modes 1 and 3 the baud rate is variable based on how often Timer 1 overflows. Well talk more about the various Serial Modes in a moment.
The next bit, SM2, is a flag for "Multiprocessor communication." Generally, whenever a byte has been received the 8051 will set the "RI" (Receive Interrupt) flag. This lets the program know that a byte has been received and that it needs to be processed. However, when SM2 is set the "RI" flag will only be triggered if the 9th bit received was a "1". That is to say, if SM2 is set and a byte is received whose 9th bit is clear, the RI flag will never be set. This can be useful in certain advanced serial applications. For now it is safe to say that you will almost always want to clear this bit so that the flag is set upon reception of any character.
The next bit, REN, is "Receiver Enable." This bit is very straightforward: If you want to receive data via the serial port, set this bit. You will almost always want to set this bit.
The last four bits (bits 0 through 3) are operational bits. They are used when actually sending and receiving data--they are not used to configure the serial port.
The TB8 bit is used in modes 2 and 3. In modes 2 and 3, a total of nine data bits are transmitted. The first 8 data bits are the 8 bits of the main value, and the ninth bit is taken from TB8. If TB8 is set and a value is written to the serial port, the datas bits will be written to the serial line followed by a "set" ninth bit. If TB8 is clear the ninth bit will be "clear."
The RB8 also operates in modes 2 and 3 and functions essentially the same way as TB8, but on the reception side. When a byte is received in modes 2 or 3, a total of nine bits are received. In this case, the first eight bits received are the data of the serial byte received and the value of the ninth bit received will be placed in RB8.
TI means "Transmit Interrupt." When a program writes a value to the serial port, a certain amount of time will pass before the individual bits of the byte are "clocked out" the serial port. If the program were to write another byte to the serial port before the first byte was completely output, the data being sent would be garbled. Thus, the 8051 lets the program know that it has "clocked out" the last byte by setting the TI bit. When the TI bit is set, the program may assume that the serial port is "free" and ready to send the next byte.
Finally, the RI bit means "Receive Interrupt." It funcions similarly to the "TI" bit, but it indicates that a byte has been received. That is to say, whenever the 8051 has received a complete byte it will trigger the RI bit to let the program know that it needs to read the value quickly, before another byte is read.

Chapter 6 8051 - Low Level Information


Chapter 6

8051 - Low Level Information

 Instruction Set, Timing and Low Level Information







8051 Tutorial: Instruction Set, Timing, and Low-Level Info


In order to understand--and better make use of--the 8051, it is necessary to understand some underlying information concerning timing.
The 8051 operates based on an external crystal. This is an electrical device which, when energy is applied, emits pulses at a fixed frequency. One can find crystals of virtually any frequency depending on the application requirements. When using an 8051, the most common crystal frequencies are 12 megahertz and 11.059 megahertz--with 11.059 being much more common. Why would anyone pick such an odd-ball frequency? Theres a real reason for it--it has to do with generating baud rates and well talk more about it in the Serial Communication chapter. For the remainder of this discussion well assume that were using an 11.059Mhz crystal.

Chapter 5 8051 - Program Flow


Chapter 5

8051 - Program Flow

 Program Flow
 Direct Jumps 
 Return from Subroutines
 Conditional Branching
 Direct Calls
 Interrupts







8051 Tutorial: Program Flow



When an 8051 is first initialized, it resets the PC to 0000h. The 8051 then begins to execute instructions sequentially in memory unless a program instruction causes the PC to be otherwise altered. There are various instructions that can modify the value of the PC; specifically, conditional branching instructions, direct jumps and calls, and "returns" from subroutines. Additionally, interrupts, when enabled, can cause the program flow to deviate from its otherwise sequential scheme.Conditional Branching
The 8051 contains a suite of instructions which, as a group, are referred to as "conditional branching" instructions. These instructions cause program execution to follow a non-sequential path if a certain condition is true.
Take, for example, the JB instruction. This instruction means "Jump if Bit Set." An example of the JB instruction might be:

    JB 45h,HELLO
    NOP
    HELLO:
    ....

Chapter 4 8051 - Addressing Modes


Chapter 4

8051 - Addressing Modes

 Addressing Modes
 Direct Addressing  
 External Direct Addressing
 Immediate Addressing
 Indirect Addressing
 External Indirect Addressing






8051 Tutorial: Addressing Modes



An "addressing mode" refers to how you are addressing a given memory location. In summary, the addressing modes are as follows, with an example of each:
    Immediate Addressing
    MOV A,#20h
    Direct Addressing
    MOV A,30h
    Indirect Addressing
    MOV A,@R0
    External Direct
    MOVX A,@DPTR
    Code Indirect
    MOVC A,@A+DPTR
Each of these addressing modes provides important flexibility.
Immediate Addressing
Immediate addressing is so-named because the value to be stored in memory immediately follows the operation code in memory. That is to say, the instruction itself dictates what value will be stored in memory.
For example, the instruction:
    MOV A,#20h

Chapter 3 8051 - Basic Registers


Chapter 3

8051 - Basic Registers

 Basic Registers
 Accumulator
 B Register
  Program Counter (PC)
 "R" Registers
 Data Pointer (DPTR)
 Stack Pointer (SP)










8051 Tutorial: Basic Registers



The AccumulatorIf youve worked with any other assembly languages you will be familiar with the concept of an Accumulator register.
The Accumulator, as its name suggests, is used as a general register to accumulate the results of a large number of instructions. It can hold an 8-bit (1-byte) value and is the most versatile register the 8051 has due to the shear number of instructions that make use of the accumulator. More than half of the 8051s 255 instructions manipulate or use the accumulator in some way.
For example, if you want to add the number 10 and 20, the resulting 30 will be stored in the Accumulator. Once you have a value in the Accumulator you may continue processing the value or you may store it in another register or in memory.
The "R" registers
The "R" registers are a set of eight registers that are named R0, R1, etc. up to and including R7.
These registers are used as auxillary registers in many operations. To continue with the above example, perhaps you are adding 10 and 20. The original number 10 may be stored in the Accumulator whereas the value 20 may be stored in, say, register R4. To process the addition you would execute the command:

    ADD A,R4

Chapter 2 8051 - Special Function Registers



Chapter 2
8051 - Special Function Registers



8051 Tutorial: SFRs



What Are SFRs?
The 8051 is a flexible microcontroller with a relatively large number of modes of operations. Your program may inspect and/or change the operating mode of the 8051 by manipulating the values of the 8051's Special Function Registers (SFRs).
SFRs are accessed as if they were normal Internal RAM. The only difference is that Internal RAM is from address 00h through 7Fh whereas SFR registers exist in the address range of 80h through FFh.
Each SFR has an address (80h through FFh) and a name. The following chart provides a graphical presentation of the 8051's SFRs, their names, and their address.








As you can see, although the address range of 80h through FFh offer 128 possible addresses, there are only 21 SFRs in a standard 8051. All other addresses in the SFR range (80h through FFh) are considered invalid. Writing to or reading from these registers may produce undefined values or behavior.
Programming Tip: It is recommended that you not read or write to SFR addresses that have not been assigned to an SFR. Doing so may provoke undefined behavior and may cause your program to be incompatible with other 8051-derivatives that use the given SFR for some other purpose.

Chapter 1 8051 - Types of Memory



Chapter 1

8051 - Types of Memory

 Types of Memory   
 Internal RAM
 Special Function Registers (SFRs)
  Register Banks
 Code Memory       
 External RAM
 Bit Memory

8051 Tutorial: Types of Memory



The 8051 has three very general types of memory. To effectively program the 8051 it is necessary to have a basic understanding of these memory types.

The memory types are illustrated in the following graphic. They are: On-Chip Memory, External Code Memory, and External RAM.








On-Chip Memory refers to any memory (Code, RAM, or other) that physically exists on the microcontroller itself. On-chip memory can be of several types, but we'll get into that shortly.
External Code Memory is code (or program) memory that resides off-chip. This is often in the form of an external EPROM.
External RAM is RAM memory that resides off-chip. This is often in the form of standard static RAM or flash RAM.

8051 Tutorial: Introduction


8051 Tutorial: Introduction


Despite its relatively old age, the 8051 is one of the most popular microcontrollers in use today. Many derivative microcontrollers have since been developed that are based on--and compatible with--the 8051. Thus, the ability to program an 8051 is an important skill for anyone who plans to develop products that will take advantage of microcontrollers.I hope the information contained in this document/web page will assist you in mastering 8051 programming. Over the years, I've received many requests for a hardcopy/printed version of this tutorial. As a result of those requests, I wrote The 8051/8052 Microcontroller which was published in September 2005. The book contains all the information contained in these tutorials plus additional information regarding hardware, interfacing, and detailed description of each instruction in the 8052 assembly language. If you find these tutorials easy-to-understand and useful, you may wish to consider purchasing this book.
This document is both a tutorial and a reference tool. The various chapters of the document will explain the 8051 step by step. The chapters are targeted at people who are attempting to learn 8051 assembly language programming. The appendices are a useful reference tool that will assist both the novice programmer as well as the experienced professional developer.


 

Based on your view




You have to try this

This is trending now #