Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[SOLVED] integrating 2 programs

Status
Not open for further replies.

amit251291

Member level 1
Member level 1
Joined
Jul 18, 2012
Messages
38
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Visit site
Activity points
1,558
hello,

In my project there are 2 parts 1) digital speedometer 2) speed monitoring (about which i told above)
I have prepared program of "digital speedometer" and "program to send a message". now I want to prepare a program which will send a message when speed is increased above particular limit. So how i should integrate this 2 programs to get final program?

Digital speedometer program:

Code:
$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





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
      
   
        
  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

          
   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


   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

        
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
                

               
CLEAR:  MOV A,#01H
        LCALL  CMD
        RET



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


Program to send messages on a mobile number:

Code:
ORG 0000H
		MOV TMOD,#20H	   		//TIMER 1, MODE 2
		MOV TH1,#-3				//9600 BAUD RATE
		MOV SCON,#50H			//8 BIT, 1 STOP, EN ENABLED
		SETB TR1
		acall delay
		acall delay
		acall delay
		acall delay
				
		MOV DPTR,#MSG1
		ACALL H1
		ACALL DELAY
		MOV DPTR,#MSG2
		ACALL H1
		ACALL DELAY
		
		MOV DPTR,#MSG4
		ACALL H1
		ACALL DELAY
		MOV DPTR,#MSG5
		ACALL H1
		ACALL DELAY
viay: sjmp viay
H1:  	CLR A
		MOVC A,@A+DPTR
		JZ B1
		ACALL SEND
		INC DPTR
		SJMP H1
B1:
		RET
SEND: 	MOV SBUF,A
H2: 	JNB TI,H2
		CLR TI
		RET
		
DELAY:  mov R5,#10H
HERE1: MOV R3,#0ffH
HERE2:  MOV R4,#0ffH
HERE:	DJNZ R4,HERE
		DJNZ R3,HERE2
		DJNZ R5,HERE1
		RET
	

ORG 300H
MSG1: DB "AT",0DH
	  DB 0H
MSG2: DB "AT+CMGF=1",0DH
	  DB 0H

MSG4: DB "AT+CMGS=",'"1234567888"',0DH
	  DB 0H
MSG5: DB "TEXT",0X1A
	  DB 0H

	  END

- - - Updated - - -

i have prepared this program by integrating above these 2 programs. But problem with this is (if all logic is correct) it will send a message when speed is greater than 6 km/hr but less than 10 km/hr as only 1 bit is monitored.. please go through these program and guide me correction/modifications required.
Controller: AT89C51
Its okay if it shows nothing on lcd when controller is executing a message routine.

waiting for reply,


Code:
$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        P2.0         ;SCL=PIN6
SDA   EQU        P2.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





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
			CJNE A,#06H,GREATER
			LJMP GET_THIRD
GREATER:   JNC SEND_SMS
		   LJMP GET_THIRD
SEND_SMS:  	
		MOV TMOD,#20H	   		//TIMER 1, MODE 2
		MOV TH1,#-3				//9600 BAUD RATE
		MOV SCON,#50H			//8 BIT, 1 STOP, EN ENABLED
		SETB TR1
		ACALL DELAY1
		
				
		MOV DPTR,#MSG1
		ACALL S1
		ACALL DELAY1
		MOV DPTR,#MSG2
		ACALL S1
		ACALL DELAY1
		
		MOV DPTR,#MSG4
		ACALL S1
		ACALL DELAY1
		MOV DPTR,#MSG5
		ACALL S1
		ACALL DELAY1
        LJMP MAIN
S1:  	CLR A
		MOVC A,@A+DPTR
		JZ B1
		ACALL SEND
		INC DPTR
		SJMP S1
B1:
		RET
SEND: 	MOV SBUF,A
S2: 	JNB TI,S2
		CLR TI
		RET
		
DELAY1:  mov R5,#02H
HERE1: MOV R3,#0ffH
HERE2:  MOV R4,#0ffH
HERE:	DJNZ R4,HERE
		DJNZ R3,HERE2
		DJNZ R5,HERE1
		RET
	



			
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
           
           LJMP LOOP               ; CONTINUE DOING THIS
              
STORE_DAT: LCALL SEND2EEPROM       ; IF SPEED IS = 00.0 THEN SAVE THE MILEAGE IN EEPROM 
       
           LJMP 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
      
   
        
  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

          
   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


   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

        
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
                

               
CLEAR:  MOV A,#01H
        LCALL  CMD
        RET



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 300H
MSG1: DB "AT",0DH
	  DB 0H
MSG2: DB "AT+CMGF=1",0DH
	  DB 0H

MSG4: DB "AT+CMGS=",'"1234567888"',0DH
	  DB 0H
MSG5: DB "TEXT",0X1A
	  DB 0H

	  
 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
 

Use a piece of paper and write pseudo code of your concept. Then use finite state machines to integrate your design.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top