8051, AT89c51, AT89s51 Programms

Temprature Controller Using LM35 and AT 89c51

Channel 3 is used with amplifire of gain 5 atteched.
Reference Voltage is 2.56Volts.
for more information of hard ware download Datasheet of AT89c51,ADC 0808 and LM35.
*************************************************************************
*************************************************************************
ORG 0000H


ADC_DATA EQU P1 ;Define Name To Port Pins

ADC_SC BIT P3.0

ADC_EOC BIT P3.1

ADC_ALE BIT P3.2

ADC_OE BIT P3.3

LCD_DATA EQU P0

LCD_RS BIT P2.4

LCD_RW BIT P2.5

LCD_E BIT P2.6

LED BIT P2.7

MOV ADC_DATA,#0FFH

CLR LED



;LCD Display Command Start



MOV DPTR,#COMD ;load Starting Address Of Command String

C1:

CLR A ;Clear Acc. For Further Opration

MOVC A,@A+DPTR ;Load Byte Of Data Located In ROM Into register A

JZ SENDDATA ;Wait For Last Command Value ZERO

ACALL COM ;Call Command Sending Routin For Sending It to LCD

ACALL READY ;Check For LCD To Be Ready For Next Data reciving

INC DPTR ;Set DPTR To Next Command Value

SJMP C1 ;Repeat Till Last Command String Ending word(ZERO) detected



;Starting Display Start



SENDDATA:

MOV DPTR,#MSG1 ;Load Starting ROM Address Of First String

ACALL D1 ;Call Data Sending Routing For Sending It to LCD

MOV A,#0C0H ;Initiate LCD Courser To Second Line & Second Character Position

ACALL COM ;Call command sending Routing for Sending it to LCD

MOV DPTR,#MSG2 ;Load Starting ROM Address Of Second String

ACALL D1 ;Call Data Sending Routing For Sending It To LCD

ACALL DELAY

MOV A,#01H ;Clear Display

ACALL COM ;Call command sending Routing for Sending it to LCD

MOV DPTR,#MSG3 ;Load Starting ROM Address Of Second String

ACALL D1 ;Call Data Sending Routing For Sending It To LCD

MOV A,#0C0H ;Move LCD Cursor On Second Line

ACALL COM ;Call command sending Routing for Sending it to LCD

MOV DPTR,#MSG4 ;Call command sending Routing for Sending it to LCD

ACALL D1 ;Call Data Sending Routing For Sending It To LCD

ACALL DELAY

MOV A,#01H ;Clear Display

ACALL COM ;Call Command sending Routing for Sending it to LCD

MOV DPTR,#MSG5 ;Call command sending Routing for Sending it to LCD

ACALL D1 ;Call Data Sending Routing For Sending It To LCD

MOV A,#0C6H ;Move LCD Cursor On Second Line 6th Position

ACALL COM ;Clear Display

MOV DPTR,#MSG6 ;Call command sending Routing for Sending it to LCD

ACALL D1 ;Call Data Sending Routing For Sending It To LCD



AGAIN2:

ACALL DISPLAY ;Call Display Routin

MOV A,R0 ;Converted Digital Data To Acc.

CJNE A,#19H,HERE4 ;Compare With 25 If Not Equal Jump To Other Location

HERE4:

JC AGAIN2 ;If No Carry Then Let LED Bit Clear



;Internal Monitering Routin



MONITOR:

SETB LED ;Set Bit

ACALL DISPLAY ;Display Temperature To LCD

MOV A,R0 ;Load Saved Data

CJNE A,#14H,HERE5 ;

HERE5:

JC HERE6

SJMP MONITOR ;Keep Monittering Bit Higher Then 20 For Clearing LED Bit

HERE6:

CLR LED ;Clear LED If Bit Is Lower then 20

SJMP AGAIN2 ;Moniter For 25



;Starting Of Data Sending Sub-Routin



D1:

CLR A ;Clear Acc.To Avoid Past Effect

MOVC A,@A+DPTR ;Load Byte Of Data Located In ROM Into register A

JZ AGAIN1 ;Leave Display Sending Sub-Routin I Last Data Zero Detected

ACALL DAT ;

ACALL READY

INC DPTR ;Increment DPTR

SJMP D1 ;Moniter Same Routin

AGAIN1:

RET ;Return to main routin



;Starting Of Command Sending Sub-Routin



COM:

