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.

please help me check this code..ASAP

Status
Not open for further replies.

chomix05

Newbie level 5
Joined
Feb 2, 2012
Messages
9
Helped
1
Reputation
2
Reaction score
1
Trophy points
1,283
Activity points
1,372
DIGITAL THERMOMETER


Code:
list      p=16f628            	
#include <p16f628.inc>        
errorlevel 0,-302
	
CBLOCK	0x20
DS_DAT	
DS_SIGN	
DUMMY0	
DUMMY1	
DUMMY2	
DUMMY3	
DUMMY4	
SEND	
COUNT	
NUM1	
NUM2	
NUM3	
DATA1	
HALF
	endc
#define	DAT_PIN	PORTB,0		; 74595 DATA pin
#define LATCH	PORTB,4		; 74595 LATCH pin 
#define CLK	PORTB,5		; 74595 CLK pin
#Define	DQ	PORTA,0

	org	0x000
	goto	Start

Table_	addwf	PCL,f
	dt	0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f

Start	clrf	PORTA		; Set port A for digital I/O	
	movlw	0x07
	movwf	CMCON
	bsf	STATUS,RP0	
	movlw	b'00000110'	; Set port B for displaying via LED 7 segments
	movwf	PORTB
	bcf	STATUS,RP0

Main	call	RD_Temp	; Read data from DS1820
	clrf	HALF		; A Half digit
	bcf	STATUS,C
	rrf	DS_DAT,w	; Use 7-bit upper
	rlf	HALF,f		; Store a half degree 
	movwf	DATA1		; Data for convert to decimal
	call	Convert		; Convert data to decimal
	call	Delay3		; Display data delay
	goto	Main

;**********************************************************************
;	Display On 7 Segment 					      *
;**********************************************************************
Delay3	clrf	DUMMY4		; Display data delay
DelayLp	call	Disp
	decfsz	DUMMY4,f
	goto	DelayLp	
	return

Delay2	clrf	DUMMY3		; Delay for scanning LED 7 segments	
	decfsz	DUMMY3,f
	goto	$-1	
	return	

Disp	movf	NUM1,w		; Load data to DSP1		
	call	Table_		; Convert
	btfsc	HALF,0		; Show a half degree on dot-point LED
	addlw	0x80
	call	Send_Dat		; Send data to LED 7 segments
	bcf	PORTB,6		; ON DSP1 Display 
	call	Delay2
	bsf	PORTB,6
	movf	NUM2,w		; Load data to DSP2
	call	Table_		; Convert
	call	Send_Dat		; Send data to LED 7 segments
	bcf	PORTB,7		; On DSP2
	call	Delay2
	bsf	PORTB,7		; Off DSP2
	return
	
Send_Dat movwf	SEND		; Load data
	movlw	0x08		; Loop 8 times for sending 8-bit data
	movwf	COUNT
Chk_Bit	bcf	DAT_PIN		; 
	btfsc	SEND,7		; Check bit 7 "0" or "1"	
	bsf	DAT_PIN		; Send bit 7 to shift register
Clock	bsf	CLK		; Clock pulse
	bcf	CLK		
Rotate	rlf	SEND,f		; Rotate bit for sending next bit
	decfsz	COUNT,f		; Test loop 8 times ?
	goto	Chk_Bit		; If no, send bit again
Latch	bsf	LATCH		; Latch data for displaying
	bcf	LATCH
	return	

;**********************************************************************
;	Macro for DS1820					      *
;**********************************************************************
DQLOW	macro
	bcf	DQ		; DQ bit ready
	bsf	STATUS,RP0
	bcf	DQ		; Set DQ to output
	bcf	STATUS,RP0
	endm

DQHIZ	macro
	bsf	STATUS,RP0
	bsf	DQ		; Set DQ to input
	bcf	STATUS,RP0
	endm

PAUSE	macro	DELAY		; Generate delay time
	movlw	DELAY
	movwf	DUMMY0
	call	Delay5
	endm

