EngineersGarage

  • Engineers Garage Main Site
  • Visit our active EE Forums
    • EDABoard.com
    • Electro-Tech-Online
  • Projects & Tutorials
    • Circuits
    • Electronic Projects
    • Tutorials
    • Components
  • Digi-Key Store
    • Cables, Wires
    • Connectors, Interconnect
    • Discrete
    • Electromechanical
    • Embedded Computers
    • Enclosures, Hardware, Office
    • Integrated Circuits (ICs)
    • Isolators
    • LED/Optoelectronics
    • Passive
    • Power, Circuit Protection
    • Programmers
    • RF, Wireless
    • Semiconductors
    • Sensors, Transducers
    • Test Products
    • Tools
  • Advertise
You are here: Home / Topics / serial interfacing assembly code

serial interfacing assembly code

|

Microcontroller › 8051 › serial interfacing assembly code

  • This topic has 0 replies, 1 voice, and was last updated 14 years, 3 months ago by Dharmit.
Viewing 1 post (of 1 total)
  • Author
    Posts
  • March 1, 2011 at 1:42 pm #766
    Dharmit
    Participant

    Hey there,

     

    I have got an assembly language code for the serial interfacing, but I dont quite get it, does it have just the interfacing part in it or the code is also for a stop watch timer???

     

    Here is the code:

     

    SDA1        EQU        P1.1         ;SDA=PIN5

    SCL1        EQU        P1.0                ;SCL=PIN6

     
     
    WTCMD EQU   10100000B       ;WRITE DATA COMMAND 

    RDCMD EQU   10100001B       ;READ DATA COMMAND 

     
     
     
     
    ;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

    ;                STORE A BYTE  (Data 8F in address location 2AH)

    ;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%                  

                   MOV A,#WTCMD ;LOAD WRITE COMMAND

                   CALL OUTS ;SEND IT

                   MOV A,#2AH ;GET BYTE ADDRESS

                   CALL OUT ;SEND IT

                   MOV A,#8FH ;GET DATA

                   CALL OUT ;SEND IT

                   CALL STOP ;SEND STOP CONDITION

    ;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

    ;                       

    ;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%                  

                   MOV     A,#WTCMD        ;LOAD WRITE COMMAND TO SEND ADDRESS

                   CALL    OUTS            ;SEND IT

                  MOV     A,#4DH            ;GET LOW BYTE ADDRESS

                  CALL    OUT             ;SEND IT

                  CALL    CREAD           ;GET DATA BYTE

                  MOV A,R1  

                  CALL MDELAY            

                         RET

    ;***********************************************************************

    ;   

    ;***********************************************************************

     
     
     
     
    ;***********************************************************************

    ; THIS ROUTINE SENDS OUT CONTENTS OF THE ACCUMULATOR

    ; and includes START condition.  Refer to the data sheets

    ; for discussion of START and STOP conditions.

    ;***********************************************************************

     
     
    OUTS:   MOV     R2,#8           ;LOOP COUNT — EQUAL TO BIT COUNT

            SETB   SDA1            ;INSURE DATA IS HI               

            SETB    SCL1            ;INSURE CLOCK IS HI

            NOP                     ;NOTE 1

            NOP                     

            NOP

            CLR     SDA1            ;START CONDITION — DATA = 0

            NOP                     ;NOTE 1

            NOP      

            NOP

            CLR     SCL1            ;CLOCK = 0

    OTSLP:  RLC     A               ;SHIFT BIT

            JNC     BITLS

            SETB    SDA1            ;DATA = 1

            JMP     OTSL1           ;CONTINUE

    BITLS:  CLR     SDA1            ;DATA = 0

    OTSL1:  SETB    SCL1            ;CLOCK HI

            NOP                     ;NOTE 1

            NOP

            NOP

            

            CLR     SCL1            ;CLOCK LOW

            DJNZ    R2,OTSLP        ;DECREMENT COUNTER

            SETB    SDA1            ;TURN PIN INTO INPUT

            NOP                     ;NOTE 1

                                 

            SETB    SCL1            ;CLOCK ACK

            NOP                     ;NOTE 1

            NOP

            NOP

          

            CLR     SCL1

            RET

     
     
    ;**********************************************************************

    ; THIS ROUTINE SENDS OUT CONTENTS OF ACCUMLATOR 

    ; without sending a START condition.

    ;**********************************************************************

     
     
    OUT:    MOV     R2,#8           ;LOOP COUNT — EQUAL TO BIT COUNT

    OTLP:   RLC     A               ;SHIFT BIT

            JNC     BITL            

            SETB    SDA1            ;DATA = 1

            JMP     OTL1            ;CONTINUE

    BITL:   CLR     SDA1            ;DATA = 0

    OTL1:   SETB    SCL1            ;CLOCK HI

            NOP                     ;NOTE 1

            NOP

            NOP

         

            CLR     SCL1            ;CLOCK LOW

            DJNZ    R2,OTLP         ;DECREMENT COUNTER

            SETB    SDA1            ;TURN PIN INTO INPUT

            NOP                     ;NOTE 1

         

            SETB    SCL1            ;CLOCK ACK

            NOP                     ;NOTE 1

            NOP

            NOP

          

            CLR     SCL1

            RET

     
     
     
     
    STOP:   CLR     SDA1            ;STOP CONDITION SET DATA LOW

            NOP                     ;NOTE 1

            NOP

            NOP

          

            SETB    SCL1            ;SET CLOCK HI

            NOP                     ;NOTE 1

            NOP

            NOP

          

            SETB    SDA1            ;SET DATA HIGH

            RET

    ;*******************************************************************

    ; THIS ROUTINE READS A BYTE OF DATA

    ; From  current address pointer.

    ; Returns the data byte in R1

    ;*******************************************************************

    CREAD:  MOV     A,#RDCMD        ;LOAD READ COMMAND

            CALL    OUTS            ;SEND IT

            CALL    IN              ;READ DATA

            MOV     R1,A            ;STORE DATA

            CALL    STOP            ;SEND STOP CONDITION

            RET

     
     
    ;**********************************************************************

    ; THIS ROUTINE READS IN A BYTE FROM

    ; and stores it in the accumulator

    ;**********************************************************************

     
     
    IN:     MOV     R2,#8           ;LOOP COUNT

            SETB    SDA1            ;SET DATA BIT HIGH FOR INPUT

    INLP:   CLR     SCL1            ;CLOCK LOW

            NOP                     ;NOTE 1

            NOP

            NOP

            NOP

         

            SETB    SCL1            ;CLOCK HIGH

            CLR     C               ;CLEAR CARRY

            JNB     SDA1,INL1       ;JUMP IF DATA = 0

            CPL     C               ;SET CARRY IF DATA = 1

    INL1:   RLC     A               ;ROTATE DATA INTO ACCUMULATOR

            DJNZ    R2,INLP         ;DECREMENT COUNTER

            CLR     SCL1            ;CLOCK LOW

            RET

     
     
    ;*********************************************************************

    ; This routine test for WRITE DONE condition 

    ; by testing for an ACK.

    ; This routine can be run as soon as a STOP condition

    ; has been generated after the last data byte has been sent

    ; The routine loops until an ACK is received 

    ; No ACK will be received until the EEPROM is done with

    ; the write operation.

    ;*********************************************************************

    ACKTST: MOV     A,#WTCMD        ;LOAD WRITE COMMAND TO SEND ADDRESS

            MOV     R2,#8           ;LOOP COUNT — EQUAL TO BIT COUNT

            CLR     SDA1            ;START CONDITION — DATA = 0

            NOP                     ;NOTE 1

            NOP

            NOP

               

            CLR     SCL1            ;CLOCK = 0

    AKTLP:  RLC     A               ;SHIFT BIT

            JNC     AKTLS

            SETB    SDA1            ;DATA = 1

            JMP     AKTL1           ;CONTINUE

    AKTLS:  CLR     SDA1            ;DATA = 0

    AKTL1:  SETB    SCL1            ;CLOCK HI

            NOP                     ;NOTE 1

            NOP

            NOP

          

            CLR     SCL1            ;CLOCK LOW

            DJNZ    R2,AKTLP        ;DECREMENT COUNTER

            SETB    SDA1            ;TURN PIN INTO INPUT

            NOP                     ;NOTE 1

          

            SETB    SCL1            ;CLOCK ACK

            NOP                     ;NOTE 1

            NOP

            NOP

           

            JNB     SDA1,EXIT       ;EXIT IF ACK (WRITE DONE)

            JMP     ACKTST          ;START OVER

    EXIT:   CLR     SCL1            ;CLOCK LOW

            CLR     SDA1            ;DATA LOW

            NOP                     ;NOTE 1

            NOP

            NOP

          

            SETB    SCL1            ;CLOCK HIGH

            NOP

            NOP

            SETB    SDA1            ;STOP CONDITION

            RET

  • Author
    Posts
