Deprecated: mysql_connect(): The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead in /home/freehos1/public_html/projectus/core/open_close_dbase_connection.php on line 0

Deprecated: Function split() is deprecated in /home/freehos1/public_html/projectus/Speedometer/index.php(0) : eval()'d code on line 22

Deprecated: Function split() is deprecated in /home/freehos1/public_html/projectus/Speedometer/index.php(0) : eval()'d code on line 35

Deprecated: mysql_connect(): The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead in /home/freehos1/public_html/projectus/scripts/get_ad_type_position.php on line 0

Deprecated: mysql_connect(): The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead in /home/freehos1/public_html/projectus/scripts/load_ads.php on line 0

Deprecated: mysql_connect(): The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead in /home/freehos1/public_html/projectus/scripts/sponsor_found.php on line 0

Deprecated: mysql_connect(): The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead in /home/freehos1/public_html/projectus/scripts/load_links.php on line 0

Deprecated: Function split() is deprecated in /home/freehos1/public_html/projectus/Speedometer/index.php(0) : eval()'d code on line 161

Deprecated: Function split() is deprecated in /home/freehos1/public_html/projectus/Speedometer/index.php(0) : eval()'d code on line 164

Deprecated: Function split() is deprecated in /home/freehos1/public_html/projectus/Speedometer/index.php(0) : eval()'d code on line 167
assembly code for speedometer at89c51 code
projectus.freehost7.com:UG and PG level projects,mini projects and many more here ...



Code for speedometer(At89c51 code)

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

;         DIGITAL SPEEDOMETER CUM ODOMETER USING  16X2 LINE LCD + 8051 + EEPROM(I2C)

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

; XTAL Freq = 12 MHz

 

$MOD51

 

 

LCD    EQU      P1    ;   P1.0 .....P1.7, PORT1 USED AS DATA BUS

RS     EQU      P3.2

RW     EQU      P3.3

EN     EQU      P3.7

 

DISTO  EQU      P3.4   ; TIMER 0 INPUT FOR DISTANCE-ODOMETER

SPEDO  EQU      P3.5   ; TIMER 1 INPUT FOR SPEEDOMETER

 

 

SCL   EQU        P3.0         ;SCL=PIN6

SDA   EQU        P3.1         ;SDA=PIN5

 

EEPROMW   EQU    10100000B     ; SLAVE ADDRESS  OF EEPROM 1010 000  + 0 TO WRITE

EEPROMR   EQU    10100001B     ; SLAVE ADDRESS  OF EEPROM  1010 000 + 1 TO READ

 

 

 

DSEG

ORG 020H                      ; BIT-ADDRESSABLE RAM

 

FLAGS:             DS       1           ; VARIABLES FOR I2C PROTOCOL

LASTREAD  BIT    FLAGS.0

SQW     BIT    FLAGS.4

ACK       BIT    FLAGS.5

BUS_FLT   BIT    FLAGS.6

_2W_BUSY  BIT    FLAGS.7

OK        BIT      1

 

BITCNT:            DS                 1

BYTECNT:  DS                       1

POINT:  DS 1    ; DISTANCE VARIABLES

KM:     DS 1

TKM:   DS 1

HKM:   DS 1

KKM:   DS 1

TKKM:  DS 1

TOTAL: DS 1

STORE BIT  TOTAL.0

 

VAL1: DS 1   ; SPEED VAL1

VAL2: DS 1   ; SPEED VAL2

VAL3: DS 1   ; SPEED VAL3

 

 

 

; ***MACRO'S***

 

SCL_HIGH  MACRO

          SETB   SCL      ; SET SCL HIGH

          JNB    SCL,$    ; LOOP UNTIL STRONG 1 ON SCL

          ENDM

         

  

CONVERT MACRO              

   ORL A,#30H         ; CONVERT TO ASCII BY ADDING 30H

   ENDM

 

 

