Docstoc

Temperature and Humidity Meter _THM_

Document Sample
Temperature and Humidity Meter _THM_ Powered By Docstoc
					                      CMCKIT
Atmel CISC Microcontroller Trainer/Writer Kit
      Technical Reference Manual

    Designed, Developed and Built in Bangladesh by the Author




                    RS232-to-USB Converter     Common Cathode 7-Segment Display Devices

                    IBMPC Communication MCU

                                              2x16 Character LCD   Humidity-Temp Sensor
                       Target 89S52 MCU

                           Real Time Clock Chip                                    4 – Channel Serial ADC




                                                                                          1500x.vsd: 4-11: GM




                 Golam Mostafa
Ahsanullah University of Science and Technology
 M-01726341559, Email: mostafgab@yahoo.com, Web: www.krdcbd.com




                                          1
A: Check List
Check that the CMCKIT package contains the following items:
    1. CMCKIT as depicted on the cover page of this book.
    2. A 4-channel serial ADC (ADC0834) placed on the breadboard of the CMCKIT.
    3. A 2x16-Charcater LCD Panel and is placed on the breadboard of the CMCKIT.
    4. A Real Time Clock Chip (DDS12C887) placed on the breadboard of the CMCKIT.
    5. 12 Nos. Common Cathode Type 7-Segment Display Devices placed on the breadboard
         of the CMCKIT.
    6. One Nose Pliers.
    7. One Electronic Cutter.
    8. Handsome amount of jumper wires.
    9. One anti-cutter.
    10. One brush.
    11. 1.5k resistors (5).
    12. 3.3 resistor (5)
    13. 100k resistor (5)
    14. 47 uF capacitor (5)
    15. 100 uF capacitor (5)
    16. 0.1 uF capacitor (5)
    17. 10k resistor (5)
    18. Green LED (5)
    19. Red LED (5)
    20. One Text/Reference Book on 8051 Microcontroller
    21. One DVD Disk

B:   Installation Procedures of the CMCKIT
1.   Check that your IBMPC is running under WINXP or Win7 operating system.
2.   Copy the DVD contents under CMCKIT folder of your D-drive.
3.   If your CMCKIT is provided with a Black-covered RS232 ↔ USB converter cable, then
     follow the steps under 3a; otherwise (for Blue-covered) follow steps under 3b.
     3a:
     a. Goto the following application and install it by double click:
           D:\CMCKIT\USBRS232-Prolific\PL-2302(USBRS232)\PL2303(USBRS232)\XP\PL-
           2303 Driver Installer \PL-2303 Driver Installer.exe
     b. Goto Step 4.
     3b:
     a. Goto the following application and install it by double click:
           D:\CMCKIT\USB232\R340\SETUP.EXE.
     b. Goto Step 4.
4.   Engage the USB-connector of the RS232 ↔ USB converter cable into a USB port of the
     IBMPC.
5.   Check that the cable is detected and a pop-up (if you are going to install the cable for the
     first time) menu would appear. Follow the menu to have some software being installed
     automatically.
6.   Click on : start →My Computer → Properties → Hardware → Device Manager → Ports →
     Serial Com Port → Properties → Port Settings → Advanced → Com Port Number to 3.

                                               2
7.       Install the Interface Package CMCKITVCOM3 from the following path:
         D:\CMCKIT\CMCKIT VCOM3.