Viewing 1 post (of 1 total)
  • You must be logged in to reply to this topic.
Log In

RSS Recent Posts

  • Simple LED Analog Clock Idea June 22, 2025
  • Fun with AI and swordfish basic June 22, 2025
  • Is AI making embedded software developers more productive? June 22, 2025
  • Can I make two inputs from one?? June 21, 2025
  • Behlke swich June 21, 2025

Stay Up To Date

Newsletter Signup
EngineersGarage

Copyright © 2025 WTWH Media LLC. All Rights Reserved. The material on this site may not be reproduced, distributed, transmitted, cached or otherwise used, except with the prior written permission of WTWH Media
Privacy Policy | Advertising | About Us

Search Engineers Garage

  • Engineers Garage Main Site
  • Visit our active EE Forums
    • EDABoard.com
    • Electro-Tech-Online
  • Projects & Tutorials
    • Circuits
    • Electronic Projects
    • Tutorials
    • Components
  • Digi-Key Store
    • Cables, Wires
    • Connectors, Interconnect
    • Discrete
    • Electromechanical
    • Embedded Computers
    • Enclosures, Hardware, Office
    • Integrated Circuits (ICs)
    • Isolators
    • LED/Optoelectronics
    • Passive
    • Power, Circuit Protection
    • Programmers
    • RF, Wireless
    • Semiconductors
    • Sensors, Transducers
    • Test Products
    • Tools
  • Advertise