CSEG                              ; CODE BEGINS HERE

              ORG 0000H           ; ON RESET

 

              SJMP MAIN   

 

              ORG 000BH            ;Timer Interrupt0

 

              LJMP UPDATE

 

 

 

MAIN:  MOV SP,#70H       ; MOVE STACK POINTER TO ADDRESS 70H OF RAM

       LCALL PWR_DELAY   ;LCD POWER ON DELAY

       LCALL INIT        ;INITIALIZE LCD

       CLR STORE         ;CLEAR STORE FLAG

      

       MOV POINT,#00H    ; RESET ALL COUNTERS TO ZERO

       MOV KM,#00H

       MOV TKM,#00H

       MOV HKM,#00H

       MOV KKM,#00H

       MOV TKKM,#00H

      

       MOV VAL1,#00H     ; RESET SPEED VALUES TO ZERO

       MOV VAL2,#00H

       MOV VAL3,#00H

      

       LCALL READEEPROM   ; GET PREVIOUS READING FROM EEPROM

     

       LCALL SEND2LCD     ; DISPLAY INITIAL/PREVIOUS VALUES

      

      

       MOV TMOD,#66H    ; BOTH THE TIMERS SET AS COUNTERS IN MODE 2 - 8 BIT AUTO RELOAD

      

       MOV TH0,#203D    ; LOAD DISTANCE COUNTER TO COUNT 53 REVOLUTIONS(255-53+1)i,e 100 METERS

       MOV TL0,#203D     

      

       SETB DISTO      ; T0 INPUT      

       SETB SPEDO      ; T1 INPUT

      

       SETB ET0        ; ENABLE TR0 INTERRUPT

       SETB EA         ; GLOBAL ENABLE INTERRUPTS

       SETB TR0        ; START TIMER0

      

      

LOOP:  MOV TL1,#00H   ;  RESET SPEED COUNTER TO 00

       SETB TR1

       LCALL ONESEC_DELAY

       MOV B,TL1      ; COPY TL1 VALUE TO REGISTER B AFTER ONE SEC DELAY

       CLR TR1        ; STOP TR1

       MOV A,B

       JNZ GET_FIRST  ; CHECK IF SPEED IS ZERO

       SETB STORE     ; IF YES, SET STORE CURRENT READING FLAG

      

GET_FIRST: MOV DPTR,#FIRST        ; LOAD TABLE FOR FIRST DIGIT OF SPEED

           MOV A,B

           MOVC A,@A+DPTR

           MOV VAL1,A

          

GET_SECOND: MOV DPTR,#SECOND      ; LOAD TABLE FOR SECOND DIGIT OF SPEED

            MOV A,B

            MOVC A,@A+DPTR

            MOV VAL2,A

 

GET_THIRD: MOV DPTR,#THIRD        ; LOAD TABLE FOR THIRD DIGIT OF SPEED

           MOV A,B

           MOVC A,@A+DPTR

           MOV VAL3,A

             

           LCALL SEND2LCD          ; SEND VALUES TO LCD

          

           JBC STORE,STORE_DAT     ; CHECK IF STORE FLAG IS SET AND CLEAR THE FLAG

          

           SJMP LOOP               ; CONTINUE DOING THIS

             

STORE_DAT: LCALL SEND2EEPROM       ; IF SPEED IS = 00.0 THEN SAVE THE MILEAGE IN EEPROM

      

           SJMP LOOP

 

 

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

;             TIMER 0 ISR  - TO MEASURE DISTANCE

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

 

UPDATE:  INC POINT

        

         MOV R0,POINT

         CJNE R0,#10D,EXIT

         MOV POINT,#00H

         INC KM

        

         MOV R0,KM

         CJNE R0,#10D,EXIT

         MOV KM,#00H

         INC TKM

        

         MOV R0,TKM

         CJNE R0,#10D,EXIT

        

         MOV TKM,#00H

         INC HKM

        

         MOV R0,HKM

         CJNE R0,#10D,EXIT

        

         MOV HKM,#00H

         INC KKM

        

         MOV R0,KKM

         CJNE R0,#10D,EXIT

         INC TKKM

        

         MOV R0,TKKM

         CJNE R0,#10D,EXIT

        

         MOV POINT,#00H       ; WHEN 99,999 Kms, RESET ALL COUNTERS TO ZERO

         MOV KM,#00H

         MOV TKM,#00H

         MOV HKM,#00H

         MOV KKM,#00H

         MOV TKKM,#00H

        

  

 EXIT: RETI    

 

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