C:       Components Layout Diagram of the CMCKIT

                                         LEDR1                 U2           LDG                 LEDR2            U3                    C3
                                                                                          P2                                  P3             1
                                                                                   1            P10                     +5V             40
                                                         P10
                                                                                   2            P11                     P00             39




                                                                                                                                                       RN2: 8x4k7
          P4                        C10                                            3            P12                     P01             38
               D1
                                                                                   4            P13                     P02             37
     1
               D2                                                                  5            P14                     P03             36
     2
                                                                                   6            P15                     P04             35
     3                        C11
                                                          Master                   7            P16                     P05             34
                                                   Q1
                              C12
                                                           MCU                     8            P17                     P06             33
                     U4
                                                                                   9            RST                     P07             32
                    7805
                                            R2
                                   R1




                                                                                  10            P30    Target           +5V             31
          P1                                                                      11            P31 (Slave MCU)         ALE             30
                      C5
                                                                                  12            P32                     P27             29
                                                  50Hz
                                   P5




                      C6                                                          13            P33    89S51            P27             28
                                                                                  14            P34    89S52            P26             27
                      C7




                                                                                                                                                 RN1: 8x1k
                                                                                  15            P35   89S8252           P25             26
                      C4                                                                        P36 ATmega8             P24             25
                            U1

                                        MAX232




                                                                              Y2

                                                                                                P37 ATmega16            P23             24
                     SW1
                                                                                                XT2 Atmega32            P22             23
                                                                                                XT1                     P21             22
                                                                                   20           GND                     P20             21
                                                                                                                                             1
                                        R3                     Y1              R4
                                                                            C9 R5                              R6     Q3
                                                                                                     Q2                      +5V
                                          C8
                     1503


                                                 Figure-1 : Components Layout of the CMCKIT


         IBMPC              P1                    U1: MAX232                      U2: 89S52                                 U3: 89S52 (Target)

                                                                                  MOSI(P15)                                      MOSI (P15)
                                                                                  MISO (P16)                                     MISO (P16)
                            TxRS                  RxRS RxTTL                RxTTL SCK(P17)                                       SCK (P17)
                            RxRS                  TxRS TxTTL                TxTTL            +5V
                                                                                                            R5         R6                   P10
                            COM                   COM    COM                COM                            4k7        1k5
                                                                                                                                 RST/                   Rx
                                                                SW1                                   R4 1k5
                                                                            RST
                                                                                         RST/(P14)                                                     1k5
                                                                                  P10                                            XT1         XT2
                                                                                                               Q2           Q3
                    USB ß---- > RS232 RS232 ß-> TTL                                                                   C9 C828            Y2
                                                                                        LEDR1                  C828
                       Converter        Converter                     +5V                                 0V          100uF                      LEDR2
 isp
                                                 Figure-2: Hardware Block Diagram of CMCKIT
                                                                             3
                                                                                                                                        U2                                     R8                                        J2                U3                             P3      J3
                                                                                                                                                                      VCC      1k5    LDG
                                                                                                                                   39                            40                                                                                                                               VCC
                                                                                                                                   38    P0.0/AD0        VCC                                                    P10                    1                             40                    Vc c
                                                                                                                                   37    P0.1/AD1                            C2                                               1             P1.0/T2           VCC         1        1
                                                                  U1                                                               36    P0.2/AD2            20              0.1uF                       1k5    P11                    2                             39                    P00          C2




                                                                             10
                                                                             7

                                                                             9
                                                                             8
                                 P1                                                                         C1                     35    P0.3/AD3        GND 31                             LDR2         R7                   2             P1.1/T2-EX    P0.0/AD0        2        2                    0.1uF
                                                                                                          0.1uF                    34    P0.4/AD4     EA/VPP 29                                                 P12                    3                             38                    P01




                                                                                T2IN

                                                                                R2 IN
                                                                              R2 OUT
                                                                              T2OUT
       GND                 5                                15                                       16                            33    P0.5/AD5       PSEN 30                                                               3             P1.2          P0.1/AD1        3        3
                           9                                      GND                         VCC                                  32    P0.6/AD6   ALE/PROG                                                    P13                    4                             37                    P02
                           4                         C4                                                     C6                           P0.7/AD7                                                                             4             P1.3          P0.2/AD2        4        4
       ---->               8                         iuF                                                    1uF                                                                                                 P14                    5                             36                    P03
       RxRS                3                                  6                                      2                                                                                                                        5             P1.4          P0.3/AD3        5        5
                           7                                      V-                           V+                                                                6 MOSI                                         P15                    6                             35                    P04
       TxRS                2                                13                                       12                            10                    P1.5                                                                 6             P1.5          P0.4/AD4        6        6
                           6                                      R1IN                   R1OUT                                           P3.0/RXD                7 MISO                                         P16                    7                             34                    P05
       ---->
                           1                                                                                                                             P1.6                                                                 7             P1.6          P0.5/AD5        7        7
                                                                                                                                                                 8 SCK                                          P17                    8                             33                    P06
                                                            14                                       11                            11                    P1.7                                                                 8             P1.7          P0.6/AD6        8        8
                                                                  T1OUT                       T1IN                                       P3.1/TXD                            VCC
                                                                                                                                                                 5 SRST                                         SRST                   9                             32                    P07
                          CONNECTOR DB9                       1                                      4                                                   P1.4                                          R6                     9             RST           P0.7/AD7        9        9
                                                                  C+                          C2+                       VCC                                      17                                    1k5        P30                 10                             31                    Vc c
                                                     C5                                               C7                                              P3.7/RD    16                       R5                             10                 P3.0/RXD       EA/VPP         10      10
                       HEADER 3 P4                   iuF                                              1uF                     C8                      P3.6/WR    15                       4k7                     P31                 11                             30                    ALE




                                                                                                                                                                                                         2
                                                              3                                      5                        100uF                    P3.5/T1   13                                                      11                 P3.1/TXD     ALE/PROG         11      11
                                 1                                C1-                         C2-                                                    P3.3/INT1   12                                3         Q3   P32                 12                             29                    PSEN/
                                 2                                                                                                                  P3.2/INTO    4                                           C828        12                 P3.2/INTO        PSEN         12      12




                                                                                                                                                                                             2
                                 3                              MAX232                               1              2               9                     P1.3   3           R4                                   P33                 13                             28                    P27
                                                                                                                                         RST              P1.2   2                    3                                  13                 P3.3/INT1     P2.7/A15        13      13




                                                                                                                                                                                                         1
                                                           U4                                                                                       P1.1/T2-EX
             T1                  D1 ! N4007                LM7805/TO                                 SW 1 MRST                R3                                                                   C9             P34                 14                             27                    P26
      L 1          4        9V                        1                                   2                                   4k7                                            4k7     Q3            100uF                 14                 P3.4/TO       P2.6/A14        14      14
                                                           VIN                VOUT                          VCC                                                                                                   P35                                                                      P25
                                                                                                                                                                 28                  C828                                             15                             26




                                                                                                                                                                                             1
     220V                   0V                                                                                                                       P2.7/A15    27                                                      15                 P3.5/T1       P2.5/A13        15      15
                                                                   GND




                                                                                                                                                     P2.6/A14                                                     P36                                                                      P24
                                 D2 IN4007 C10                                            C11               0.1uF                                                26                                                                   16                             25
      N 3          6        9V                                                                              C12                    14                P2.5/A13    25                                                      16                 P3.6/WR       P2.4/A12        16      16
                                           2200uF                                        220uF                                           P3.4/TO     P2.4/A12    24                                               P37                 17                             24                    P23
     220V/9-0-9V                                                                                                                                     P2.3/A11    23                   11.0592MHz                         17                 P3.7/RD       P2.3/A11        17      17
                                                                  3




                                                                                                                                   18                P2.2/A10    22                                               XT 2                18                             23                    P22
                                                                                                                                         XT AL2       P2.1/A9    21                         Y2                           18                 XT AL2        P2.2/A10        18      18
                                                                       VCC                                                                            P2.0/A8
                                                                                20mS Pulse                                    Y1                                                                                  XT 1                19                             22                    P21
                                                 2




                                 R1 1k5                                                                                                                                     LDR1                                         19                 XT AL1         P2.1/A9        19      19
                                           3         R2 1k5              P5          J5                                            19                            1                                                                    20                             21                    P20
                                                                                                                                         XT AL1       P1.0/T2                                                            20                 GND            P2.0/A8        20      20
                                          Q3                             1           1                            11.0592MHz                                                1091M
                                          C828                           2           2
                                                 1




                                                                         CON2        CON2                                               AT 89C52                                                                              CON20        AT 89S52                       CON20    CON20




                                                                                                          Figure-3: Schematic Diagram of CMCKIT

D: Testing of the CMCKIT
Carry out the following steps to check that the CMCKIT is working. The working condition will
be exhibited by having the LEDR2 (Fig-1, 2, 3) blinking continuously.
1.                Apply power to the CMCKIT. Press the switch SW1 (Fig-1) until LEDR1 (fig-1) comes ON.
3.                Engage the USB connector of the CMCKIT into a USB port of the IBMPC and follow step B6.
4.                From start icon, execute the package CMCKITVCOM3 to launch the following Interface.




                                                                                                                                                                       4
5.   Follow the menu to select. Erase the target MCU chip (Fig-1, U3).
6.   Follow the menu to download (fuse = permanent storage) the program codes of the
     following file into the Code Memory of the target MCU.
     D:\CMCKIT\ledp10-0030.hex
7.   If the downloaded program is not running (meaning that the LEDR2 is not blinking), then
     take a jumper wire and connect the RST-pin of U3 to ground (short: P2-9 to P2-20).

E: Performing Experiments
E1: Experiment-1 [Driving LED, exp1.asm]
To blink LEDR2 (Fig-1) only for 5 times.
Procedures:
1. Convert the following Pseudo Codes into 8051 ASM Codes and save the program as:
    D:\CMCKIT\exp-E1.asm.

              ORG      0000H
              LJMP     0030H

              ORG      0030H
     START:   NOP

     L1:      LCALL    INITMCU        ; initialize MCU by setting up Stack and Bank

     L2:      05H → Counter           ; 5 times to blink

     L3:      LH → P1,0               ; ON LEDR2
              Time Delay              ; calling Time Delay Subroutine (TDEL)

     L4:      LL → P1.0               : OFF LEDR2
              Time Delay

     L5:      Counter – 1 → Counter

     L6:      if (Counter !=0)
                  Goto L3

     L7:      Halt

     INITMCU:
             MOV       SP, #70H       ; Stack Top begins at IRAM location 70H
             MOV       PSW, #00H      ; working Bank-0
             RET

     TDEL:    MOV      R7,   #0FFH
     AGN2:    MOV      R6,   #0FFH
     AGN1:    DJNZ     R6,   AGN1
              DJNZ     R7,   AGN2
              RET

              END
