Wednesday, September 11, 2013

PUSH & POP
STACK:
it s part of RAM in which data will store temporary during execution of program.
STACK work on last in first out principal.to store and retrieve data during program execution in stack push and pop instruction work for it.
PUSH:
its used to store data into stack.
POP:
to retrieve data from stack.
SP:
stack pointer is 8 bit register which store value of top of the stack.
by default stack pointer contain 07h.

PUSH AND POP OPERATION:

PUSH:
using push operation stack pointer increased first and then content of register or memory will store on that stack location which stored in SP.
here SP contain =07h

PUSH R6;SP increased by one and contain of R6 store into 08 location.
PUSH R1;SP increased again by one and contain of R1 stored into 09 location.
PUSH R4;SP increased again by one and contain of R4 stored into 0A location.

POP:
In this retrieve data first and then stack pointer decreased by one.
if we write
POP 20h;then content at 0Ah location will copy into 20h then stack pointer decrease by 1.
POP 21h;then content at 09h location will copy into 21h then stack pointer decrease by 1.

-----------------------------------------------------------------------------------------------------------------------
 NEXT: serial communication                                        PREVIOUS:how to access external memory






In 8051 micro controller have in built RAM and ROM,but size of this memory is limited size of RAM is 128 byte while size of ROM is 4KB some time we need more memory then this so we connect external memory with micro controller.

access external RAM

To access external RAM we used MOVX instruction.

MOVX A,@DPTR;this code used for read data from external RAM.

MOVX @DPTR,A;this code used for write data into external RAM.

access External ROM

MOVC A,@A+DPTR; to read data from ROM.

here we add content of A and DPTR and then using indirect addressing mode we copy the content of that location into A.

MOVC A,@A+PC; to read data from ROM.

we increment content of PC and then add with A.then we copy the content of that location into A using indirect addressing mode.


External program memory is accessed under the following condition.
  1. Whenever is low, or
  2. Whenever PC contains a number higher than 0FFFH (for 8051) or 1FFF (for 8052). 
Some typical use of code/program memory access: External program memory can be not only used to store the code, but also for lookup table of various functions required for a particular application. Mathematical functions such as Sine, Square root, Exponential, etc. can be stored in the program memory (Internal or eternal)  and these functions can be accessed using MOVC instruction.
 ----------------------------------------------------------------------------------------------------------------------
PREVIOUS:Serial communication                                                       NEXT: push & pop operation

Wednesday, September 4, 2013

Serial Interface
  • The serial port of 8051 is full duplex, i.e., it can transmit and receive simultaneously.
  • The register SBUF is used to hold the data. The special function register SBUF is physically two registers. 
  • One is, write-only and is used to hold data to be transmitted out of the 8051 via TXD. 
  • The other is, read-only and holds the received data from external sources via RXD. Both mutually exclusive registers have the same address 099H. 