ONESEC_DELAY:

 

                    

            MOV R0,#10D    ; One second delay routine

RZ3:    MOV R1,#100D

RZ1:    MOV R2,#250D

RZ2:    NOP

            NOP

            DJNZ R2,RZ2

            DJNZ R1,RZ1 

            DJNZ R0,RZ3 

        RET 

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

    

SEND2LCD:

      

       MOV A,#84H     ; LINE 1

       LCALL CMD

      

       MOV A,TKKM

       CONVERT

       LCALL DAT

         

      

       MOV A,KKM

       CONVERT

       LCALL DAT

      

       MOV A,HKM

       CONVERT

       LCALL DAT

      

       MOV A,TKM

       CONVERT

       LCALL DAT

      

       MOV A,KM

       CONVERT

       LCALL DAT

      

       MOV A,#'.'

       LCALL DAT

      

       MOV A,POINT

       CONVERT

       LCALL DAT

      

       MOV A,#0CBH    ; LINE 2

       LCALL CMD

      

            

       MOV A,VAL1

       CONVERT

       LCALL DAT

     

       MOV A,VAL2

       CONVERT

       LCALL DAT

      

       MOV A,#'.'

       LCALL DAT

      

       MOV A,VAL3

       CONVERT

       LCALL DAT

      

      

       RET

     

  

;****************************LCD SUBROUTINES****************************************

       

  READY:SETB EN ;H->L PULSE ON E

        CLR  RS ;RS=0 CMD

        SETB RW ;RW=1 FOR READ

        SETB P1.7 ;D7 AS INPUT

        JB P1.7,READY

        CLR EN

        CLR RW

        RET

;****************************LCD SUBROUTINES****************************************

         

   DAT:   SETB EN ;H->L PULSE ON E

          SETB RS ;RS=1 DATA

          CLR RW ;RW=0 FOR WRITE

          MOV LCD,A ;MOVE ACC.DATA TO PORT

          CLR EN

          NOP

          LCALL READY

          RET

;****************************LCD SUBROUTINES****************************************

 

   CMD:      SETB EN ;H->L PULSE ON E

             CLR RS  ;RS=0 FOR COMMAND

             CLR RW ;RW=0 FOR WRITE

             MOV LCD,A ;MOVE ACC. DATA TO PORT

             CLR EN

             NOP

             LCALL READY

             RET

 ;****************************LCD SUBROUTINES****************************************

       

INIT:           MOV A,#030H   ;INITIALIZE LCD BY SENDING 30H THREE TIMES.

                LCALL  CMD

                ACALL DDELAY  ;INITIAL DELAY 4.1MSEC

                MOV A,#030H  

                LCALL  CMD

                ACALL DDELAY 

                MOV A,#030H  

                LCALL  CMD

                ACALL DDELAY

               

                MOV A,#038H   ; INITIALIZE, 2-LINES, 5X7 MATRIX.

                LCALL  CMD

                ACALL DDELAY

               

                MOV A,#0CH    ;  INVISIBLE CURSOR ON;

                LCALL  CMD

                MOV A,#01H    ; CLEAR LCD SCREEN

                LCALL  CMD

                MOV A,#06H    ; SHIFT CURSOR RIGHT

                LCALL  CMD

               

                MOV A,#80H       ; LINE 1

                LCALL CMD        

              

                MOV DPTR,#MSG_1

        LINE1:  CLR A

                MOVC A,@A+DPTR

                JZ NEXTLINE

                ACALL DAT

                INC DPTR

                SJMP LINE1

    

      NEXTLINE: MOV A,#0C0H       ; LINE 2

                LCALL CMD       

              

                MOV DPTR,#MSG_2

        LINE11: CLR A

                MOVC A,@A+DPTR

                JZ DONE

                ACALL DAT

                INC DPTR

                SJMP LINE11

                              

               

         DONE:  RET

               