2.   Download D:\CMCKIT\exp1.exe into the code memory of the target MCU U3.
3.   Check that LEDR2 blinks for only 5 times.
E2: Experiment-2 [save as D:\cmckit\exp-E2.asm]
Write a program so that the LEDR2 of Experiment-1 blinks approximately at 1-sec interval.
E3: Experiment-3 [Draw Flow Chart for the program exp-E1.asm]
                                               5
                                    START:      NOP

                                    L1:
                                       Initialization:
                                       Bank, Stack, Counter

                                    L2:

                                             ON LEDR2

                                    L2A:

                                             Time Delay                   TDEL

                                   L3:

                                             OFF LEDR2

                                    L3A:

                                             Time Delay                   TDEL

                                    L4:

                                          Decrement Counter


                                   N
                                             Counter=0
                                                ?
                                    L5:                   Y

                                                    End
                                                                            1601


E4: Experiment-2 [Driving 7SDD, exp-E4.asm]
In this experiment we will be learning to display a character A on one of the 7SDD (7-Segment
Display Devices) that are placed on the breadboard of the CMCKIT. The leftmost 7SDD is
designated as DP0 (Display Device No 0), next one as DP1 and so on.

Procedures:
1. Use jumper wires and connect the segment pins and CC-pin of DP0 with to comply with the
    following circuit.
                                              +5V
                                                                   DP0
                                            RN1 : 8x1k

                                                           5   p
                                             P2.7
                                                          10   g
                                             P2.6
                                                           9   f
                                             P2.5
                                                           1   e
                                             P2.4
                                                           2   d
                                             P2.3
                                                           4   c
                                             P2.2
                                                           6   b
                                             P2.1
                                                           7   a
                                             P2.0
                                                                    cc0
                                                                   3
                                             P1.1


    Figure-5: Schematic Diagram of the connection of a 7SDD with Port-2 of 89S52 MCU of CMCKIT



                                                      6
2.   Assemble, download and execute the following program (D:\cmckit\exp-E2.asm)

              ORG      0000H
              LJMP     0030H

              ORG      0030H
     START:   NOP

     L1:      LCALL    INITMCU               ; initialize MCU by setting up Stack and Bank

     L2:      MOV      P2, CC_A              ; CC-code of A is sent to Port-2
              CLR      P1.1                  ; LL is put at cc0-pin of DP0
     L3:      LJMP     L3                    ; loop here; 8051 has no halt instruction

     INITMCU:
             MOV       SP, #70H              ; Stack Top begins at IRAM location 70H
             MOV       PSW, #00H             ; working Bank-0
             RET

              END

E5: Experiment-E5
Modify program exp-E2.am to show character 5 at DP0-position (save as d:\cmckit\exp-E5.asm).

E6: Experiment-E6 [Driving two 7SDD on Time Multiplex, save as d:\cmckit\exp-E6.asm]
In this experiment we will be adding two hex numbers (say, 69H and 21H) and will show the
result at <DP0, DP1> positions of the display unit.

Procedures:
1. Use jumper wires and connect the segment pins and CC-pin of DP0, DP1 with to comply
    with the following circuit.
                                  +5V
                                                      DP0                 DP1
                                RN1 : 8x1k

                                              5   p               5   p
                                 P2.7
                                             10   g              10   g
                                 P2.6
                                              9   f               9   f
                                 P2.5
                                              1   e               1   e
                                 P2.4
                                              2   d               2   d
                                 P2.3
                                              4   c               4   c
                                 P2.2
                                              6   b               6   b
                                 P2.1
                                              7   a               7   a
                                 P2.0
                                                       cc0                 cc1
                                                      3                   3
                                 P1.1
                                 P1.2

                            Figure-6: Driving Two 7SDD on Time Multiplex

2.   Assemble, download and execute the following program (save as d:\cmckit\exp-E3.asm).

              ORG      0000H
              LJMP     0030H

              ORG      0030H
     START:   NOP

     L1:      MOV      SP, #70H              ; initialize MCU by setting up Stack and Bank
              MOV      PSW, #00H             ;


                                                             7
L2:     LCALL   INITLUT       ; initialize Lookup Table to convert hex → CC

L3:     MOV     A, #69H       ; 1st hex number
        ADD     A, #21H       ; adding the 2nd hex number;

L4:     LCALL   HEX2CC        ; convert hex to CC; result in <R3,R2> register

L5:     MOV     P2, R3        ; show 1st digit of result – 8
        CLR     P1.1          ; cc0 is LL
        SETB    P1.2          ; cc1 is LH
        LCALL   TDEL
        MOV     P2, R2        ;   show 2nd digit of result - A
        SETB    P1.1          ;   DP0 is OFF
        CLR     P1.2          ;   DP1 is ON
        LCALL   TDEL          ;   inserting Time delay. Why?

L6:     LJMP    L5            ; refresh display to prevent from being frozen

INITLUT:
        MOV     40H, #3FH   ;     cc-code of digit-00
        MOV     41H, #06H   ;     1
        MOV     42H, #5BH   ;     2
        MOV     43H, #4FH   ;     3
        MOV     44H, #66H   ;     4
        MOV     45H, #6DH   ;     5
        MOV     46H, #7DH   ;     6
        MOV     47H, #07H   ;     7
        MOV     48H, #7FH   ;     8
        MOV     49H, #6FH   ;     9
        MOV     4AH, #77H   ;     A
        MOV     4BH, #7CH   ;     B
        MOV     4CH, #39H   ;     C
        MOV     4DH, #5EH   ;     D
        MOV     4EH, #79H   ;     E
        MOV     4FH, #71H   ;     cc-code of digit-F
        RET
HEX2CC: ; input 8-bit data is     passed via A-register
        ; output cc-codes are     passed via <R3, R2> registers

        MOV     B, A        ; temporary storage; say A = 8A
        ;--- extracting 8 from 8A---------------------
        SWAP    A           ; A = A8
        ANL     A, #0FH     ; A = 08
        ;--- collecting CC-code of 8 (= 7F) from LUT—
        ADD     A, #40H     ; adding base address of LUT
        MOV     R0, A       ; passing A into R0-pointer
        MOV     A, @R0      ; collecting &FH from LUT = the CC-code of 8
        MOV     R3, R2
        ;----- collect CC-code of A-----
        MOV     A, B
        ANL     A, #0FH
        ADD     A, #40H
        MOV     R0, A
        MOV     A, @R0
        MOV     R2, A       ; cc-code of A is passed into R2 register
        ;----------------------------------
        RET
;--------------------------------------------------------------------------

TDEL:   MOV     R7,   #20HH
AGN2:   MOV     R6,   #20HH
AGN1:   DJNZ    R6,   AGN1
        DJNZ    R7,   AGN2
                                       8
               RET
       ;--------------------------------------------------------------------------
               END

E7: Experiment-E7 [Creating CC-codes for the digits 0-F]
Draw internal architecture of a CC7SDD and then fill in the gaps of the following Table for all the
digits 0 - F

 Digit    Segment Format of Digit                     Segments of the Digit                   CC-code in Hex Format
                                                        p g f e d c b a
 0
 1
 ------   ---------------------------------       ------------------------------------   ------------------------------------
 F

