Documente Academic
Documente Profesional
Documente Cultură
Supratim Gupta
Programming Issues
Hardware Information Architecture of the processor p Architecture of the peripheral interconnection Software Instructions Complex Instruction Set Computer (CISC) 135 Instructions for 8051
8051 Architecture
Specific Features 1. 8-bit CPU with registers A (accumulator) and B 2. 16-bit program counter (PC) and data pointer (DPTR) 3. 8-bit program status word (PSW) 4. 8-bit stack pointer (SP) 5. Internal ROM or EPROM of 4k (8051) 6. Internal RAM of 128 bytes 4 register banks each containing 8 registers of 8-bit 16-bytes bit addressable registers 80 bytes general purpose data memory
8051 Architecture
Specific F t S ifi Features 7. 32 input-output pins arranged as 4 eight-bit ports (P0 P3) 8. Two 16 bit timer/counters : T0 and T1 9. Full duplex serial data receiver/transmitter 10. Control registers : TCON, TMOD, SCON, PCON, IP, and IE 11. 2 external and 3 internal interrupt sources 12. Oscillator and clock circuit
Cntd
Cntd
8051 Architecture
SCON SBUF PCON 30 2F Bit Add. Area 20 8 81 1F Bank 3 18 SP 17 Bank 2 10 8 83 8 82 16 0F Bank 1 08 DPH DPL PC R7 07 Data Pointer R6 R5 8 80* 8 A0* R4 8 90* R3 3 P0 Latch P2 Latch P1 Latch R2 R1 00 R0 * => bit addressable Internal RAM
No Address
P3 Latch
8051
A Pin of Port 1
Read latch TB2 Vcc Load(L1) Internal CPU bus Write to latch
D Q
P1.X
Clk Q
P1.X pin M1
P1.x
A Pin of Port 0
Read latch TB2
P0.X
Clk Q
P0.X pin M1
P0.x
Using a quartz crystal oscillator g q y We can observe the frequency on the XTAL2 pin.
C2 33pF 33pF C1
XTAL2
XTAL1 GND
TMOD Register
Timer 1
Timer 0
Gate When t ti G t : Wh set, timer only runs while INT(0 1) is high. l hil INT(0,1) i hi h C/T : Counter/Timer select bit. 0 to set it in timer mode M1 : Mode bit 1. M0 : Mode bit 0.
TCON Register g
TF1: Timer 1 overflow flag. TR1: Timer 1 run control bit. TF0: Ti TF0 Timer 0 overflag. fl TR0: Timer 0 run control bit. IE1: External interrupt 1 edge flag. p g g IT1: External interrupt 1 type flag. IE0: External interrupt 0 edge flag. IT0: External interrupt 0 type flag. flag
EA : Global enable/disable. Gl b l bl /di bl --- : Undefined. ET2 :Enable Timer 2 interrupt. p ES :Enable Serial port interrupt. ET1 :Enable Timer 1 interrupt. EX1 :Enable External 1 interrupt. E ternal interr pt ET0 : Enable Timer 0 interrupt. EX0 : Enable External 0 interrupt.
Peripheral Architecture p
Peripheral Architecture p
Peripheral Architecture p
Input pins Address pins Add i ALE pin p SC pin Clock pin EOC pin
: 8 channels in multiplexed fashion : 3 address bits defines each input channels dd bi d fi hi h l : Latches the address bits : Instructs the ADC to start conversion : Provides clock input to the ADC : Low state on EOC indicates end of conversion
Peripheral Architecture p
Peripheral Architecture p
Peripheral Architecture p
o u t
re f
A M 2
S B
A 7 4
..........
A 2 4
A LSB 2 5 6
Problem Statement: State and Explain an algorithm for square wave generation
Interrupt
Time
Resource for time interval generation: Timer0 or Timer1 Design Issues: Mode of timer (16 or 8 bit) 8-bit) tim_mod .equal 02h mov TMOD, #tim_mod , Computation of content to be used for initialization of timer
12
Interrupt Interval:
;----------Basic time interval*tickN-----------sjmp back tm_1: dec ACC mov tick10,A back: pop PSW pop ACC reti
mov P1, #00h ; Set port1 as output Add Address V t i Vectoring .org 0 ajmp main j p .org 000bh ajmp TM0 ;jump to timer0 routine
Serial Communication
: Serial port mode bit 0 : Serial port mode bit 1 : Multiprocessor communication enable : Receiver enable. Set this bit to receive characters
t : Transmit bit 8 The 9th bit in case of mode 2 and 3 8.
: Receive bit 8. The 9th bit in case of mode 2 and 3 : Transmit flag. Set when a byte transmitted completely : Receive flag. Set when a byte transmitted completely
Serial Communication
SM0 0 0 1 1
SM1 0 1 0 1
Baud Rate fosc/12 B0 = Set by Timer 1/2 B1 = 2*B0 = Set by Timer 1/2 fosc/64 fosc/32 B0 = Set by Timer 1/2 B1 = 2*B0 = S t b Ti Set by Timer 1/2
Serial Communication
TH 1 256
f o sc B req 384
f o sc B req 192
TH 1 256
Serial Communication
Transmission
clr TI ; Clear the transmit flag
mov SBUF, #D ; Send letter D to transmit Loop: jnb TI , Loop ; Check for transmission over Reception p Loop: jnb RI , Loop ; Check for reception complete mov A SBUF ; R d received d A, Read i d data
Low Voltage Level (0) 0-Vcc/2 0-0.8V Transmission Low Voltage ( ) Level (0) (+5)- (+25)V
Reception Low Voltage ( ) Level (0) > (+3)V High Voltage ( ) Level (1) < (-3) V
Implementation p
Hardware: Universal Microcontroller Programmer Software: Assembler for 8051 Converts *.asm file to *.obj Linker for 8051 Links several *.obj files and converts the whole to *.hex Hex code downloader application program Provided with universal programmer Download the hex code into the microcontroller