Microcontroller and Interfacing Microcontroller and Interfacing
Microcontroller and Interfacing Microcontroller and Interfacing
Contents:
Introductory Concept
- Introduction to Embedded System - Program writing, Compilation and simulation writing - Introduction to Top View Simulator
Basic inputs and outputs Interfacing Seven segment Display Keypad Interfacing Basics f B i of LCD and it interfacing d its i t f i Timer and Counter Serial Communications Interrupt Handling Introduction to Proteus
Samrat Subedi samratsubedi@gmail.com 2
Microprocessors:
General-purpose microprocessor
CPU for Computers No RAM, ROM, I/O on CPU chip itself ExampleIntels x86, Motorolas 680x0
Data Bus
RAM
ROM
I/O Port
Timer
Microcontroller :
A smaller computer On-chip RAM, ROM, I/O ports... ExampleMotorola s 6811, Intel s 8051, Zilog s ExampleMotorolas 6811 Intels 8051 Zilogs Z8 and PIC 16X
RAM ROM
A single chip g p
Serial Timer COM Port Microcontroller
Embedded System
Embedded system means the processor is embedded into that application. An embedded product uses a microprocessor or microcontroller to do one task only. onl In an embedded system, there is only one application software that is typically burned into ROM. Exampleprinter, keyboard, video game player
Block Diagram
External interrupts Interrupt Control On-chip ROM for program code
Timer/Counter
On-chip RAM
Timer 1 Timer 0
Counter p Inputs
OSC
Bus Control
4 I/O Ports
P0 P1 P2 P3
TxD RxD
Address/Data Add /D t
Samrat Subedi samratsubedi@gmail.com 10
11
8051
12
Feature of 8051
Eight bit CPU with register A and B 16 bit Program Counter bi P C Internal Ram of 128 bytes 4 Kb Flash Memory 4 I/O Ports Two 16 bit Timer (T0 and T1) Full duplex Serial Communication Six Interrupts
13
Vccpin 40 Vcc provides supply voltage to the chip. The voltage source is +5V. GNDpin 20ground XTAL1 and XTAL2pins 19,18
14
15
16
9 RST
17
D Latch:
22
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
P0.x
8051 IC
23
Vcc 1 0
M1 P1.X
Clk Q
P1.X pin
output 1
8051 IC
24
ground 0 1
M1 P1.X
Clk Q
P1.X pin
output 0
8051 IC
25
Q
P1.X 0 M1
P1.X pin
Write to latch
Clk
TB1 Read pin 3. Read p pin=1 Read latch=0 Write to latch=1 8051 IC Samrat Subedi samratsubedi@gmail.com 26
Q
P1.X 0 M1
P1.X pin
Write to latch
Clk
TB1 Read pin 3. Read p pin=1 Read latch=0 Write to latch=1 8051 IC Samrat Subedi samratsubedi@gmail.com 27
Other Pins
P1, P2, P1 P2 and P3 have internal pull up resisters pull-up resisters. P1, P2, and P3 are not open drain. P0 has no internal pull up resistors and does not pull-up connects to Vcc inside the 8051. P0 is open drain. Compare the figures of P1.X and P0.X. However, for a programmer, it is the same to program P0, P1, P2 and P3. d All the ports upon RESET are configured as output.
Samrat Subedi samratsubedi@gmail.com 28
A Pin of Port 0
Read latch TB2
P1.X
Clk Q
P0.X pin M1
P1.x
8051 IC
29
P0.0 DS5000 P0.1 P0.2 8751 P0.3 P0 3 P0.4 8951 P0.5 P0.6 P0.7 P0 7
Port 0
30
31
32
Registers g
A B R0 DPTR R1 R2 R3 R4 R5 R6 R7 Some 8-bitt Registers of the 8051 Some 8051 16-bit Register PC PC DPH DPL
33
8k
0000H 0000H
0FFFH
8751 AT89C51
34
30H 2FH Bit-Addressable RAM 20H 1FH 18H 17H 10H 0FH 08H 07H 00H Register Bank 2 (Stack) Register Bank 1 Register Bank 3
Register Bank 0 R i B k
35
36
Save as --
See here!!!
C:\ C:\program files\SDCC\bin>SDCC led.c files\SDCC\ led c
C:\ C: C \program fil \SDCC\bi packihx l d ih l d h files\ files SDCC\bin> bin>packihx led.ihx>led.hex kih you will See packihx: packihx: read 107 lines, wrote 58: OK. 58:
38
And then
39
40
41
42
43
44
45
Try this
#include<at89x51.h> #include<at89x51.h> h> void delay(int a) delay(int { float i; for (i=0;i<100*a ;i++ ); (i ;i<100*a ;i } void main() { char in=0x04; in=0 04; P0=in; while(1 while(1) { in++; delay(20); delay(20); P0=in; } }
46