Ans:
Architecture of CC-type 7-Segment Display Device (CC7SDD)

           a          p                  a    f   a                p                a    b    c   d   e   f   g   p
   a                                                       b
                       g                 b                         g
   b             b
     f     g                         cc
  cc                   cc                                          cc
                                                  g        c   p
   c             c      f                c e                       f
     e
   d              p     e            d                             e                                                  cc
           d                                      d       26-00a                   26-00a
    (a) Physical View                    (b) Internal Structure                              (c) Schematic Diagram

                  Figure-4.4: Structure of Common Cathode type 7-Segment Display Device

There are eight Light Emitting Diodes (LEDs), which are known as segment-a, segment-b,
segment-c, segment-d, segment-e, segment-f, segment-g and segment-p. The cathodes of the
segments are shorted together.

The anodes of the segments are available to the user via the external metallic pins of the device.
There are eight segments in a device, but it is commonly known as 7-segment device. It is due to
the fact that the p-segment has the infrequent usage.

A segment emits ‗good amount of light‘ when it conducts about 20mA current and experiences a
voltage drop of 1.2V. For safe operation (avoiding the burn out of the segment) of the device
using +5V, appropriate current limiting resistor must be used in series with the LED so that
conduction current doesn‘t exceed 20mA.

Common Cathode (CC) and CA (Common Anode) Codes for the Characters 0-F
Character  CC-Segments ON Binary Format CC-code      Hex Format CC-code                                               CA-code
0          pgfedcba         00111111                 3FH                                                              C0H
1          pgfedcba         00000110                 06H                                                              F9H
2          pgfedcba         01011011                 5BH                                                              A4H
3          pgfedcba         01001111                 4FH                                                              B0H
                                                               9
4             pgfedcba                01100110                       66H                           99H
5             pgfedcba                01101101                       6DH                           92H
6             pgfedcba                01111101                       7DH                           82H
7             pgfedcba                00000111                       07H                           F8H
8             pgfedcba                01111111                       7FH                           80H
9             pgfedcba                01101111                       6FH                           90H
A             pgfedcba                01110111                       77H                           88H
B (b)         pgfedcba                01111100                       7CH                           83H
C             pgfedcba                00111001                       39H                           C6H
D (d)         pgfedcba                01011110                       5EH                           A1H
E             pgfedcba                01111001                       79H                           86H
F             pgfedcba                01110001                       71H                           8EH

E8: Experiment-E8 [Understanding Non Multiplexed (dedicated) Display System]
                      +5V

                                          RN1                                      RN2
             89S52                        8x1k                                     8x1k
                                                          DPA                                  DPB

                     P0

                     P07                         p                                        p

                     P06                         g                                        g

                     P05                         f                                        f

                     P04                         e                                        e

                     P03                         d                                        d

                     P02                         c                                        c

                     P01                         b                                        b

                     P00                         a                                        a
                                                          ccA                                      ccB



                                                     0V                                       0V




                     P2
                     P27

                     P26

                     P25

                     P24

                     P23

                     P22

                     P21

                     P20




                                                                                              1598 : 2009 : GM



                            Figure-4.5: Dedicated Non-multiplexed Display System

The display system of Fig-4.5 is an example of a non-multiplexed display system. The word non-
multiplexed refers to the fact that ‗no two‘ display devices share common IO lines for data
transfer. In this type of display, every digit is separately connected with the MCU ports.
In Fig-4.5, the device DPA is connected with the P0-port using the P00 – P07 IO lines. The device
DPB is connected with the P2-port using the P20 - 27 IO lines. The devices are separately
connected with the ports. The cc-points of the devices are grounded.
There are advantages of the non-multiplexed display system, which are:



                                                      10
       a.         After writing data into the ports, the MCU is not required to take care of them. Because,
                  the data are written into latches (the Ports are D Flip flops), the meaning if the data are
                  always visible on the output devices.
       b.         The MCU may engage to some other jobs.
       c.         The segments of the display devices continuously sink currents. So, there is absolutely
                  no chance of flickering.
The disadvantages are:
    a. Wastage of microcontroller ports, which are considered as ‘useful resources’ from the
         point of view single-chip design.
    b. More wiring that makes the system costly and less immune to noise.
The following are the 8051 ASM codes to show the characters 6 and A on the CC7SDD devices of
Fig-4.5:
                  MOV              P0, #7DH                  ; 7DH is the cc-code for the character 6
                  MOV              P2, #77H                  ; 77H is the cc-code for the character A

E9: Experiment-E9 [Understanding Multiplexed Display System]
Working Principles
The word ‘time-multiplexed’ refers to the fact that ‗any two or more‘ display devices can share
common IO lines to have connection with the microcontroller ports for data reception of their
own. This means that the devices can receive and show different data though they share common
IO lines. The system of Fig-4.6 is an example of a time-multiplexed display system. The schematic
is made based on the AMCKIT-A so that an interested reader can test it using the AMCKIT.
                                           +5V

                                                                   RN1
                                    89S52 MCU                      8x1k
                      Y1 = 12MHz
                                                                                  DP0   DP1   DP2 ------------------------- DPD   DPE       DPF
             +5V                           P2
                                   X2
                                                 P2.7                     5   p                                                         p
   RST                                           P2.6                    10   g                                                         g
                                                 P2.5                     9   f                                                         f
                   C1              X1
                                                 P2.4                     1   e                                                         e
                   100uF
                                                 P2.3                     2   d                                                         d
                                   RST
                                                 P2.2                     4   c                                                         c
                                                 P2.1                     6   b                                                         b
            R1
                                                 P2.0                     7   a                                                         a
            4k7
                                                                                  ccE   cc1                                       ccE       ccF
                                                                                  3     3                                         3         3
                      0V                                4-to-16 Decoder
                                   GND                     2x74LS138
                      +5V
                                   Vcc
                                   EA/                             S0/
                                                                   S1/
                                          P1
                                               P1.4      D
                                               P1.3      C
                                               P1.2      B
                                          P1.1 P1.1      A         SE/
                                                                   SF/

 1602 : JM: 11-2009
                                         U1                   U2

                                         Figure-4.6: Dedicated Non-multiplexed Display System

There are 16 cc-type seven-segment display devices (CC7SDD), DP0-DP15. The identical segment
pins of all the devices are connected together, which means that the segment-a pins of all the
devices are joined together; segment-b pins are joined together and so on. Finally, there are only
eight pins instead of 128 (8x16) , which are connected with port P2 of the MCU using 8 IO lines.


                                                                              11
The cc-pins of the display devices are separately driven by the active-low outputs of a 4-to-16
decoder. The outputs of the decoder assumes LL-states in succession (S0/, S1/, … , SD/, SE/,
SF/, S0/…) as the input pattern cycles through the states 0000, 0001, …. 1110, 1111, 0000 This
arrangement allows a particular device to remain ON for sometimes while all other devices
remain OFF. This is the ‗working principles‘ of the time-multiplexed display system.

Let us wish to see simultaneously the character 6 at DP0-position and the character A at DPF-
position of the display unit of Fig-4.6. We can make it happening in the following way:
a.    Write the pattern 0111 1101 (7DH, cc-code of character 6) on P2, which will simultaneously appear to
      all the devices of the display unit. But, we want to see it at DP0-position only.
b.    Next send the pattern 0000 on P1.1-P1.4 pins of P1. As a result, the S0/-pin of the decoder will be at LL
      and S1/ - SF/ be at LH-states. The device DP0 becomes ON and we will see character 6.