;****************************LCD SUBROUTINES****************************************

              

CLEAR:  MOV A,#01H

        LCALL  CMD

        RET

 

;****************************LCD SUBROUTINES****************************************

 

DDELAY:  MOV R5,#41D           ; 4.1 mS DELAY

    QT2: MOV R6,#50D

    QT1: DJNZ R6,QT1

         DJNZ R5,QT2                

         RET

 

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

;                I2C - SERIAL EEPROM ROUTINES

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

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

; THIS SUB READS ONE BYTE OF DATA FROM THE EEPROM

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

 

READ_BYTE:

         MOV         BITCNT,#08H; SET COUNTER FOR 8-BITS DATA

         MOV         A,#00H

         SETB        SDA        ; SET SDA HIGH TO ENSURE LINE

                                ; FREE

READ_BITS:

         SCL_HIGH               ; TRANSITION SCL LOW-TO-HIGH

         MOV         C,SDA      ; MOVE DATA BIT INTO CARRY

         RLC         A          ; ROTATE CARRY-BIT INTO ACC.0

         CLR         SCL        ; TRANSITION SCL HIGH-TO-LOW

         DJNZ        BITCNT,READ_BITS

                                ; LOOP FOR 8-BITS

         JB          LASTREAD,ACKN

                                ; CHECK TO SEE IF THIS IS

                                ; THE LAST READ

         CLR         SDA        ; IF NOT LAST READ SEND ACK-BIT

 

ACKN:

         SCL_HIGH               ; PULSE SCL TO TRANSMIT ACKNOWLEDGE

         CLR         SCL        ; OR NOT ACKNOWLEDGE BIT

         RET

 

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

;         SUB SENDS START CONDITION

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

 

SEND_START:

         SETB        _2W_BUSY   ; INDICATE THAT 2-WIRE

         CLR         ACK        ; OPERATION IS IN PROGRESS

         CLR         BUS_FLT    ; CLEAR STATUS FLAGS

         JNB         SCL,FAULT

         JNB         SDA,FAULT

         SETB        SDA        ; BEGIN START CODITION

         SCL_HIGH

         CLR         SDA

         ACALL       DEELAY

         CLR         SCL

         RET

FAULT:

         SETB        BUS_FLT

         RET

 

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

;          SUB SENDS STOP CONDITION

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

SEND_STOP:

         CLR         SDA

         SCL_HIGH

         SETB        SDA

         CLR         _2W_BUSY

         RET

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

; SUB DELAYS THE BUS

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

DEELAY:

         NOP                    ; DELAY FOR BUS TIMING

         RET

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

; THIS SUB SENDS 1 BYTE OF DATA TO THE EEPROM

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

 

SEND_BYTE:

         MOV         BITCNT,#08H; SET COUNTER FOR 8-BITS

SB_LOOP:

         JNB         ACC.7,NOTONE ; CHECK TO SEE IF BIT-7 OF

         SETB        SDA          ; ACC IS A 1, AND SET SDA HIGH

         JMP         ONE

NOTONE:

         CLR         SDA             ; CLR SDA LOW

ONE:

         SCL_HIGH                    ; TRANSITION SCL LOW-TO-HIGH

         RL          A               ; ROTATE ACC LEFT 1-BIT

         CLR         SCL             ; TRANSITION SCL LOW-TO-HIGH

         DJNZ        BITCNT,SB_LOOP  ; LOOP FOR 8-BITS

         SETB        SDA        ; SET SDA HIGH TO LOOK FOR

         SCL_HIGH               ; ACKNOWLEDGE PULSE

         CLR         ACK

         JNB         SDA,SB_EX  ; CHECK FOR ACK OR NOT ACK

         SETB        ACK        ; SET ACKNOWLEDGE FLAG FOR

                                ; NOT ACK