;**********************************************************************
;    	DS1820 1-Wire bus                                             *
;**********************************************************************
RD_Temp	call	DS_Rx		; Check chip status
	addlw	0x01		
	btfss	STATUS,Z	; Z set = ready
	return			; W is not zero = not ready

Get_Temp call	DS_Reset

	movlw	0xcc		; Skip ROM
	call	DS_Tx

	movlw	0xbe		; Read scratch pad RAM of DS1820
	call	DS_Tx
	call	DS_Rx		; Read 8-bit data 
	movwf	DS_DAT

	call	DS_Reset	; Restart

	movlw	0xcc		; Skip ROM
	call	DS_Tx

	movlw	0x44		; Start conversion
	call	DS_Tx

Delay5	nop			; Delay for PAUSE  macro
	nop	
	decfsz	DUMMY0,f
	goto	Delay5
	return

DS_Reset DQLOW
	PAUSE	0x77		; 600 microcsecond delay
	DQHIZ
	PAUSE	0x0c		; Wait  for response pulse (67 microsecond)
	nop
	nop
	movf	PORTA,w		; Read response
	andlw	0x01		; Use RA0 only
	movwf	DUMMY1
	PAUSE	0x3b		; 300 microcsecond delay
	movf	DUMMY1,w	; Response in W
	return

DS_Tx	movwf	DUMMY2		; Transmission data 
	movlw	0x08		; Prepare 8-bit counter for sending data
	movwf	DUMMY1		; Define loop counter
Tx_Loop	DQLOW			; Macro of DQ pin to low, This is start bit
	PAUSE	0x01		; 10 microsecond delay
	rrf	DUMMY2,f	; Rotate data to Carry flag
	btfsc	STATUS,C	; Test Carry flag
	bsf	DQ		; If Carry flag = "1" , set DQ to high
	PAUSE	0x0d		; 70 microsecond delay
	DQHIZ
	nop
	decfsz	DUMMY1,f	; 8 times ?
	goto	Tx_Loop		; No, send again
	return

DS_Rx	movlw	0x08		; Recieve 8-bit data
	movwf	DUMMY1
Rx_Loop	DQLOW			; Macro of DQ pin to low, this is start bit
	PAUSE	0x01		; 10 microsecond delay
	DQHIZ			; Back to high for receiving
	nop
	nop
	movf	PORTA,w		; Read data
	andlw	0x01		; Get data bit 0 only
	addlw	0xff		; Move data bit 0 to Carry flag with addition method
	rrf	DUMMY2,f	; Move data bit 0 to DUMMY bit 7
	PAUSE	0x0b		; 60 microsecond delay
	decfsz	DUMMY1,f	; Loop 8 times
	goto	Rx_Loop		; Read again
	movf	DUMMY2,w	; Save data to W register
	return

;**********************************************************************
;    	Convert Hex to  Decimal	(3 Digit)			      *
;**********************************************************************
Convert	clrf	NUM2		; Clear register of 10's unit
Check	movlw	0x0A		; 
	subwf	DATA1,w		; Subtract with 10 until lower 10
	btfss	STATUS,C	; Check subtraction result lower 10 ?
	goto	Less1		; If yes then return
	incf	NUM2,f		; If no, increase 10's unit value 
	movlw	0x0A		;  
	subwf	DATA1,f		;  Subtract with 10 until lower 10 and check result again 
	goto	Check

Less1	movf	DATA1,w		; 
	movwf	NUM1		; Send data to 1's unit display
	clrf	NUM3		; Check hundred unit
Check2	movlw	0x0A
	subwf	NUM2,w		; 
	btfss	STATUS,C	; 10's unit over 10 ?
	return			; If no then return
	incf	NUM3,f
	movlw	0x0A		; If yes, subtract again and check until the result is lower 10
	subwf	NUM2,f		
	goto	Check2
;**********************************************************************
	end







schematic diagram


litar DT.jpg

When you post code use CODE tags [alexan_e]
 
