Micro c lab3(ssd)
Transcript of Micro c lab3(ssd)
MicrocontrollersLab 3
DRIVING SSDs TO DISPLAY DATA USING 8051
Objectives of the LabGetting Introduced to PSW Register and Addressing Modes
Displaying data on SSDs using 8051 output ports.
Getting Introduced to Look-up tables
Implementing up/down counter from 00-99
Programming 8051 using Smart-PRO Burner. (Review)
Deciding Pins or Ports to use
Use withcaution
If EA high*We shall use P2 and P3.
Flags Register
Carry PSW.7 Holds carry after addition or borrow after subtraction.
Auxiliary PSW.6 Holds (half)carry after addition or borrow after subtraction b/w bit 3 &4.
-- PSW.5 Available to the user for General Purpose.
RS1 PSW.4 Register Bank Selector 1.
RS0 PSW.3 Register Bank Selector 0.
Overflow PSW.2 It is used to show if the result has exceeded the capacity of machine.
Parity PSW.0 Even Parity: If no. of ones odd, P=1, if even, P=0. (Only Accumulator)
Register Banks
(Selected by Default)Use setb and clr instructions to Select register banks.
Addressing ModesBefore learning to display data on SSD, it is required to
know about the 5 addressing modes used in 8051.1. Immediate Addressing: Move data directly to registers e.g.
MOV A,#25h2. Register Addressing: Move data in between registers e.g.
MOV A,R0; MOV R2,A; MOV R4,R7 is invalid.3. Direct Addressing: Move data from RAM locations e.g.
MOV R0,40h; MOV R4,7Fh; note the missing ‘#’ sign.4. Register Indirect Addressing: MOV A,@R0; move contents
of RAM location, the location is stored in R0.5. Indexed Addressing: Widely used to access data from look-
up tables e.g. MOVC A,@A+DPTR
Seven Segment Displays First, we decide whether to use Common Anode or
Common Cathode SSDs. The decision is a simple one: Since, 8051 is better at
sinking current than sourcing, we shall use CA SSDs. To drive a SSD, the common terminal will be tied with 5V
(CA) and the segment terminals will be joined to 8051 port pins via 470Ω resistors.
To turn on a segment, we will simply clear 8051 pin to ‘0’ and to turn off we will set 8051 pin to ‘1’.
LED displays are power hungry and pins hungry but are cheaper than LCD displays.
Displaying Data on CA SSDDigit Hexa Px.7 Px.6 Px.5 Px.4 Px.3 Px.2 Px.1 Px.0
X g f e d c b a0 C0 1 1 0 0 0 0 0 0
1 F9 1 1 1 1 1 0 0 1
2 A4 1 0 1 0 0 1 0 0
3 B0 1 0 1 1 0 0 0 0
4 99 1 0 0 1 1 0 0 1
5 92 1 0 0 1 0 0 1 0
6 82 1 0 0 0 0 0 1 0
7 F8 1 1 1 1 1 0 0 0
8 80 1 0 0 0 0 0 0 0
9 98 1 0 0 1 1 0 0 0
This table is for Common Anode. For Common Cathode, complement the values
Clear pin to ‘0’ to turn on, set pin to ‘1’ to turn off.
Algorithm for SSD CountingStart
First Digit to
Port
Call Delay
*Controller Programs tend to run forever i.e. in the infinite loop.
mov a,#0C0h
mov a,#98h
call delay
Call Delay
Last Digit to Port
call delay...
Too Complicated!! The above code looks simple but it creates a lot of
complication when it is incorporated with other applications. For Example, what if we have to write a code to count up to
00 to 99, then there is a lot of writing to do and memory to allot.
Take another example, what if we have to display a value e.g. temperature, then the process needs to be automated not manual.
But as we see there is no pattern between the data being sent to the port for even the adjacent numbers, e.g. the data for displaying ‘0’ is way different for displaying ‘1’.
Our Requirement: We need a code that would modify this non-pattern data into a pattern.
Look Up Tables The non-pattern data can be carved into a pattern using look up
tables, which are more understood as arrays. We can make look-up table (array) whose 1st entry contains the
1st non-pattern data element, 2nd entry contains the 2nd non-pattern data element and so on.
Now, on the first index of look-up data (array) is our first data, on 2nd index, we have the data we needed to come second and so on.
Remember the index starts from zero in µC. So, the data to display ‘zero’ on SSD is in zero index, to display
‘one’ on SSD is in 1st index and so on. What we need to know is how to make and access these look-up
tables.
Instructions used in this LabMOVC A,@A+DPTR (Explanation during example code)CJNE REG,DATA,LABEL (See instruction set)INC DPTR (dptr can’t be decremented)INCDECSee instruction set for the details of above commands.
Making and using Look-up TablesThere are two techniques to make look-up tables.table: db 11000000b
db 111111001b …
table: db 0C0h,0F9h,0A4h,0B0h,099h,092h,082h,0F8h, 080h,098h.
mov dptr,#table; labelmov a,#0movc a,@a+dptrinc a; then loop these 4 instructions till the last entry.
Index 0 1 2 3 4 5 6 7 8 9
Data 0C0h 0F9h 0A4h 0B0h 099h 092h 082h 0F8h 080h 098h
ReviewProgram Structure (Directives)org 00h...call delay...
delay: ;subroutine...retend
Example code (0-9)mov dptr,#tablemain: mov r1,#0loop1: mov a,r1movc a,@a+dptrmov p1,ainc r1call delaycjne r1,#10,loop1jmp maintable: db 0C0h,0F9h,0A4h,0B0h,099h,092h,082h,0F8h,
080h,098h.Index 0 1 2 3 4 5 6 7 8 9
Data 0C0h 0F9h 0A4h 0B0h 099h 092h 082h 0F8h 080h 098h
Using Proteus to simulate 8051 codes1. The ‘HEX’ file generated by ‘keil’ or any other software as such can be
used to check the working of code on software using proteus.
2. Just search for ‘AT89c51’, place the controller, double click on it to edit
properties
1. Change the clock frequency to 11.0592 MHz.
2. Click the ‘folder icon’ in front of Program files and locate the code hex file.
3. In advanced properties, select ‘Simulate Program Fetches’ and ‘Yes’.
3. Then, place other devices, interconnect with 8051 and simply play the
simulation.
How to program a µC using SmartPro 2008 (Programmer)
1. Connect your SmartPro 2008 Programmer to PC via
USB port and turn the device on using its adapter. Also,
place the µC carefully in the ZIF socket.
2. Locate and click ‘SmartPro 2008’ icon available on
desktop.
3. If it asks for the Programmer Select ‘Smart PRO 5000u’
and click demo.*One must check, how to place different types of controller in the programmer.
How to program a µC using SmartPro 2008 (Programmer)4. Click ‘Select Device’ on the window or choose Device>Select or
press Ctrl+S.
1. In ‘Type’, select ‘MCU’
2. In ‘Manufacturer’, select ‘ATMEL’ , AT89Cxx.
3. In ‘Device’, select AT8951.
5. Now, select File>Open or press Ctrl+O, in ‘files of type’ select
Intel Hex and locate the ‘HEX’ file you want to program. Also,
see if buffer is loaded with the new ‘HEX’ file.
How to program a µC using SmartPro 2008 (Programmer)6. Now, there are a bunch of options that can be performed depending upon the
users needs.
1. F4 or Click ‘Read’: Reads a previous program already burned in the µC.
2. F5 or ‘Erase’: Erases the previous program in µC.
3. F6 or ‘Blank Check’: Verification if program is erased.
4. F7 or ‘Program’: Loads the *current HEX file in µC.
5. F8 or ‘Verify’: Verification if the program is properly loaded.
6. ‘Batch’: This option is used in Industry.
7. Spacebar or ‘Auto’: Performs all the steps from 2 to 5 in sequence.
7. Shortcut: Open SmartPro, slect device, locate hex file & press spacebar.
Debugging with µC1. Unlike electronic circuits, the debugging with µC is different. Firstly,
there is software debugging and then there is hardware debugging.
2. The software debugging includes the working of code.
3. The hardware debugging includes the working of code on hardware
and the devices interfaced.
4. Always perform µC experiment in three stages, test the µC IC and
generic board using led blinking, then verify the working of code on
Proteus software, then finally test the program on hardware.
Proteus Devices needed in this Lab1. AT89c51
2. CA SSD
Lab TasksShow counting on SSD’s in following patterns
with delay of 500 milli-seconds.Pattern 1: Show count from 0-9.Pattern 2: Show count from 9-0.Pattern 3: Show count from 00-99.Pattern 4: Show count from 99-00.Quiz next week: (all material in LED and SSD slide + codes)