micro c lab1(intro to 8051)
TRANSCRIPT
MicrocontrollersLab 1
INTRODUCTION TO THE CONTROLLER AT89C51 (8051)
Objectives of the LabTo learn the functionality of different ports and pins of 8051
µcontroller.
To discuss the circuits that make 8051 works.
To learn the ‘KEIL’ software to create a ‘HEX’ file for the
8051 controller.
Pins and Ports of 8051
Use withcaution
If EA high
Internal Block Diagram of 8051
Once Around the PinsPower: VCC,VSS (GND)Reset:RSTCrystal:XTAL1,2External Device Interfacing: EA,ALE,PSEN,WR,RDI/O Port: P0-P3 [7:0]P3: Shared with control lines: Serial RxD TxD, Counter
control T0, T1, External Interrupts INT0, INT1P0 and P2 are multiplexed with data bus.P1 can only be used as I/O port.
Circuits that make 8051 work
2 mc
Crystal Frequency and Machine CycleCrystal Frequency used is 11.0592MHz or 11059200 Hz.The oddball frequency is used to synchronize the serial baud
rates.At this frequency, the time period of one wave will be
1/11059200 seconds.The ‘time unit’ for 8051 is known as Machine Cycle.And one machine cycle equals 12 waves of crystal frequency.So the time period of 1 machine cycle will be 12 times the
time-period of one wave i.e. 12/11059200 secThis comes out to be approximately 1.085 µs.
Logic Levels & Ports for I/O OperationAlways write ‘high’ to ports for input
Program Structure (Directives)org 00h
Coding instructions here
delay: ;subroutine
ret
end
Registers (Naming) Normally UsedAccumulator (A or ACC) Base (B)Ports (P0,P1,P2,P3 & Px.y) PSW (For Flags & Register Banks)R0,R1,…,R7 SP(Stack Pointer)DPTR(Data Pointer) Timer RegistersSerial Port Registers Interrupt RegistersPCON (Power Control Register)
IP (Instruction Pointer)
Legend:* Frequently used* Special Functions* Occasionally* Used automatically
How to work with ‘KEIL’1. Locate the ‘Keil uVision2’ icon on the screen.
2. Run the program and go to Project>Close Project if a previous project file
is open otherwise go to Project> New Project.
3. The program will ask for the file name. Give any location in the directory
and write any program name you like. (Remember: Create a folder before
creating program)
4. After step 3, another window will open namely ‘Select Device for Target’.
Expand Atmel and click ‘AT89c51’. Also check ‘ Use extended linker
LX51 instead of BL51’ and click ‘OK’
How to work with ‘KEIL’5. Now create a new file. Go to File>New.
6. Save this file by any name but give the extension
‘.asm’ e.g. firstprog.asm.
7. On the leftmost side, expand ‘Target1’ to ‘Source
Group 1’. Right click on ‘Source Group1’ and select
‘Add files to Group’. A window will appear. Select
file type ‘Asm Source File’ and add the just made file
and close the window.
How to work with ‘KEIL’9. Now go to Project>Options for Target. A new window will
appear. On the ‘Target tab’, modify the xtal frequency to
11.0592. Then go to ‘Output tab’ and check ‘Create HEX File’.
10. Then write the code for the program. After writing code, save
it. Then go to Project>Build Target. In the lower box, if there
are no errors in the file, ‘creating hex file’ will be written. This
means the HEX file is created.
Lab TaskCreate HEX file of a blank program.