Last edited by a moderator:

Attachments

  • ScreenShot001.jpg
    ScreenShot001.jpg
    49 KB · Views: 104
this project not run properly,i think this code have some problem. The output is not what i need
 
Hi,


You need to give more info - what does 'not run properly' mean ? and what does The 'output is not what you need' mean?

Are you using actual hardware or a simulator ..?
 

Thank You Sir..The information and your suggestion is very helpful.... thank very much.

i have one question,if i use DS1820 it is same function with DS18S20???
 

hi me new here. i want to programming for 89s52 using eeprom 24c512 and sensor. when 1 sense then 72 bit data is gone.. plz send me code
 

hi me new here. i want to programming for 89s52 using eeprom 24c512 and sensor. when 1 sense then 72 bit data is gone.. plz send me code

Please start a new thread rather than crashing in on someone elses totally different problem.

You need to be more detailed in your information - what is that board ? what is the sensor ?

---------- Post added at 12:37 ---------- Previous post was at 12:34 ----------

Thank You Sir..The information and your suggestion is very helpful.... thank very much.

i have one question,if i use DS1820 it is same function with DS18S20???

The DS1820 and DS18S20 are virtually identical, the DS18B20 needs some program code modificiation.

Full details of the differences here **broken link removed**

---------- Post added at 12:38 ---------- Previous post was at 12:37 ----------

Thank You Sir..The information and your suggestion is very helpful.... thank very much.

i have one question,if i use DS1820 it is same function with DS18S20???


The DS1820 and DS18S20 are virtually identical, the DS18B20 needs some program code modificiation.

Full details of the differences here Comparison of the DS18B20 and DS18S20 1-Wire® Digital Thermometers - Maxim
 

