Vous êtes sur la page 1sur 8

8051 Microcontroller Tutorial(basics)

HEX ADDITION AND SUBTRACTION, 8051 Timers Before actually going through this tutorial let me tell you something about number systems used in Computer Systems. As you know human know the decimal number system 1,2,3---9, but how will computer understand our language hence we use binary system which uses 0 & 1. Computers understand the language of 0 & 1. We also have a hexadecimal system which is nothing but a way of representing a binary number. Similarly we have a ASCII System for information sharing between computers. Memory inside computer system: There are Basically two types of memories RAM & ROM. RAM as you know is Random Access Memory and data stored in it is temporary whereas ROM is read only memory and data stored in it is permanent. CPU (Central Processing Unit is combination of ALU Arithmetic Logic Unit & Control Unit. The A.L.U. (Arithmetic and Logic Unit) performs all the calculations.
Introduction to 8051 Main features of 8051 Microcontroller are : RAM-128 bytes, ROM-4K bytes, Timer-2, I/O pins-32, Serial port, Interrupt sources. Below on the left you can see 8051 pin diagram and on the right is the Internal RAM of 8051.Internal RAM locations 20-2FH are both byte-addressable and bit addressable. Out of 128 bytes of Internal RAM only 16 bytes of it are bit addressable.

8051s programming registers & SFR's


A Accumulator -Used to accumulate resultants of big instructions. B register-Similar To ACC except it holds 1byte SP Stack Pointer register-Used for Push and Pop. This SFR indicates where the next value to be taken from the stack will be read from in Internal RAM DPTR Data Pointer register(16bit) -Points to Data to be executed.The SFRs DPL and DPH act together to represent a 16-bit value called the Data Pointer. R0-R7 general registers-8 bit registers PSW (Program Status Word (Flagregister): PSW SFR contains the carry flag, the auxiliary carry flag, the overflow flag, and the parity flag. P1 Port -Input/Output Port P2 Port-Input/Output Port P3 Port-Input/Output Port TH0 TL0 16-bit timer register TH1 TL1 16-bit timer register SCON Serial Control register -controls the baud rate of the serial port SBUF Serial Buffer register-Act as an Input/Output Port Addressing Modes in 8051: MOV A,#30H ;immediate mode MOV A,30H ; direct mode MOV A,R0 ; register mode MOV R0,#30H ; immediate mode MOV A,@R0 ; indirect mode

MOV DPTR,#9000H ;immediate mode MOVX A,@DPTR ; indirect mode

8051 Timer Basics Timer SFRs-TMOD SFR and TCON SFR

SFR Type TH0 TL0 TH1 TL1 TCON TMOD

Description of SFR High Byte OF Timer 0 Low Byte OF Timer 0 High Byte OF Timer 1 Low Byte OF Timer 1 Timer Control Timer Mode

SFR Address 8Ch 8Ah 8Dh 8Bh 88h 89h

TMOD SFR -Timers


By Using this SFR we can modify timer to be a 16-bit timer, an 8-bit autoreload timer, a 13bit timer, or 2 separate timers

Bit Number 7

Type

Working

Timer Type

GATE1

Gating Control when set To decide whether timer is used as a delay generator or as an event counter Timer mode bit Timer mode bit Gating Control Purpose To decide whether timer is used as a delay generator or as an event counter Timer mode bit

C/T1

5 4 3

M1 M0 GATE0

1 1 0

C/T0

M1

M0

Timer mode bit

0 Description of Mode 13-bit Timer. 16-bit Timer 8-bit autoreload Split timer mode

M1

M0

Timer Mode

0 0

0 1

0 1

TCON SFR-Timers

The Timer Control SFR is used to modify the way in which the 8051's two timers T0 & T1 are operating
Bit Type Working

TF1

Timer 1 Overflow flag

TR1

Timer 1 Run control bit

TF0

Timer 0 Overflow flag

TR0

Timer 0 Run control bit

3 2 1 0

IE1 IT1 IE0 IT0

External Interrupt 1 Interrupt 1 type External Interrupt 0 Interrupt 0 Type

8051Microntroller vs 8052 Microcontroller

Features of 8051 Microcontroller ROM- 4K bytes RAM-128 bytes Timer-2 I/O pins-32 Serial port-1 Interrupt sources-6

Features of 8052 Microcontroller ROM- 8K bytes RAM-256 bytes Timer-3 I/O pins-32 Serial port-1 Interrupt sources-8

8051 Circuits
8051 Development System Circuit Board 8051: Frequency Meter SIMPLE CIRCUITS - Free 8051 Microcontroller projects 8051 Development System Circuit Board3 8051 and 8052 Microcontrollers Circuits/Schematics Directory circuits : 8051 Microcontroller Projects AVR PIC Projects Examples of C Code & Micro Circuits for PIC16C84, AVR & 8051 Sam's 8051 Page 8051 microcontroller hardware interfacing tutorials circuits

8052 Circuits
Free 8052 Microcontroller Based Projects The Microcontroller Idea Book: Circuits, Programs & Applications The 8052-Basic Resource Page 8052 Simulator at WhatCircuits.com The Microcontroller Idea Book, Circuits, Programs, & Applications 8051 and 8052 Microcontrollers Circuits/Schematics Directory Robotics using the 8052 8052.com The 8051/8052 Microcontroller: Architecture, Assembly Language Hobby Projects 8051 and 8052

Microcontrollers Circuits/Schematics Directory

8051 Subroutines
BCD TO BYTE bcd_to_byte: XCH A,R0 SUBB A,#30h JNB ACC.4,bcd_to_byte_2 SUBB A,#07h bcd_to_byte_2: XCH A,R0 SUBB A,#30h JNB ACC.4,bcd_to_byte_3 SUBB A,#07h bcd_to_byte_3: SWAP A ORL A,R0 RET BYTE TO BCD byte_to_bcd: MOV R0,A ANL A,#0Fh ADD A,#0F6h JNC byte_to_bcd_2 ADD A,#07h byte_to_bcd_2: ADD A,#3Ah XCH A,R0 SWAP A ANL A,#0Fh ADD A,#0F6h JNC byte_to_bcd_3 ADD A,#07h byte_to_bcd_3: ADD A,#3Ah RET Decrement Data Pointer DEC_DPTR: XCH A,DPL ;Exchange A for DPL DEC A ;Decrement A (which is DPL) CJNE A,#0FFh,_dec_dptr2 ;If A (DPL) is not #0FFh, continue normally

BYTE TO ASCII Byte2ascii: mov b, a swap a acall Nibble2ascii xch a, b Nibble2ascii: anl a, #0x0f inc a movc a, @a+pc ret .ascii "0123456789ABCDEF" HEX TO ASCII Convert a hexadecimal nibble to its ASCII character equivalent.

Microprocessor vs Microcontroller

HexAsc: ANL A,#0Fh ; Make sure we're working Microprocessor is a microcomputer on a single with only chip. A microprocessor are of various types ; one nibble. such as 20 pin microprocessor or a 40 pin CJNE A,#0Ah,HA1 ; Test microprocessor. A microprocessor is a value range. programmable digital electronic component HA1: JC HAVal09 ; Value is that incorporates the functions of a central 0 to 9. processing unit (CPU) on a single semi ADD A,#7 ; Value is A to conducting integrated circuit (IC). Advanced F, extra adjustment. Microprocessors can be said as HAVal09: ADD A,#'0' ; Microcontrollers like we have 8051 and 8052. Adjust value to ASCII hex. RET In a Microcontroller we have an inbuilt RAM, ROM, I/O Ports that is they exist on the chip Delays Subroutines itself as shown in the above diagram. Delay For 500 Microseconds delay500ms: call delay100ms call delay100ms call delay100ms call delay100ms call delay100ms ret Delay for 100 Microseconds delay100ms: mov r7,#100 Embedded Products using Microcontrollers INTERCOM TELEPHONE FAX MACHINES TVs CABLE TV TUNER

DEC DPH ;If A=FFh, we need to decrement DPH _dec_dptr2: XCH A,DPL ;Exchange A for DPL (thus saving DPL and restoring A) RET

x4: call delay1ms djnz r7,x4 ret Delay for 1 Seconds delay1s: mov r6,#10 x5: call delay100ms djnz r6,x5 ret Delay for 1ms delay1ms: mov r2,#10 x3: mov r1,#49 x2: djnz r1,x2 djnz r2,x3 ret

VCR CAMCORDER MICROWAVE LASER PRINTER ENGINE CONTROL SEWING MACHINES REMOTE CONTROLS VIDEO GAMES CELLULAR PHONES TELEPHONES

Binary To ASCII BINTOASC : anl a,#00fh ; Keep Only Low Bits add a,#090h ; Add 144 da a ; Decimal Adjust addc a,#040h ; Add 64 da a ; Decimal Adjust ret ; Return To Call end

8051 Microcontroller Properties

8051 Microcontroller is one of the latest microcomputers on a single chip. This microcontroller has following properties ROM-4KB RAM-128 Bytes Timers available-2 I/O Pins-32 Serial Port-1 Interrupts sources-6 sources available We need to understand Number System in order to learn assembly language better.Vcc-5v obviously and Speeds available include 12Mhz,16Mhz,20Mhz depends on Crystal. We can use this microcontrollers

in manufacturing LED Clocks and other programmable devices such as Microwaves and Camcorders.

Vous aimerez peut-être aussi