ACALL READY ;Call Routin For Check Weather LCD Is Ready Or Not

MOV LCD_DATA,A ;Send Command To LCD Through Port

CLR LCD_RS ;Clear RS For Sending Command

CLR LCD_RW ;Clear R/W For Writing Data To LCD

SETB LCD_E ;Send High To Low Pulse For LCD To Latch Data Available At Data Pin

ACALL DELAY1 ;Let Pulse To Stay High For Some Moment

CLR LCD_E ;Clear Enable After Latched

RET ;Jump To Main Routin

DAT:

ACALL READY ;Check For LCD To Be Ready

MOV LCD_DATA,A ;Send Data To LCD Through Port

SETB LCD_RS ;Set RS For Sending Data

CLR LCD_RW ;Clear R/W For Writting Data To LCD

SETB LCD_E ;Send High To Low Pulse For LCD To Latch data avalable at Data Pin

ACALL DELAY1 ;Let Pulse To Stay High For Some Momment

CLR LCD_E ;Clear Enable After Latched

RET ;Jump To Main Routin

READY:

SETB LCD_DATA.7 ;Make D7 Bit Of LCD As Input To Read Status

CLR LCD_RS ;Clear RS To Access Command Reg.

SETB LCD_RW ;Set R/W Bit To Read Command Status

WAT:

CLR LCD_E ;Send Low To High Pulse

NOP ;Give LCD Some Time

NOP

SETB LCD_E ;Stay Until Busy Flag Goes Low

JB LCD_DATA.7,WAT ;Return To Main Routin

RET



;ADC Programming Start



DISPLAY:

SETB ADC_EOC ;Make EOC AS Input Port

CLR ADC_ALE

CLR ADC_SC

CLR ADC_OE

BACK:

SETB ADC_ALE ;Give High To Low Pulse To Latch Address

ACALL DELAY1

SETB ADC_SC ;Give High To Low Pulse For Start Of Cnversion

ACALL DELAY1

CLR ADC_ALE

CLR ADC_SC

HERE12:

JB ADC_EOC,HERE12 ;Wait Till ADC Complit Its Task

HERE11:

JNB ADC_EOC,HERE11 ;After ADC Put Data To Output Signal Goes High Again

SETB ADC_OE ;Set OE High For converted Data To Avalable On Controller,For Further Operation

ACALL DELAY1

MOV A,ADC_DATA ;Load Data To Acc.

; CLR C

; SUBB A,#02H

CLR ADC_OE ;Save Converted Digital Data On Memmory

MOV B,#05H ;Divide By Amplifire Gain To Get Currect Data

DIV AB

MOV R0,A ;Save New Data For Future Use



;Data Conversion Sub Routin For LCD Display Start



DISPLAY1:

MOV A,#0C6H ;Move To C6 Location For Over Writing With New Temperature Data

ACALL COM ;Call Command sending Routing for Sending it to LCD

MOV A,R0 ;Load Save Data To Acc .To Be displayed On

MOV B,#10

DIV AB

MOV R7,B ;Save Least Significant Byte (LSB)

MOV B,#10

DIV AB

MOV R6,B

ORL A,#30H ;Or With 30H To Conver Number To It's ASCII Value (MSB)

ACALL DAT ;Call Data Sending Routin

MOV A,R6

ORL A,#30H

ACALL DAT

MOV A,R7

ORL A,#30H

ACALL DAT

ACALL DELAY ;Wait For Next Sample

RET ;Return To Main Routin



;Delay

;App. 1.2749 Sec. Delay

DELAY:

MOV R3,#9

HERE13:

MOV R1,#255

HERE21:

MOV R2,#255

HERE31:

DJNZ R2,HERE31

DJNZ R1,HERE21

DJNZ R3,HERE13

RET

;App. 243 ยต Sec.

DELAY1:

MOV R3,#1

HERE1:

MOV R1,#10

HERE2:

MOV R2,#10

HERE3:

DJNZ R2,HERE3

DJNZ R1,HERE2

DJNZ R3,HERE1

RET



;Input String Start



ORG 200H

COMD:

DB 38H,01H,06H,80H,0CH,0H

MSG1:

DB " Miniproject On",0

MSG2:

DB " Temp. Control",0

MSG3:

DB " Group Member",0

MSG4:

DB " 03 04 05 & 65",0

MSG5:

DB " Temperature",0

MSG6:

DB " C",0

END