Serial Port Control Register (SCON)
  • Register SCON controls serial data communication.
    Address: 098H (Bit addressable

Data Transmission
  • Transmission of serial data begins at any time when data is written to SBUF. 
  • Pin P3.1 (Alternate function bit TXD) is used to transmit data to the serial data network. 
  • TI is set to 1 when data has been transmitted. This signifies that SBUF is empty so that another byte can be sent. 
Data Reception
  • Reception of serial data begins if the receive enable bit is set to 1 for all modes. 
  • Pin P3.0 (Alternate function bit RXD) is used to receive data from the serial data network. 
  • Receive interrupt flag, RI, is set after the data has been received in all modes. The data gets stored in SBUF register from where it can be read. 
Serial Data Modes 
8051 micro controller communicate with another peripheral device through RXD and TXD pin of port3.controller have four mode of serial communication.this four mode of serial communication are below.
1. Serial data mode 0-fixed buad Rate.
2. Serial data mode 1-variable baud rate.
3. Serial data mode 2 -fixed baud Rate.
4. Serial Data mode 3 -variable baud rate.

                                          Serial Data Mode-0
                                           (Baud Rate Fixed)

  • In this mode, the serial port works like a shift register and the data transmission works synchronously with a clock frequency of fosc /12. 
  • Serial data is received and transmitted through RXD. 8 bits are transmitted/ received aty a time. 
  • Pin TXD outputs the shift clock pulses of frequency fosc /12, which is connected to the external circuitry for synchronization. 
  • The shift frequency or baud rate is always 1/12 of the oscillator frequency.   

Serial Data Mode-1 (standard UART mode)
(baud rate is variable)
  • In mode-1, the serial port functions as a standard Universal Asynchronous Receiver Transmitter (UART) mode. 10 bits are transmitted through TXD or received through RXD. 
  • The 10 bits consist of one start bit (which is usually '0'), 8 data bits (LSB is sent first/received first), and a stop bit (which is usually '1'). Once received, the stop bit goes into RB8 in the special function register SCON. The baud rate is variable.
 


Serial Data Mode-2 Multiprocessor 
(baud rate is fixed)
  • In this mode 11 bits are transmitted through TXD or received through RXD.
  • The various bits are as follows: a start bit (usually '0'), 8 data bits (LSB first), a programmable 9 th (TB8 or RB8)bit and a stop bit (usually '1').  
  • While transmitting, the 9 th data bit (TB8 in SCON) can be assigned the value '0' or '1'. For example, if the information of parity is to be transmitted, the parity bit (P) in PSW could be moved into TB8.
  • On reception of the data, the 9 th bit goes into RB8 in 'SCON', while the stop bit is ignored. 
  • The baud rate is programmable to either 1/32 or 1/64 of the oscillator frequency.

f baud = (2 SMOD /64) fosc 


Serial Data Mode-3 - Multi processor mode
(Variable baud rate)

  • In this mode 11 bits are transmitted through TXD or received through RXD.
  • The various bits are: a start bit (usually '0'), 8 data bits (LSB first), a programmable 9 th bit and a stop bit (usually '1').  
  • Mode-3 is same as mode-2, except the fact that the baud rate in mode-3 is variable (i.e., just as in mode-1). 
f baud = (2 SMOD /32) * ( fosc / 12 (256-TH1))  
-----------------------------------------------------------------------------------------------------------------------
PREVIOUS:Power Saving mode                                                 NEXT:write and read serial port
 

In this mode PCON (power control register).in this register two bit play important role for power control of 8051.
Below show the format of PCON

8051 has two power saving modes.they are
  1. idle mode
  2. power down mode.
  • The two power saving modes are entered by setting two bits IDL and PD in the special function register (PCON) respectively.
POWER DOWN MODE:

the schematic diagram of power down mode shown below.
  • By setting the PD bit of the PCON register from within the program, the microcontroller is set to Power down mode.
  • thus turning off its internal oscillator and reduces power consumption enormously.
  • The microcontroller can operate using only 2V power supply in power- down mode, while a total power consumption is less than 40uA.
  • The only way to get the micro controller back to normal mode is by reset.
  • While the microcontroller is in Power Down mode, the state of all SFR registers and I/O ports remains unchanged.
  • By setting it back into the normal mode, the contents of the SFR register is lost, but the content of internal RAM is saved.
  • Reset signal must be long enough, approximately 10mS, to enable stable operation of the quartz oscillator.
IDLE MODE:
  • Upon the IDL bit of the PCON register is set, the microcontroller turns off the greatest power consumer- CPU unit while peripheral units such as serial port, timers and interrupt system continue operating normally consuming 6.5mA. 
  • In Idle mode, the state of all registers and I/O ports remains unchanged.
  • n order to exit the Idle mode and make the microcontroller operate normally, it is necessary to enable and execute any interrupt or reset.
  • It will cause the IDL bit to be automatically cleared and the program resumes operation from instruction having set the IDL bit. 
  • It is recommended that first three instructions to execute now are NOP instructions.
  • They don't perform any operation but provide some time for the microcontroller to stabilize and prevents undesired changes on the I/O ports.
-----------------------------------------------------------------------------------------------------------------------
PREVIOUS:serial communication                                                     NEXT:write and read serial port



Tuesday, September 3, 2013

To write data to serial port
  • To write a byte to the serial port one must simply write the value to the SBUF (99h) SFR.
  • if you wanted to send the letter "A" to the serial port, it could be accomplished as easily as
                                         MOV SBUF,#A

  • Upon execution of the above instruction the 8051 will begin transmitting the character via the serial port.
  • Obviously transmission is not instantaneous--it takes a measureable amount of time to transmit.  
  • And since the 8051 does not have a serial output buffer we need to be sure that a character is completely transmitted before we try to transmit the next character.
  • The 8051 lets us know when it is done transmitting a character by setting the TI bit in SCON.
  • When this bit is set we know that the last character has been transmitted and that we may send the next character.
                                         CLR TI ;Be sure the bit is initially clear
                                         MOV SBUF,#A ;Send the letter A to the serial port
                                         JNB TI,$ ;Pause until the TI bit is set.
 
  • The above three instructions will successfully transmit a character and wait for the TI bit to be set before continuing.
  • The last instruction says "Jump if the TI bit is not set to $"--$, in most assemblers, means "the same address of the current instruction.".
  • Thus the 8051 will pause on the JNB instruction until the TI bit is set by the 8051 upon successful transmission of the character.
To read Data from serial port
  • Reading data received by the serial port is equally easy.
  • To read a byte from the serial port one just needs to read the value stored in the SBUF (99h) SFR after the 8051 has automatically set the RI flag in SCON. 
  • For example, if your program wants to wait for a character to be received and subsequently read it into the Accumulator, the following code segment may be used:
                                          JNB RI,$ ;Wait for the 8051 to set the RI flag
                                          MOV A,SBUF ;Read the character from the serial port
 
  • The first line of the above code segment waits for the 8051 to set the RI flag; again, the 8051 sets the RI flag automatically when it receives a character via the serial port.
  • So as long as the bit is not set the program repeats the "JNB" instruction continuously. 
  • Once the RI bit is set upon character reception the above condition automatically fails and program flow falls through to the "MOV" instruction which reads the value.
-----------------------------------------------------------------------------------------------------------------------
 PREVIOUS: Serial communication                                            NEXT: Power Saving Operation
Related Posts Plugin for WordPress, Blogger...
Subscribe to RSS Feed Follow me on Twitter!