SB_EX:

         ACALL       DEELAY      ; DELAY FOR AN OPERATION

         CLR         SCL         ; TRANSITION SCL HIGH-TO-LOW

         ACALL       DEELAY      ; DELAY FOR AN OPERATION

         RET

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

;  SUB READS FROM THE EEPROM AND WRITES IT TO THE SCRATCHPAD MEMORY

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

READEEPROM:

         MOV         R1,#POINT      ;  START FROM POINT STORAGE LOCATION

         MOV         BYTECNT,#00H

         CLR         LASTREAD

         LCALL       SEND_START

         MOV         A,#EEPROMW     

         LCALL       SEND_BYTE

         MOV         A,#00H         ; POINT TO 00H ADDRESS OF EEPROM

         LCALL       SEND_BYTE

         LCALL       SEND_STOP

        

         LCALL       SEND_START

         MOV        A,#EEPROMR      ; READ COMMAND

         LCALL       SEND_BYTE

 

READ_LOOP:

         MOV         A,BYTECNT

         CJNE        A,#06H,NOT_LAST  ;  CHECK FOR THE LAST BYTE

         SETB        LASTREAD

 

NOT_LAST:

         LCALL       READ_BYTE

         MOV         @R1,A

         MOV         A,BYTECNT

         CJNE        A,#00H,NOT_FIRST

         MOV         A,@R1

         MOV         @R1,A

NOT_FIRST:

         INC         R1              ;** INC RAM LOCATION **

         INC         BYTECNT

         MOV         A,BYTECNT

         CJNE        A,#07H,READ_LOOP  ; CHECK FOR 7th BYTE,IF 7th BYTE THEN STOP TRANSFER

         LCALL       SEND_STOP

         RET

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

           

SEND2EEPROM: 

                       

            LCALL SEND_START                        ; SEND 2WIRE START CONDITION

            MOV A,#EEPROMW                          ; LOAD EEPROM WRITE COMMAND

            LCALL SEND_BYTE              ; SEND WRITE COMMAND

           

            MOV A,#00H                      ; SET EEPROM DATA POINTER TO 00H (ADDRESS LOCATION)

            LCALL SEND_BYTE

           

            MOV A,POINT                     ; Send POINT

            LCALL SEND_BYTE

           

            MOV A,KM                               ; Send KM

            LCALL SEND_BYTE               

           

            MOV A,TKM                            ; Send TKM

            LCALL SEND_BYTE

           

            MOV A,HKM                            ; Send HKM

            LCALL SEND_BYTE             

           

            MOV A,KKM                    ; Send KKM

            LCALL SEND_BYTE                         

           

            MOV A,TKKM                          ; Send TKM

            LCALL SEND_BYTE

           

                       

            LCALL SEND_STOP              ; SEND 2WIRE STOP CONDITION

           

            RET

           

 

           

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

           

PWR_DELAY:                       ; 15 mSec DELAY FOR LCD TO INTIALIZE AFTER POWER-ON

          MOV R4,#30D

H2:       MOV R3,#250D

H1:       DJNZ R3,H1

          DJNZ R4,H2

          RET

 

 

 

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

 

 ORG 0350H

 

MSG_1: DB 'Kms:',00H

MSG_2: DB 'Speed-Kmph:',00H

 

 

FIRST:

DB 0H,0H,1H,2H,2H,3H,4H,4H,5H,6H,6H,7H,8H,8H,9H,0H

 

SECOND:

DB 0H,6H,3H,0H,7H,4H,0H,7H,4H,1H,8H,4H,1H,8H,5H,0H

 

THIRD:

DB 0H,8H,6H,4H,2H,0H,8H,6H,4H,2H,0H,8H,6H,4H,2H,0H

 

END