c.    After a while (say after 10S), let us write the pattern 0000 0111 (07H, cc-code of A) on P2 and send the
      pattern 1111 to the input of the decoder. As a result, DP0 is OFF and DPF is ON. We will see character
      A at DPF-position and nothing at DP0—position.
d.    Wait for 10S and then goto to Step-a. We will again see character 6 at DP0-position and nothing at
      DPF-position. After a 10S delay, Step-c will be executed and we will see the character A at DPF.
e.    The cycle is repeated at 100 KHz (1/10S) and both characters appeared to be present simultaneously.

Assembly Codes:
L1:        MOV        P2, CC6          ; CC6 = cc-code of character 6
           CLR        P1.4
           CLR        P1.3
           CLR        P1.2
           CLR        P1.1             ; cc0-pin is made LL
           LCALL      TDEL10           ; 10S time delay
L2:        MOV        P2, CCA          ; CCA = cc-code of character A
           SETB       P1.4
           SETB       P1.3
           SETB       P1.2
           SETB       P1.1             ; ccF-pin is made LL
           LCALL      TDEL10           ; 10S time delay
L3:     LJMP    L1
;------------------------------------------------

Advantages of Time Multiplexed Display System:
The following advantages are experienced in a time-multiplexed display system:
a. Savings if many port pins, which could be used for other purposes.
b. Facilitates MCU-based system design using less parts counts.
c. Low cost and relatively reliable single chip solution.
Disadvantages of Time Multiplexed Display System:
The following disadvantages are associated with time-multiplexed display system:
a. The MCU spends a considerable amount of time in refreshing the display system to prevent
     flickering and data lock up.
b. Difficult to serve real time vectored interrupts.
c. The MCU may be required to serve all other available services including the interrupts by
     polling methods.


                                                      12
Recommended Data Structure and Algorithm for Code Conversion and Display

                      DP0       DP1                                                                   DPE     DPF

                                                                                                                          CC7SDD
                                                                                                                            Unit
     Multiplexed                                                                                               ccF
                      cc0       cc1                                                                   ccE
      CC-code


                      S0/       S1/                            CCX7SDD                                SE/      SF/
                                                                                          DPE
                     P2                     DP0   DP1
                                  DP0-DPF                            DP0-DPF            DPF




                                                                 DP0-DPF

                                                                                                                          CC-Code
                     DP0    DP1                                                                         DPE    DPF
                                                                                                                            Table
                                                                                                                           (CCCT)
     Internal RAM    30H    31H                                                                         3EH    3FH
                                                                                                                           Internal RAM
                                                                                                                                CC-Code
                                                                                                             LUT
                                                                                                                     40    CC-0
                                                                                                             Digit
                                                                HEX2CC                                        Vs
                                                                                                            CCcode
                                                                                                                     4F    CC-F




                                                                                                                            Hex
                      DP0DP1          DP2DP3       DP4DP5     DP6DP7    DP8DP9   DPADPB       DPCDPD        DPEDPF         Table
      Input
                                                                                                                          (HEXT)
     Internal RAM         50H          51H              52H    53H        54H     55H           56H            57H
 52x : GM: 2011



                    Figure-4.7: Recommended Data Structure for 16-digit Multiplexed Display System

