8051 training

47
BASIC EMBEDDED SYSTEM TRAINING A COURSE ON

Upload: atulgoyal91

Post on 04-Oct-2015

220 views

Category:

Documents


0 download

DESCRIPTION

8051 language

TRANSCRIPT

PowerPoint Presentation

BASIC EMBEDDED SYSTEM TRAININGA COURSE ON

What is an embedded system?It is an information processing systems embedded into a larger product.

It can perform only that operations ,which it is designed for

Lets checkout ,,,,,

Characteristics of embedded systemMust be dependable

Reliability

Maintainability

Safety

Security

Characteristics of embedded systemMust be efficient

Energy efficient

Code-size efficient (especially for systems on a chip)

Run-time efficient

Cost efficient

Dedicated towards a certain application

Dedicated user interface (no mouse, keyboard and screen).

What is the difference ?Embedded Systems

Few applications that are known at design-time.

Not programmable by end user.

Fixed run-time requirements

Criteria: cost power consumption predictabilityGeneral Purpose Computing

Broad class of applications.

Programmable by end user.

Faster is better.

Criteria:

cost average speed

DIGITAL FUNDAMENTALSCHAPTER 1let us begin with

NUMBER REPRESENTATIONDBH02143568791013111214150011011100101111110100010101011110011011110111110010214356879ACBDEFecimalinaryexBase 10Base 2Base 16

NUMBER REPRESENTATION0/1Bit0 0 0 00 0 0 00 0 0 00 0 0 00 0 0 00 0 0 00 0 0 0NibbleByteWord

Decimal to binary conversion232 11522222111101remainder02310 =2

BINARY TO DECIMAL CONVERSION0 0 1 0 1 0 1 0 128 64 32 16 8 4 2 1 Binary valuePlace value0*1280*11*20*41*80*161*320*64+++++++=42Decimal value

BINARY TO HEX CONVERSION1 0 1 10 0 1 1LSBMSB8 4 2 1 8 4 2 10214356879ACBDEF1*1+1*2 =31*1+1*2+1*8=11Result = B3 H

BINARY NOT LOGIC1 = 00 = 1Not logic complements the voltage levelFor what???

Binary or logic1011000

0000011

1011011Changing the voltage level of a pin or value of a bit without altering othersFor what???

Binary and logic 0101011

00001111

00001011Masking:Discarding bits keeping needed bits aliveFor what ?

Binary xor logic10110101

10110101

00000000

Comparing two sequencesFor what ?

TTL & CMOSPort OR Out Put of a Digital Circuit5 Volt Pin of IC1 at this O/P =5V with 60uA source0 at this O/P = 0V with 1.6mA sink(3.2 ma for P0)GND pin of IC+ve of 5V-ve of 5VRR

MICROCONTROLLER GENERAL VIEW

MEMORY ORGANIZATION

INTERNAL RAMUser RamRegister bankBit addressable Ramr5r4r3r2r6r1r0r7007FB0B7R2If r2=3C101000010780 TO FF are SFRs21How controller works.MOV A,r0ADD A,#0BInstruction decoderProgram memory10101110r0AReading command OR Fetch cycleDATA BUS3F143F133F12Decoding commandsEXECUTINGProgram counter3F123F1300111110MOV A,r0ADD A,#0B3F14Address busAddress of P.G1011000001000110

COMMANDS1 Commands are binary words.

2. Each command has a specific work.

3. This work is done on MEMORY, REGISTERS, or PORTS.

4. These commands are stored in PROGRAM MEMORY.

5. Controller will read these commands from program memory and execute.

6. The result of one command will not be changed until the execution of another command at the same destination.

JUMP INSTRUCTIONLJMP and SJMP are used to Change the flow of commands.L JMP 3A20ADD B,#F3MOV P2,AMOV A,r11F001F011F023A203A213A221F001F013A201F02Program counterProgram memory

24CALL InstructionLCALL A018MOV A,P2vvLCALL A108RRARRARRARRAMOV A,@R1Program Counter A108A109A10A21012102210002CA02CBA10BA10C02CC02CA210002CB2101A10807Stack Pointer.07080B0A09STACKRETA10D0708

25Addressing.Addressing is to which or where OR from which or where the command should act.eg: ADD A,#0Ba. A is the address where the ADD should act. (Register addressing)b. #0B is not an address. But this method is immediate addressing.

Expressions used in Instruction Set and Addressing ModesRn:---- Register R7-R0

direct :------8-bit internal RAM address. location (0-127) or a SFR @Ri :-----8-bit internal data RAM location (0-255) addressed indirectly through registerR1or R0.

#data :------8-bit constant included in instruction.

#data 16:------ 16-bit constant included in instruction.

