|

C and Assembly Code for 8051 based temperarture Monitoring System

INTRODUCTION :

Ladies and Gentlemen, way back couple of weeks I posted a working model for 8051/8052 based temperature monitoring system. The C and Assembly Code was in the pending tray. Please note that the monitoring system includes LCD, the programming for which had also been integrated below. In fact this is the whole program for complete temperature monitoring system.  The subject coding for microcontroller 8051 is discussed with sufficient comments below. Moreover if you find any difficulty regarding the coding or the the description, you are more than welcome to contact the owner of this term project at jamalel640@hotmail.com


CODE :


;OBJECTIVE:  TEMPERATURE MONITORING SYSTEM






;THIS PROGRAM DISPLAY TEMPERATURE ON LCD BY USING LM35

;PROGRAMER: JAMAL

;BATCH : 2007

;PROGRAM NAME: TEMPERATURE SENSOR

;MICROCONTROLLER: ATMEL AT89S52



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



;........DEFINING VARIABLES..........



ORG 0000H



RS_LCD BIT P1.5 ;pins 1.5,1.6,1.7 of microcontroller

RW_LCD BIT P1.6 ; is connected with register select,

EN_LCD BIT P1.7 ; write and enable pin of lcd

OUTPUT_LCD EQU P3 ; port3 is connected with data pins of

OUTPUT_ADC EQU P2 ; lcd

STR_PTR_ADC EQU 35H ; STR_PTR_ADC is a memory location

CS_ADC BIT P3.0

RD_ADC BIT P3.1

WR_ADC BIT P3.2

INTR_ADC BIT P3.3





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



;................MAIN PROGRAM.......................







CLR EN_LCD ; make en=0

CALL SEND_STRING ; call subroutine

HERE: CALL LM35_ADC

CALL SEND_HEX_TO_DEC

SJMP HERE



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



;.........ROUTINE FOR DISPLAYING STRING..............



SEND_STRING: CALL INIT_LCD

MOV OUTPUT_LCD,#80H ; address for the first line of lcd

CALL WR_LCD_COMMAND ; call routines to initalize lcd

CALL WAIT_LCD ; call routine to check busy flag

MOV DPTR,#STRING ; move 16 bit string to data pointer

MOV STR_PTR_ADC,#0FFH ; make STR_PTR_ADC an input

STRING_ROUTINE:

INC STR_PTR_ADC

MOV A,STR_PTR_ADC

MOVC A,@A+DPTR ; move string to A

CJNE A,#'$',DISP_AGN ; check the condition

JMP EXIT_LCD_MSG

DISP_AGN: MOV OUTPUT_LCD,A ; move data of A to lcd

SETB RS_LCD ; make rs=1

CLR RW_LCD ; make rw=0

SETB EN_LCD ; apply high to low pulse for writing data

CLR EN_LCD

CALL WAIT_LCD

JMP STRING_ROUTINE

EXIT_LCD_MSG:

RET



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



;...........ROUTINE TO CONVERT HEXADECIMAL NUMBER TO DECIMAL NUMBER...........



SEND_HEX_TO_DEC:MOV A,OUTPUT_ADC ; data come from adc data pins

CJNE A,#01100100B,CONVERSION ; jump occurs if A is not equal to 100

MOV B,#10 ; move 10 in B

DIV AB ; process to convert hexadecimal number

MOV R7,B ; into decimal number by dividing by 10

MOV B,#10 ; store the result in registers

DIV AB

MOV R6,B

MOV R5,A

CALL DISPLAY

BACK:

RET



CONVERSION: MOV B,#10

DIV AB

MOV R3,A

MOV OUTPUT_LCD,#8CH ; address to show number on lcd

CALL WR_LCD_COMMAND

CALL WAIT_LCD

MOV A,R3

ADD A,#30H

CALL WR_LCD_DATA ; call subroutine to send data to lcd

MOV A,B

ADD A,#30H ; subtract 30H from A to convert from ascii

CALL WR_LCD_DATA ; character

MOV A,#'C'

CALL WR_LCD_DATA

JMP BACK



DISPLAY: MOV OUTPUT_LCD,#8CH ; address to show number on lcd

CALL WR_LCD_COMMAND

CALL WAIT_LCD

MOV A,R5 ; most significant digit

ADD A,#30H

CALL WR_LCD_DATA

mov A,R6

ADD A,#30H

CALL WR_LCD_DATA

mov A,R7 ; least significant digit

ADD A,#30H

CALL WR_LCD_DATA

MOV A,#'C'

CALL WR_LCD_DATA

RET



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



;...........ROUTINE FOR INITALIZATION OF LCD.............



INIT_LCD: MOV R0,#04H ; loop to initalize to lines of lcd

MOV OUTPUT_LCD,#38H ; by sending 38H

AGAIN: CALL WR_LCD_COMMAND

DJNZ R0,AGAIN

CALL WAIT_LCD

MOV OUTPUT_LCD,#0EH ; display on,cursor on

CALL WR_LCD_COMMAND

CALL WAIT_LCD

MOV OUTPUT_LCD,#01H ; clear lcd screen

CALL WR_LCD_COMMAND

CALL WAIT_LCD

RET



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



;.......... ROUTINE FOR SENDING COMMANDS TO LCD.............



WR_LCD_COMMAND: CLR RS_LCD ; commands are sent by making rs=0,

CLR RW_LCD ; rw=0, and high to low pulse on

SETB EN_LCD ; enable pin

CLR EN_LCD



RET



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



;..........ROUTINE FOR SENDING DATA TO LCD..................



WR_LCD_DATA: MOV OUTPUT_LCD,A

SETB RS_LCD ; commands are sent by making rs=1,

CLR RW_LCD ; rw=0, and high to low pulse on

SETB EN_LCD ; enable pin

CLR EN_LCD

CALL WAIT_LCD

RET



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



;..........ROUTINE FOR CHECKING BUSY FLAG OF LCD.............



WAIT_LCD: MOV OUTPUT_LCD,#0FFH ; make port 3 an input port

CLR EN_LCD

CLR RS_LCD

SETB RW_LCD

SETB EN_LCD

MOV A,OUTPUT_LCD

JB ACC.7,WAIT_LCD

CLR EN_LCD ; clear the enable for other commands

ret



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



;........... STRING TO BE DISPALYED ON LCD.....................



ORG 100H



STRING: DB 'TEMPERATURE=$' ; string end with a null character

; $ sign shows end of string

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



;............TEMPERATURE FROM LM35 INTO ADC..........................



LM35_ADC: MOV OUTPUT_ADC,#0FFH ; make port2 an input port

SETB INTR_ADC

CLR CS_ADC

SETB RD_ADC

CLR WR_ADC

SETB WR_ADC

JB INTR_ADC,$

CLR RD_ADC

NOP

SETB CS_ADC

RET



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



END ; end of program

Posted by Muhammad Ahmed on 17:47. Filed under , , . You can follow any responses to this entry through the RSS 2.0. Feel free to leave a response

Labels

Recently Commented

Recently Added