haloo..can u check this coding for this circuit plz?? i need to finish up my project before this 8th feb ...plz help me :(




and this is the coding

RB0 EQU 000H ; Select Register Bank 0
RB1 EQU 008H ; Select Register Bank 1 ...poke to PSW to use


DIS_A EQU P0.2
DIS_B EQU P0.3
DIS_C EQU P0.4
;DIS_D EQU P0.6
DIS_D EQU P2.2
DIS_E EQU P0.5
DIS_F EQU P0.1
DIS_G EQU P0.0

DIS1 EQU P0.7
;DIS2 EQU P2.6
DIS2 EQU P0.6

LIGHT EQU P2.7

SEN1 EQU P1.0
SEN2 EQU P1.1
test EQU P1.2
test2 EQU P1.3


UP BIT 0H
DWN BIT 1H
COUNT EQU 30H
SPEED EQU 31H
VALUE_1 EQU 32H
VALUE_2 EQU 33H
NUMB1 EQU 34H
NUMB2 EQU 35H
NUMB3 EQU 36H
VISITOR EQU 37H

STACK EQU 50H


;---------==========----------==========---------=========---------
; PROCESSOR INTERRUPT AND RESET VECTORS
;---------==========----------==========---------=========---------

ORG 00H ; Reset
JMP MAIN
ORG 000BH ;Timer Interrupt0
JMP REFRESH

;---------==========----------==========---------=========---------
; Main routine. Program execution starts here.
;---------==========----------==========---------=========---------
MAIN:
MOV PSW,#RB0 ; Select register bank 0
MOV SP,STACK
CLR LIGHT
CLR test2
CLR DIS_D
MOV VISITOR,#00H
MOV SPEED,#00H
MOV COUNT,#00H
MOV VALUE_1,#15H
MOV VALUE_2,#15H
CLR DIS1
CLR DIS2

MOV TMOD,#01H ;enable timer0 for scanning
MOV TL0,#00H
MOV TH0,#0FFH
SETB ET0
SETB EA
SETB TR0 ;Start the Timer


MOV VALUE_1,#00H
MOV VALUE_2,#00H
SETB SEN1
SETB SEN2
UPP: JNB SEN1,UP_COUNT
CPL test
JB SEN2,UPP

MOV A,VISITOR ;DOWN COUNTING
CJNE A,#00,UAPS
CLR LIGHT
JNB SEN2,$
CALL DELAY
JB SEN1,$
CALL DELAY
JNB SEN1,$
CALL DELAY
AJMP UPP
UAPS: DEC VISITOR
MOV A,VISITOR
CJNE A,#00,UAPA
CLR LIGHT
UAPA: MOV R2,VISITOR
MOV R1,#00H
MOV R3,#00D
MOV R4,#00D
MOV R5,#00D
MOV R6,#00D
MOV R7,#00D
CALL HEX2BCD
MOV VALUE_2,R3
MOV VALUE_1,R4
JNB SEN2,$
CALL DELAY
JB SEN1,$
CALL DELAY
JNB SEN1,$
CALL DELAY
AJMP UPP

UP_COUNT:
SETB LIGHT
INC VISITOR
MOV A,VISITOR
CJNE A,#99,UPPS
MOV VISITOR,#98
JNB SEN1,$
CALL DELAY
JB SEN2,$
CALL DELAY
JNB SEN2,$
CALL DELAY
AJMP UPP
UPPS: MOV R2,VISITOR
MOV R1,#00H
MOV R3,#00D
MOV R4,#00D
MOV R5,#00D
MOV R6,#00D
MOV R7,#00D
CALL HEX2BCD
MOV VALUE_2,R3
MOV VALUE_1,R4
JNB SEN1,$
CALL DELAY
JB SEN2,$
CALL DELAY
JNB SEN2,$
CALL DELAY
AJMP UPP


;**************************************************
HEX2BCD:
MOV B,#10D
MOV A,R2
DIV AB
MOV R3,B ;
MOV B,#10 ; R7,R6,R5,R4,R3
DIV AB
MOV R4,B
MOV R5,A
CJNE R1,#0H,HIGH_BYTE ; CHECK FOR HIGH BYTE
SJMP ENDD

HIGH_BYTE:
MOV A,#6
ADD A,R3
MOV B,#10
DIV AB
MOV R3,B
ADD A,#5
ADD A,R4
MOV B,#10
DIV AB
MOV R4,B
ADD A,#2
ADD A,R5
MOV B,#10
DIV AB
MOV R5,B
CJNE R6,#00D,ADD_IT
SJMP CONTINUE
ADD_IT:
ADD A,R6
CONTINUE:
MOV R6,A
DJNZ R1,HIGH_BYTE
MOV B, #10D
MOV A,R6
DIV AB
MOV R6,B
MOV R7,A
ENDD: RET
;***************************************************************************
;&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
; 7 SEGMENT DISPLAY ROUTINE
;&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
DISP:
MOV R2,SPEED
CJNE R2,#00H,AAS1
CLR DIS_A
CLR DIS_B
CLR DIS_C
CLR DIS_D
CLR DIS_E
CLR DIS_F
SETB DIS_G
RET
AAS1: CJNE R2,#01H,AS2
CLR DIS_B
CLR DIS_C
SETB DIS_A
SETB DIS_D
SETB DIS_E
SETB DIS_F
SETB DIS_G
RET
AS2: CJNE R2,#02H,AS3
CLR DIS_A
CLR DIS_B
CLR DIS_D
CLR DIS_E
CLR DIS_G
SETB DIS_C
SETB DIS_F
RET
AS3: CJNE R2,#03H,AS4
CLR DIS_A
CLR DIS_B
CLR DIS_C
CLR DIS_D
CLR DIS_G
SETB DIS_E
SETB DIS_F
RET
AS4: CJNE R2,#04H,AS5
CLR DIS_B
CLR DIS_C
CLR DIS_F
CLR DIS_G
SETB DIS_A
SETB DIS_D
SETB DIS_E
RET
AS5: CJNE R2,#05H,AS6
CLR DIS_A
CLR DIS_C
CLR DIS_D
CLR DIS_F
CLR DIS_G
SETB DIS_B
SETB DIS_E
RET
AS6: CJNE R2,#06H,AS7
CLR DIS_A
CLR DIS_C
CLR DIS_D
CLR DIS_E
CLR DIS_F
CLR DIS_G
SETB DIS_B
RET
AS7: CJNE R2,#07H,AS8
CLR DIS_A
CLR DIS_B
CLR DIS_C
SETB DIS_D
SETB DIS_E
SETB DIS_F
SETB DIS_G
RET
AS8: CJNE R2,#08H,AS9
CLR DIS_A
CLR DIS_B
CLR DIS_C
CLR DIS_D
CLR DIS_E
CLR DIS_F
CLR DIS_G
RET
AS9: CJNE R2,#09H,AS10
CLR DIS_A
CLR DIS_B
CLR DIS_C
CLR DIS_D
CLR DIS_F
CLR DIS_G
SETB DIS_E
RET
AS10: CJNE R2,#15H,AS11 ;symbol for -
SETB DIS_A
SETB DIS_B
SETB DIS_C
SETB DIS_D
SETB DIS_E
SETB DIS_F
CLR DIS_G
RET
AS11: CJNE R2,#16H,AS12 ;switch off all disp
SETB DIS_A
SETB DIS_B
SETB DIS_C
SETB DIS_D
SETB DIS_E
SETB DIS_F
SETB DIS_G
RET
AS12: MOV SPEED,#00H
AJMP DISP
;**********************************************************
; INTRRUPT ROUTINE TO REFRESH THE DISPLAY
;**********************************************************
REFRESH:
PUSH PSW ; save current registerset
MOV PSW,#RB1
PUSH ACC
INC COUNT
MOV R4,COUNT
QA1: CJNE R4,#01H,QA2
MOV SPEED,VALUE_1
CLR DIS2
SETB DIS1
CALL DISP
AJMP DOWN
QA2: CJNE R4,#02H,QA3
MOV SPEED,VALUE_2
CLR DIS1
SETB DIS2
CALL DISP
AJMP DOWN
QA3: MOV COUNT,#01H
MOV R4,COUNT
AJMP QA1
DOWN: MOV TL0,#0FFH
MOV TH0,#0F0H
POP ACC
POP PSW
RETI
;**********************************************************
DELAY:
MOV R1,#4FH
REP2: MOV R2,#0FFH
REP1: NOP
DJNZ R2,REP1
DJNZ R1,REP2
RET
;**********************************************************




END
 

Attachments

  • visitor.asm.txt
    6 KB · Views: 70

sir i want ask something...
can u give me a hex file that u have convert the code that i give u???
because when i want burn into pic, the software ask for configuration...the software display like this... "No configuration for pic"
 

sir i want ask something...
can u give me a hex file that u have convert the code that i give u???
because when i want burn into pic, the software ask for configuration...the software display like this... "No configuration for pic"

Hi,

Just add in this config line of code and re Build it or enter the config value 3F21 into your programmer.

list p=16f628
#include <p16f628.inc>
errorlevel 0,-302

__CONFIG _CP_OFF & _WDT_OFF & _BODEN_OFF & _PWRTE_ON & _XT_OSC & _MCLRE_ON & _LVP_OFF ; As a config value = 3F21

CBLOCK 0x20



Hex file with config included -
 

Attachments

  • chrome.rar
    527 bytes · Views: 90
thank you sir for your help..
can you explain why we need put the config line of code into the program and what the config mean???..
 

Hi,

Simply put, the Config information tells the chip when its being programmed about how certain hardware features must be arranged to work with the software code you are programming in.

Two common parameters are MLCRE which can be enabled for a Reset Switch or Disabled.
The OSC parameter specifes what type of oscillator you want to use, such as external crystal or internal oscillator etc.


Seems you ae putting up other circuits and code to be checked out - what are you looking for ??
 

thank you sir,
one question:
in the hardware,if i touch the DS1820,the output not detect the temperature at my hand..why??
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top