Expressions used in Instruction Set and Addressing Modesaddr 16 :-------16-bit address. Used by LCALL and LJMP. A branch can beanywhere within the 64K byte Program Memory address space.addr 11:------- 11-bit destination address. Used by ACALL and AJMP. The branch will bewithin the same 2K byte page of program memory as the first byte of thefollowing instruction.rel :------Signed (twos complement) 8-bit offset byte. Used by SJMP and allconditional jumps. Range is -128 to +127 bytes relative to first byte of thefollowing instruction.Bit:----- Direct Addressed bit in Internal Data RAM or Special Function Register.

Examples of instructions.MOV A,Rn Move register to Accumulator.Eg:---MOV A, r2---- the contents of r2 will move to Accumulator.

MOV A,direct ---- Move contents of RAM to A.Eg:- MOV A, 6A ---the contents of RAM location 6A will move to A

MOV A, @Ri ---Contents of RAM indicated by Ri will move to A.Eg:-- MOV A, @r1--- If r1=3B, the contents of RAM location 3B will move to A.

Examples of instructions.MOV A, #direct---- move the data immediate to A.eg:-- MOV A, #2B-- the content of A will be 2B.INC --- increment.DEC---- Decrement.MUL---- Multiply.ANL -----Logical AND.ORL --- Logical OR

INPUT OUTPUT PORTS

*OPEN COLLECTOR PORT0

OSCILLATOR

TIMER/COUNTER

SERIAL COMMUNICATION

COUNTERS & TIMERS

8051 has 2 timers/counters T0 and T1They can measure time, count intervals, and generate baud rate.

Timer T0

If the content of the timer T0 is equal to 0 (T0=0) then both registers will contain 0. If the timer number 2580 (hex), then the TH0 register (high byte) will contain the number 25, while the TL0 register (low byte) will contain number 80. (Upon reset Timer = 0000h).

TMOD Register(Timer Mode)

GATE enables and disables Timer by means of a signal brought to the INTx pin 1 - Timer operates only if the INTx bit is set.0 - Timer operates regardless of the logic state of the INTx bit.C/T selects pulses to be counted up by the timer/counter :1 - Timer counts pulses brought to the T0/T1pin 0 - Timer counts pulses from internal oscillator.T1M1,T1M0 These two bits select the operational mode of the Timer0/1.T1M1 T1M0 MODE DESCRIPTION 0 0 0 13-bit timer 0 1 1 16-bit timer 1 0 2 8-bit auto-reload 1 1 3 Split mode

TIMER-0 IN MODE 0 (13 BIT)

This mode configures timer 0 as a 13-bit timer which consists of all 8 bits of TH0 and the lower 5 bits of TL0. As a result, the Timer 0 uses only 13 of 16 bits.

TIMER-0 IN MODE 1(16 BIT)

Mode 1 configures timer 0 as a 16-bit timer comprising all the bits of both registers TH0 and TL0. That's why this is one of the mostcommonly used modes.

TIMER-0 IN MODE 2 (8 BIT AUTO RELOAD)

TL0 register operates as a timer, while TH0 register stores the value from which the counting starts.

TIMER-0 IN MODE 3(SPLIT MODE)Mode 3 configures timer 0 so that registers TL0 and TH0 operate as separate 8-bit timers. The TL0 timer turns into timer 0, while the TH0 timer turns into timer 1.

TCON Register(Timer Control)

TF1 bit is automatically set, on the Timer 1 overflow.

TR1 bit enables the Timer 1.1 - Timer 1 is enabled.0 - Timer 1 is disabled.

TF0 bit is automatically set, on the Timer 0 overflow.

TR0 bit enables the timer 0.1 - Timer 0 is enabled.0 - Timer 0 is disabled.

TIMER-0 PROGRAMMING

The timer 0 operates in mode 1 and counts pulses generated by internal clock the frequency of which is equal to 1/12 the quartz frequency.1.MODE CONFIGURATION

2.TURN ON TIMER

The TR0 bit is set and the timer starts operation. If the quartz crystal with frequency of 12MHz is embedded then its contents will be incremented every microsecond.

TIMER-0 OVERFLOW DETECTIONConstant reading of timer is in efficient.

Only need to monitor overflow* (FFFF 0000)

When it occurs, the TF0 bit of the TCON register will be automatically set.

The state of this bit can be constantly checked from within the program or by enabling an interrupt which will stop the main program execution when this bit is set.

Delay using timerRequired delay = 0.05 seconds (ie 50,000 machine cycles, 0.05/1uS) Assuming XTAL Freq = 12Mhz

Find value to be loaded into timer registers( TH & TL)

15536 3CB0 60176

Timer T1

Timer 1 only have UART circuitry in 8051