Working Principles:
An input data from one byte to eight byte (00H/FFH – 0000000000000000H/FFFFFFFFFFFFFFFH
can be converted to corresponding cc-codes and then be displayed on the CC7SDD devices [Fig-
4.6] with the help of the data structure and algorithm of Fig-4.7. The procedures are:

a.      Create a Lookup Table in IRAM (preferably using the space: 40H – 4FH) to hold cc-codes for
        the characters: 0 – 9, A – F. The location 40H will hold the cc-code for character 0 and so on.
b.      Keep the input data into Hex Table cintain9ing IRAM locations from 50H – 57H. MS-byte of
        the data will enter at location 57H.
c.      Call the subroutine HEX2CC (Hex Code – to – CC Code Conversion) to convert the data of
        Hex Table into CC-codes. After conversion, the cc-code of the MS-digit of the content of
        location 50H will be kept at location 30H. The cc-code of the LS-digit of the content of
        location 50H will be kept at location 31H and so on. The HEX2CC subroutine consults the
        Lookup table of Step-a for the conversion process.
d.      Call the subroutine CCX7SDD (Transfer cc-codes of CC Table into 7SDD). The SUR reads cc-
        code of IRAM location 30H and ‗does everything‘ to show it on DP0-position of the display
        unit. The cc-code of IRAM location 31H appears at DP1-position and so on. The phrase
        ‗does everything‘ refers to the mechanism of ‗time multiplexing‘ of the data of CC Table on
        the respective display devices. This means that the MCU reads the content of 30H, place it
        on P2 (Port-2), activate cc0-pin, deactivate cc1-ccF and then wait for a while.

                                                                  13
Displaying Message on Multiplexed CC7S-type Display Unit
                                          +5V

                                                         RN1
                                   U3: 89S52 MCU         8x1k
                      Y1 = 12MHz
                                                                    DPA   DPB    DPC    DPD      DPE   DPF
             +5V                           P2
                                   X2
                                                P2.7        5   p
     RST                                        P2.6       10   g
                                                P2.5        9   f
                   C1              X1
                                                P2.4        1   e
                   100uF
                                                P2.3        2   d
                                   RST
                                                P2.2        4   c
                                                P2.1        6   b
            R1
                                                P2.0        7   a
            4k7                                                                          ccD
                                                                    ccA    ccB   ccC             ccE   ccF
                                                                    3      3     3       3       3     3
                      0V
                                   GND
                      +5V
                                   Vcc
                                   EA/          P1.1
                                                P1.2
                                                P1.3
                                                P1.4
                                                P3.3
                                                P3.4



 1603 : JM: 11-2009


                                    Figure-4.8: Driving CC7SD Devices using IO Lines of CMCKIT

a.         Let us build the 6-digit CC7S display unit of Fig-4.8 on the breadboard of the AMCKIT-A.
b.         Complete the connections with the AMCKIT using jumper wires.
c.         The resistor network RN1 may be placed on the edge connector of P2 port on the AMCKIT.

Add Two 8-bit Binary Numbers and show Result at DPA-DPB Positions of Fig-4.8
Procedures:
a. Assemble and download the following program. The program contains 45H and 25H as the
    input binary numbers.
b. Execute the downloaded program.
c. The DPA, DPB [positions of the display unit should show the result, 6A.
d. Let us get familiar with the source codes of the program P42d1.asm and check that the
    program construction follows the structure of the algorithm of Fig-4.7.

           Assembly Code Listing:
           ORG              0000H
           DB               02H
           DB               00H
           DB               30H

    ORG     0030H
START:
    NOP
    ;--stcak, bank init------
L1: MOV     SP, #70H
    MOV     PSW, #00H

    ;-----Lookup                     Table Init------
L1A:MOV     40H,                     #3FH           ; cc-code for character 0
    MOV     41H,                     #06H           ; cc-code for character 1
    MOV     42H,                     #5BH

                                                                    14
    MOV     43H,   #4FH
    MOV     44H,   #66H
    MOV     45H,   #6DH
    MOV     46H,   #7DH
    MOV     47H,   #07H
    MOV     48H,   #7FH
    MOV     49H,   #6FH
    MOV     4AH,   #77H
    MOV     4BH,   #7CH
    MOV     4CH,   #39H
    MOV     4DH,   #5EH
    MOV     4EH,   #79H
    MOV     4FH,   #71H         ; cc-code for character F

    ;--------addition--------
L2: MOV     A, #45H             ; input data1 = 45H
    ADD     A, #25H             ; data2 = 25H and result = 6A

    ;-------HEX-to-CC code Conversion----------
L3: MOV     55H, A      ; result in HEX table
    MOV     R0, #55H    ; pointing at HEX table
    MOV     R1, #3AH    ; pointing at CC table
    MOV     R2, #01H    ; number of byte to convert
    LCALL   HEX2CC

    ;-----------------
L4: LCALL   CCX7SDD
    LJMP    L4

    ;---------------------
HEX2CC:
SR11:
    MOV     A, @R0      ; getting the HEX
    MOV     B, A
    SWAP    A
    ANL     A, #0FH
    ADD     A, #40H
    MOV     03H, 00H
    MOV     R0, A
    MOV     A, @R0
    MOV     @R1, A

    MOV     A, B
    ANL     A, #0FH
    ADD     A, #40H
    MOV     R0, A
    MOV     A, @R0
    INC     R1
    MOV     @R1, A
    DJNZ    R2, ADJ
    RET

ADJ:MOV     00H, 03H
    INC     R0
    INC     R1
    LJMP    SR11

                                      15
;------------------

CCX7SDD:
SR21:
    MOV     P2, 3AH
    CLR     P1.1
    SETB    P1.2
    LCALL   TDEL

    MOV     P2, 3BH
    SETB    P1.1
    CLR     P1.2
    LCALL   TDEL
    RET
    ;------------------

TDEL:
    MOV     R7, #50H
D2: MOV     R6, #50H
D1: DJNZ    R6, D1
    DJNZ    R7, D2
    RET
    ;------------------------

    END

    C Codes Listing:
#include <8052.h>

void delay(unsigned int y);

void main()
{
  //---Lookup Table init in IRAM space : 80H – FFH -----------
  static idata unsigned char luptab[] = {
                                            0x3F, 0x06, 0x5B, 0x4F, 0x66, 0x6D,
                                            0x7D, 0x07, 0x7F, 0x6F,
                                            0x77, 0x7C, 0x39, 0x5E, 0x77, 0x71
                                        };
  //---Hex abd CC Tables init----------
  static data unsigned char hext[1];    // Hex Code Table in RAM space:30H–7FH
  static data unsigned char ccct[2];    // CC-code Table in RAM space: 30H–7FH
  unsigned char x,y, z;
  //-----addition----
  x = 0x37;
  y = 0x25;
  z = x+y;
  hext[0] = z;

  //-----HEX2CC conversion
  x = hext[0];
  x>>=4;
  ccct[0] = luptab[x];
  x = hext[0];
  x = x & 0x0F;
  ccct[1] = luptab[x];
                                      16
      //----CCX7SDD
    CCX7SDD:
    while(1)
    {
       P2 = ccct[0];
       P1_1 = 0;
       P1_2 = 1;
       delay(300);

        P2 = ccct[1];
        P1_1 = 1;
        P1_2 = 0;
        delay(300);
    }
}

void delay(unsigned int y)
{
  int i;
  for(i=0;i<y;i++)
  {
    ;
  }
}
;----------------------------------------------------------------------------------------------------------------------------- --
E10:         Experiment-E10 [Driving LCD]
In this experiment, we will learn the tricks of displaying alphanumeric message on the LCD
panel placed on the breadboard of the CMCKIT.

Procedures:
1. Use jumper wires to connect the LCD panel with the CMCKIT as per following circuit.
                                    +5V
                                                                                  U1x:    2x16 Charracter LCD
         CMCKIT                             RN2 (already placed)
                                            8x4k7                           DP0                                           DPF        Line-1
                            32, 31,….,39             D7,….D0 : 14,13,…,7
                  P07-P00                                                   DP0                                           DPF        Line-2

                                                                            E R-W/ D-I/    VA        Vdd Vss       L+          L-
                                                                                                                   15


                                                                                                                              16
                                                                           6

                                                                                  5

                                                                                      4


                                                                                           3




                                                                                                      2

                                                                                                          1




                      P23   23

                      P21   22                                                                                           R2x
                                                                                                                         3k3
                      P20   21
                                                                                                               6




                                                              R1x=1k5
                     GND    20                                             Viewing Angle            +5V   0V            +5V         0V



                                                          LEDR2
                                           1k5
                                                                    0V
                     P1.0
                                                                    14
                                                                    15
                                                                    16
                                                   1
                                                   2




                                                              2-Line LCD Panel
                                                               Physical Layout
                                                              Model : QY-1602A
        U3 : 89S52                                                                                                 747ay GM : 2011




                                                                   17
2.    Assemble, download and execute the following program. Save the program as
      d:\cmckit\exp11.asm. After the execution of the program we will see the following results:
      a.   The LCD will show the following message:
           Line-1        : Travel Time:
           Line-2        C

      b.   The LEDR2 will blink after each 5-sec interval (not exactly 5-sec due to 11.0592 MHZ
           crystal.

Assembly Code Listing:
T2CON      DATA     0C8H          ; defining Byte address of Timer-2 Control Register
TH2        DATA     0CDH
TL2        DATA     0CCH
TR2        BIT      0CAH          ; defining bit address of Timer-2 Run Bit
ET2        BIT      0ADH
TF2        BIT      0CFH

           ORG      0000H    ; Main Line Program
           LJMP     0030H

           ORG      002BH    ; interrupt vector for Timer-2 Overflow
           LJMP     T2OVF    ; Timer-2 Overflow Interrupt


           ORG 0030H
START:     NOP

L1:        MOV      SP, #70H              ; stack init
           MOV      PSW, #00H             ; working Bank

           MOV      P2, #0FFH             ; P2 is output

           MOV      3AH, #00H             ; Counter to count 50mS Time Tick

         CLR    P1.0
         LCALL TDEL
;------------------------------------
;--- LCD Initialization------------
        MOV     B, #01h ; Cbyte-1:
        LCALL   BFW2IR
        MOV     B, #0Fh ; Cbyte-3:
        LCALL   BFW2IR
        MOV     B, #14h ; Cbyte-4:
        LCALL   BFW2IR
        MOV     B, #3Fh ; Cbyte-5: 2-line display
        LCALL   BFW2IR
;----------------------------
;---- Timer2 Initialization, 16-bit auto reload---
        MOV     T2CON, #00H ; 16-bit auto-reload

        MOV     TH2, #3CH
        MOV     TL2, #0B0H ; 50ms Time Para
;---------------------------------------------
        SETB    P1.0
        LCALL   TDEL
        CLR     P1.0
        LCALL   TDEL


                                                18
          MOV     B, #0C0H    ; cursor position at DP0 of Line-2 to show    C
          LCALL   BFW2IR
          MOV     B, #43H     ; ASCII code of C is 43H
          LCALL   BFW2DR
      ;------------------------

          MOV     B, #80H     ; cursor position at DP0 of Line-1
          LCALL   BFW2IR      ; cursor position
      ;---------------------------------------

         MOV     DPTR, #MSG1
         MOV     A, #00H
LQ:      MOVC    A, @A+DPTR      ; DPTR can point to internal code memory
         CJNE    A, #00H, LQ2
         LJMP    NXT
LQ2:     MOV     B, A
         LCALL   BFW2DR
         INC     DPTR
         MOV     A, #00H         ; 00H marks the end of the string
         LJMP    LQ


NXT:    SETB    ET2
        SETB    EA
        SETB    TR2
    ;-----------------
HERE:   LJMP    HERE
;--------------------------------

T2OVF:   CLR     TF2
         INC     3AH     ; to count 100 ticks for 5 Sec
         MOV     A, 3AH
         CJNE    A, #64H, RMLP
         MOV     3AH, #00H
         SETB    P1.0
         LCALL   TDEL
         CLR     P1.0
         LCALL   TDEL


RMLP:   RETI
;---------------------------

MSG1:   DB ' :Travel Time:', 00H ; 'Bangladesh', 00H
;---------------------------
BFW2IR: ;LCALL   DELAY
        CLR     P2.0   ; D-I/
        CLR     P2.1   ; R-W/
        CLR     P2.2   ; E
        LCALL   DELAY
        SETB    P2.1
        LCALL   DELAY
        SETB    P2.2
        LCALL   DELAY
        MOV     A, P0
        JNB     0E7H, LX
        LJMP    BFW2IR
LX:     LCALL   DELAY
        CLR     P2.2
        LCALL   DELAY
        CLR     P2.1
        LCALL   DELAY
        SETB    P2.2
        LCALL   DELAY
                                        19
        MOV     A, B
        MOV     P0, A
        LCALL   DELAY
        CLR     P2.2
        RET
;---------------------------
BFW2DR: ;LCALL   TDELAY
        CLR     P2.0    ; D-I/
        CLR     P2.1    ; R-W/
        CLR     P2.2    ; E
        LCALL   DELAY
        SETB    P2.1
        LCALL   DELAY
        SETB    P2.2
        LCALL   DELAY
        MOV     A, P0
        JNB     0E7H, LX1    ; Checking that LCD is not busy
        LJMP    BFW2DR
LX1:    LCALL   DELAY
        CLR     P2.2
        LCALL   DELAY
        CLR     P2.1
        LCALL   DELAY
        SETB    P2.0
        LCALL   DELAY
        SETB    P2.2
        LCALL   DELAY
        MOV     A, B
        MOV     P0, A
        LCALL   DELAY
        CLR     P2.2
        RET
;----------------------
DELAY: MOV      R7, #50H
AGN1:   MOV     R6, #50H
AGN:    DJNZ    R6, AGN
        DJNZ    R7, AGN1
        RET
;-------------------------------------------------------------------------------------------------------------------------------
E11:         Experiment – 11 [Interfacing Serial Analog-to-Digital Converter, ADC0834]




                                                              20
E12:      Experiment-12 [Interfacing Serial Communication Port of 89S52 with IBMPC]
Introduction:
The Pin-10 and Pin-11 of the 89S52 microcontroller can be configured as RxD-pin and TxD-pin
respectively to establish ‗asynchronous serial communication link‘ with the Serial Com (SCOM)
port of the IBMPC.

The detailed theory of ‗Asynchronous Serial Communication Protocol and Its Interfacing with
IBMPC via Visual Basic-6 based Graphical User Interface‘ can be found in Chapter-4 of the book
―8086 Microprocessor Interfacing and System Design By: Golam Mostafa‖. The book is available
at Monika Books, Nilkhet, New Market, Dhaka, Tel: 01554346144.

Connection Diagrams
                                                                CMCKIT                                                                                       IBMPC

     U3 : 89S52 Microcontroller                                      U1X : MAX232                          J12: Holes                            Pins of DB9 Connector
                                                        J6-10
                                                       RXTTL                                                    1
       Address: 99H                                                                                J6-13
                                                                                                                                                        1   CD/
                                            RxD
          Rx Buffer                                                                                TXRS
                                                                                                                    6                               6       DSR/
                                                       10      12 R1OUT                  R1IN 13
                                        P30
                                                                                                                2
                                                                                                                                                        2   RXRS
                                                        J6-12
       Address: 99H                                    TXTTL                                                                                        7
                                            TxD                                                                         7                                   RTS/
          Tx Buffer
                                                       11      11 T1IN              T1OUT 14
                                                                                                                3
         Port-3 : B0H                   P31                                                                                                             3     TXRS

                       P30
                       P31                                                                                                  8                       8       CTS/
                       P32                             12                                          J6-11
                       P33                             13                                          RXRS
                       P34                             14                                                   4                                           4   DTR/         DB9 Connector
                       P35                             15
                                                                                                                        9
                       P36                             16                                                                                           9         +5V
                       P37                             17
                                                                                              15    0V          5                     COM               5



                                                                    TTL <--> RS232                 DB9 Connector                                 COM1 Port of (SCOM1)IBMPC
         753abc : GM : 10-05


                                  Figure – E12a : Serial Link Operation using Serial COM Port of IBMPC


                                                                 TXTTL
                                                                                                   753abc                         MAX232 DETAILS
  DB9 Connector (9-Holes)                              U30
                                                                                                                                                                         C3 1uF
                                                                                                         C1 1uF         1                                           16
    J8                                            13                       12     RXTTL                                         C1+                           Vcc
                                                        R1IN     R1OUT
            5                                      8                       9                                    +                                                                   +
            9                                           R2IN     R2OUT                                                                +5V to +10V Converter
            4                                     11                       14     TXRS
                                                        T1IN      T1OUT                                                                                                   +
            8                                     10                       7                                            3                               V+ (+10V) 2
            3                   RXRS                    T2IN      T2OUT                                                         C1-
                                                                                                                                                             GND 15
            7                                      1                                                     C2 1uF
                                                        C1+                                                             4                                          6              C5 1uF
            2                                      3                                                                            C2+                      V- (-10V)
                                                        C1-                                                     +
            6                                      4
            1                                      5    C2+                                                                  +5V to -10V Converter                                C4 1uF
                                                        C2-                                                                                                                   +
                                                   2                                                                    5                       GND 15
                                                        V+                                                                C2- 400k
                       +




                C36                                6
 VCC                                                    V-
                1u                                                                                                  11                      +5      400k   T1OT 14
                                       C35                                                             TTL                                                                        RS232
                                                                                                                    10 T2IN                             +5 T2OT 7
            C33                  C34                   MAX232                                        Inputs                                                                       Outputs
                  +




                                 +     +
                                                                                                       TTL          12 R1OT   0V                            R1IN 13
                  1u                                                                                                                                                              RS232
                           1u          1u                                                           Outputs          9 R2OT                                 R2IN 8
                                                                                                                           0V                                                     Inputs
                                                                         753abc


         Figure-E12b: Internal Structure and Circuit Connection of MAX232 TTL↔ RS232 Converter Chip


                                                                                          21
                                         IBMPC                                                                                      CMCKIT
                                                                                         Tx, RX




                                                                      COM1 Port
               VB6 Based                 Asynchronous                                    RS232
                Graphical                   Serial
              User Interface             Communication
                                           Controller




                                                                                                                P1X
                                                                                         TX, RX
                 Virtual




                                                                          USB Port
                                             USB                                         USB
                  Serial
                                           Interface                                                                                RxRS, TXRS
               COM Port 3
                                           Controller
                (VCOM3)
                                                                                            59x            USB ß-> RS232



            Figure-E12c: Hardware Block Diagram to Operate Serial Link using USB Port of IBMPC
        IBMPC                     P1X          U1X: MAX232                                      U3: 89S52


                                                                                                                                 R1X : 1k5
                                                                                                                                                      0V
                                  TxRS         RxRS      RxTTL                            RxTTL               P35
                                  RxRS         TxRS      TxTTL                            TxTTL                                             RLEDX
                                                                                  20
                                  COM          COM         COM                            COM                 P2                                0V or +5V
                                                                                     9                                1
                                                                                          RST                 P10
                                                                                                                      P20          R7
                                                                                             XT2        XT1
                                                                                                                                   1k5
                      USB ß---- > RS232                                      Y1                                                      LEDR2
                         Converter                                   11.0592MHz                                            0V
 1503usb

 Figure-E12d: Connection Diagram for the Serial Port Operation of 89S52 MCU using USB Port of IBMPC

  753abc




If yo
        RS232 ß-> USB Converter            RS232 ß-> USB Converter                          RS232 ß-> USB Converter       DB9 to DB9 (Male to Female) Jumpper


     Figure-E12e: Pictorial Views of the available RS232↔USB Converter Cable and DB9 Jumper Cable

If your IBMPC has a SCOM port (unfortunately, the today‘s computers do not have SCOM ports),
then the connection diagrams among the MCU (U3), TTL↔RS232 (U1X) converter chip, DB9-
Female-Connector (J12 with holes at one side and pins at other side), DB9-Male-Connector
(COM1 Port of IBMPC, which can be found at the rear side of the PC) as per above diagram of
Fig-1. The J12 and COM1-port would be connected by a 9-pin to 9-pin jumper cable (see Fig-5
below).

However, we assume that your IBMPC doesn‘t have a COM-port. Under this circumstance, we
will operate the serial link using the USB-port of the IBMPC. The detailed procedures for setup,
connection diagrams and operations are given below.
                                                                     22
Procedures:
1. Place a MAX232 (U1X of Fig-E12d) on the breadboard of the CMCKIT. Connect the filter
    capacitors (C1, C2, C3, C4) with this chip as per circuit diagram of Fig-E12b).
2. Use jumper wires to connect +5V and 0V of the CMCKIT with this chip.
3. Use jumper wires to connect RxD-pin (Pin-10 of MCU) with R1OUT (Pin-12 of MAX232) and
    TxD-pin (Pin-11 of MCU) with T1IN (Pin-11 of MAX232) of the CMCKIT (Fig- E12d).
4. Place a DB9 (9-pin Female and Pin) connector on the breadboard of the CMCKIT. If this DB9
    connector doesn‘t fit on the breadboard, use a female-female DB9 connector. Use jumper
    wires and establish connections between the MAX232 chip and the DB9 connector as per
    diagram of Fig-12a.
5. Use jumper wires to make the short circuits among the indicated pins (Fig-E12a) of the DB9
    connector.
6. Choose (or the one you can in the IDB Computer City) RS232 ↔ USB converter cable (Fig-
    E12e) and engage its 9-pin male-side with the female-side of the DB9 connector of the
    breadboard. Do not connect the USB-side with the IBMPC at this time.
7. Assemble the following program d:\cmckit\siotest.asm) and download its hex file
    (d:\cmckit\sisotest.hex) into the code memory of the target MCU (U3) of the CMCKIT. Or
    use a commercial universal ROM programmer (TOP2005 or similar) to fuse the program
    codes into the code memory of the target MCU.

         ORG      0000H
         LJMP     0030H

         ORG      0030H
L1:      MOV      20H, #00H     ; flag bits : f0 - f7 are 0s.
L1A:     MOV      PSW, #00H         ; Bank-0
         MOV      SP, #70H      ; Stack Top is set at : 70H
         CLR      P1.0
         CLR      P3.5
         CLR      SCON.0

         ;SETB    P3.5
         CLR      EA       ; all interrupts are disabled
L2:      LCALL    SPORTINIT     ; serial port init for 4800Bd, 8-bit data, No
                                ; Parity, 1-stop bit

L3:     JB      SCON.0, L4 ; checking if any command has come from IBMPC
        LJMP    L3
L4:     CLR     SCON.0
        MOV     A, SBUF     ; Reading the received data
        CJNE    A, #05H, L5
        LCALL   LEDB        ; command 05H is received to blink RLEDX 5 times
    ;-----------------------

         ;MOV     SBUF, #32H

         MOV      R2, #05H
AGN:     SETB     P3.5
         LCALL    TDEL
         LCALL    TDEL
         LCALL    TDEL
         CLR      P3.5
         LCALL    TDEL
         LCALL    TDEL
         LCALL    TDEL
                                            23
        DJNZ    R2, AGN
        ;LJMP   L3
    ;------------------
L5:     CJNE    A, #06H, L3
        LCALL   LEDB
        MOV     SBUF, P2
        LJMP    L3

;------------
SPORTINIT:
        MOV     SCON, #50H     ; Serial Port Init: 4800-Bd, NP, 1-Stopbit
        MOV     PCON, #00H ; SMOD=0 for 4800Bd
        MOV     TH1, #0FAH     ; Timer-1 reload value for 4800Bd
        MOV     TMOD, #20H ; TC1 configured as Timer-1 and 8-bit auto-reload
        MOV     TCON, #40H ; Timer-1 is in RUN (start) mode.
        RET
;----------
TDEL:   MOV     R4, #0FFH
D1:     MOV     R3, #0FFH
D2:     DJNZ    R3, D2
        DJNZ    R4, D1
        RET
;----------
LEDB:   SETB    P1.0
        LCALL   TDEL
        CLR     P1.0
        LCALL   TDEL
        RET
;-----------
        END
;-----------------
8.  Do not remove the USB connector of the CMCKIT from the IBMPC.
9.  Engage the USB connector of the serial link cable of the project into another USB port of the
    IBMPC. Follow all the steps of Section-B (page-2) for installing the USB cable into the
    IBMPC.
10. Install the following application package into your PC. This application will create a
    Graphical User Interface (GUII) to establish serial communication with the target MCU (U3)
    of the CMCKIT.
         D:\cmckit\SIOTESTVCOM4
11. Take a jumper wire and connect the RST-pin of the target MCU (U3) with the 0V.
12. From the start icon of the IBMPC, execute the application SIOTESTVCOM4. The following
    GUI will appear on the screen of the IBMPC.




13. Follow the GUI menu to perform data read/write operations with the target MCU.
    Note: Whenever the CMCKIT receives a command (either Read Port-2 or Blink RLEDX : Fig-
    E12d), the LEDR2 (Fig-E12d) will flash for once. Use jumper to inject LL (0V) to P2.0 – P2.7.
                                              24
25

				
DOCUMENT INFO
Shared By:
Categories:
Tags:
Stats:
views:33
posted:9/25/2011
language:English
pages:25