;********************************************************** ; OREGON INSTITUTE OF TECHNOLOGY ; COMPUTER HARDWARE DEPARTMENT ; ; REMOTE WEATHER STATION JUNIOR PROJECT ; DISPLAY STATION SOFTWARE ; ; Team Leader: Stefan Lever ; Team Members: James Conley ; Derek Purdy ; Khanh Nguyen ; ; Date Completed: May 13, 2004 ; ; This software was designed and written by the above ; students at Oregon Institute of Technology for Junior ; Project. This software was written for the Display ; Station. It may be modified, copied, or used for ; any purpose. However, it is only guaranteed to work ; for the system it was specifically designed for. ;********************************************************** ;*************** INTERRUPT HANDLERS *********************** ORG 00H ; Reset LJMP main ORG 03H ; INT0 RETI ; do nothing ORG 0BH ; Timer 0 LJMP isr_t0 ORG 13H ; INT1 RETI ; do nothing ORG 1BH ; Timer 1 RETI ; do nothing ORG 23H ; Serial port RETI ; do nothing ;************************ EQUATES ************************** count100 equ 64h count250 equ 0FAh firstline equ 80h ; 00h + 80h secondline equ 0C0h ; 40h + 80h thirdline equ 94h ; 14h + 80h fourthline equ 0D4h ; 54h + 80h ;******************* BIT SEGMENT*************************** BSEG AT 20h done: dbit 1 ; Transmission Time Exp. ;**************** DATA SEGMENT****************************** DSEG AT 30h linetext: ds 15h buffer: ds 4h sign: ds 4h timer: ds 1 vtemp: ds 1 vhumd: ds 1 vwspd: ds 1 vwdir: ds 1 vcsum: ds 1 vwsgt: ds 1 ;*************** DISPLAY STATION SOFTWARE********************* CSEG AT 80h main: SETB ET0 ; Enable Timer 0 Interrupt SETB PT0 ; Set priority of Timer 0 Interrupt SETB EA ; Global Enable SETB P3.7 ; Turn Off Receiving LED CALL initlcd ; initialize lcd CALL show_welcome trnstr: ; Waiting For Transmission SETB P3.7 ; Turn Off Receiving LED CLR done CALL get_trans ; First Start Byte SUBB A, #00h JNZ trnstr CALL strtmr CALL get_trans ; Second Start Byte SUBB A, #0A5h JNZ trnstr JB done, trner1 CLR P3.7 ; Turn Receive LED on CALL get_trans ; Temperature Byte MOV vtemp, A JB done, trner1 CALL get_trans ; Humidity Byte MOV vhumd, A JB done, trner1 CALL get_trans ; Wind Speed Byte MOV vwspd, A JB done, trner1 CALL get_trans ; Wind Gust Byte MOV vwsgt, A JB done, trner1 CALL get_trans ; Wind Direction Byte MOV vwdir, A JB done, trner1 CALL get_trans ; Check Sum Byte MOV vcsum, A ; Compare Check Sum CLR TR0 ; Timer 0 off MOV A, vtemp ADD A, vhumd ADD A, vwspd ADD A, vwsgt ADD A, vwdir CLR C ; Clear carry flag SUBB A, vcsum JNZ trner2 ; Print to LCD Display MOV A, vtemp ; Temperature MOV R4, vwspd ; Wind speed MOV R7, #01h CALL show_weather MOV A, vhumd ; Humidity MOV R7, #02h CALL show_weather MOV A, vwspd ; Wind Speed MOV R4, vwsgt ; Wind Gust MOV R7, #03h CALL show_weather MOV A, vwdir ; WDIRind Direction CALL show_weather JMP trnstr ; Loop to top trner1: CLR TR0 ; Timer 0 off MOV A, #1 ; Error 1 CALL print_err JMP trnstr ; Loop to top trner2: CLR TR0 ; Timer 0 off MOV A, #2 ; Error 2 CALL print_err JMP trnstr ; Loop to top ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; Start Timer - Initialize Timer ; PASSED - none ; RETURNS - none ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; strtmr: CLR TR0 CLR TF0 MOV timer, #255 MOV TMOD, #01h MOV TH0, #00h MOV TL0, #00h CLR done SETB TR0 RET ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; GET TRANSMISSION ; PASSED - none ; RETURNS - data in A ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; get_trans: trngo: JB done, trans_err ; Jump if timer has expired JNB P1.3, trngo ; Loop until TE goes high MOV A, P2 ; Read port trndn: JB P1.3, trndn ; Wait for TE to go low trans_err: RET ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; Timer 0 ISR ; PASSED - none ; RETURNS - none ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; isr_t0: PUSH ACC CLR TR0 CLR TF0 DEC timer MOV A, timer CJNE A, #00h, zer1 SETB done POP ACC RETI zer1: ; Initialize Timer MOV TMOD, #01h MOV TH0, #00h MOV TL0, #00h SETB TR0 POP ACC RETI ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; SHOW WEATHER ; PASSED - A: temperature, humidity, wind speed, wind gust, or wind direction ; - R7: 01 - temperature, 02 - humidity, 03 - wind speed, ; 04 - wind direction, 05 - wind gust ; - R4: gust value for wind speed, or wind speed value for wind chill ; RETURNS - none ; ; This function will display temperature and wind chill, humidity, ; wind speed and wind gust, and wind direction on the LCD display. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; show_weather: CALL check_num Temperature: CJNE R7, #01h, Humidity CJNE R2, #00h, nterr MOV DPTR, #Temp JMP errmsg nterr: CALL calc_wc CJNE R2, #00h, terr MOV DPTR, #Temp JMP twcs terr: CJNE R2, #02h, dtempwc MOV DPTR, #Temp JMP errmsg dtempwc: MOV DPTR, #twc twcs: CALL i8toa MOV R0, #sign MOV @R0, #0DFh INC R0 MOV @R0, #'F' INC R0 MOV @R0, #00h ; Null terminated JMP readdata Humidity: CJNE R7, #02h, Windspeed MOV DPTR, #Humid ; Convert signed integer to ascii CJNE R2, #01h, errmsg CALL i8toa MOV R0, #sign MOV @R0, #'%' INC R0 MOV @R0, #00h ; Null terminated JMP readdata Windspeed: CJNE R7, #03h, WindDirection CJNE R2, #00h, nerr ; If no error, go to nerr, else continue MOV DPTR, #WSpeed JMP errmsg nerr: PUSH ACC ; Determine if windgust (R4) is 5 mph greater than wind speed (A) SUBB A, R4 JZ s1 JNC rpos ; Jump to rneg if result is negative CPL A ; 1's complement ADD A, #01h ; 2's complement SUBB A, #06h ; Determine if result is greater than 5 JNC windgust ; R4 is greater than w speed 5 mph, display windgust s1: MOV DPTR, #WSpeed ; Move pointer to wind speed string JMP ws rpos: MOV DPTR, #WSpeed JMP errmsg windgust: MOV DPTR, #WSpg ; Move pointer to Wind speed and gust string ws: POP ACC CALL i8toa ; Convert signed integer to ascii PUSH ACC MOV R0, #sign MOV @R0, #' ' INC R0 MOV @R0, #'M' INC R0 MOV @R0, #'P' INC R0 MOV @R0, #'H' INC R0 MOV @R0, #00h ; Null terminated JMP readdata WindDirection: CJNE R7, #04h, jmp_out ; Convert signed integer to direction MOV DPTR, #WDir CALL decode_dir CJNE R2, #01h, errmsg MOV R0, #sign MOV @R0, #00h ; Null terminated JMP readdata jmp_out: LJMP show_weather_out errmsg: MOV R0, #buffer MOV @R0, #'E' INC R0 MOV @R0, #'r' INC R0 MOV @R0, #'r' INC R0 MOV @R0, #00h MOV R0, #sign MOV @R0, #00h readdata: MOV R0, #linetext MOV R6, #14h ; Set line length in R6 rloop: MOV A, #00h MOVC A, @A+DPTR MOV @R0, A INC R0 DEC R6 INC DPTR JNZ rloop ; Read buffer value DEC R0 INC R6 MOV R1, #buffer rvalue: MOV A, @R1 MOV @R0, A INC R0 DEC R6 INC R1 JNZ rvalue DEC R0 INC R6 CJNE R7, #01h, wigust ; If displaying only temperature, go to next CJNE R2, #01h, dsign ; If Wind Chill is the same, go to next MOV @R0, #'/' ; Add slash INC R0 INC R6 MOV A, R4 CALL i8toa MOV R1, #buffer rwc: MOV A, @R1 MOV @R0, A INC R0 DEC R6 INC R1 JNZ rwc ; Read sign DEC R0 INC R6 JMP dsign wigust: CJNE R7, #03h, dsign POP ACC PUSH ACC ; Determine if windgust (R4) is 5 mph greater than wind speed (A) SUBB A, R4 JZ rpos1 JNC rpos1 ; Jump to rpos1 if wind gust is less than normal wind speed CPL A ; 1's complement ADD A, #01h ; 2's complement SUBB A, #06h ; Determine if result is greater than 5 JNC dgust ; R4 is not within 5 mph, Display wind gust rpos1: POP ACC JMP dsign ; If result is greater than 5 ; Add the slash / dgust: CJNE R2, #01h, dsign ; If wind speed or wind gust has an error MOV @R0, #'/' INC R0 DEC R6 POP ACC ; Get wind gust value MOV A, R4 CALL i8toa MOV R1, #buffer rgust: MOV A, @R1 MOV @R0, A INC R0 DEC R6 INC R1 JNZ rgust ; Read sign DEC R0 INC R6 dsign: MOV R1, #sign rsign: MOV A, @R1 MOV @R0, A INC R0 DEC R6 INC R1 JNZ rsign DEC R0 INC R6 zloop: MOV @R0, #20h ; Add space to the rest of the string INC R0 DJNZ R6, zloop MOV @R0, #00h ; Add null to the end of string dweather: MOV A, #linetext ; Display text CALL putstring show_weather_out: RET ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; CALCULATE WINDCHILL ; PASSED - A: temperature, R4: Wind speed ; RETURNS - R4: wind chill, R2: 00-no wind chill, 01-need to display wind chill, 02- ERROR ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; calc_wc: PUSH 00H ; Save R0 PUSH ACC ; Save ACC SUBB A, #50 ; Subtract A from 50 to see if A is greater than 49 JNC nochange ; If it is greater than 49, no need to calculate wind chill POP ACC ; Restore ACC PUSH ACC ; Save ACC JNB ACC.7, chkwsp ; If ACC is negative, do the following ANL A, #80h ; Mask out the neg bit SUBB A, #50 ; Subtract A from 50 to see if A is greater than 49 JNC nochange ; If it is greater than 49, no need to calculate wind chill chkwsp: MOV A, R4 ; Move wind speed to A JB ACC.7, wcerr ; If it is negative, show wind chill error SUBB A, #04 ; If A is less than 4 JC nochange ; A is less than 4, no need to calculate wind chill MOV A, R4 ; Restore wind speed SUBB A, #110 ; If A is greater than 109 JNC wcerr ; It is greater than 109, show wind chill error calcwc: MOV A, R4 MOV B, #02h DIV AB MOV B, #03h MUL AB MOV B, #05h DIV AB ; Divide A by 10 MOV R4, A ; Save result to R4 POP ACC ; Restore temperature PUSH ACC ; Save ACC again MOV B, #03H JB ACC.7, negt ; Jump to negt if temperature is negative MUL AB ; Multiply temperature with 3 MOV B, #10 DIV AB ; Divide result by 10 MOV R2, A POP ACC PUSH ACC ADD A, R2 SUBB A, R4 SUBB A, #13 JB ACC.7, reneg MOV R4, A ; Put windchill to R4 JMP change reneg: CPL A ADD A, #01h ; 2's complement ORL A, #80h ; Add neg bit MOV R4, A JMP change negt: ANL A, #80h ; Mask out negative bit MUL AB MOV B, #10 ; Load 10 to divide DIV AB ; Divide A by 10 MOV R2, A POP ACC PUSH ACC ADD A, R2 ADD A, R4 ADD A, #13 ; Check to see if WC is less than -99 SUBB A, #100 JNC wcerror ORL A, #80h ; Add 1 to make it negative MOV R4, A ; Put windchill to R4 JMP change nochange: MOV R2, #00h JMP calc_wc_out wcerr: LJMP wcerror change: POP ACC ; Eestore Acc PUSH ACC JB ACC.7, aneg ; A is negative apos: ; A is positive MOV A, R4 JB ACC.7, wcneg wcpos: POP ACC PUSH ACC SUBB A, R4 ; Subtract normal temp. from wind chill JNC wcsuccess JMP wcerror ; Jump to error, since wc is less than normal temp. wcneg: MOV A, R4 ANL A, #80h MOV R2, A POP ACC PUSH ACC ADD A, R2 JMP wcsuccess aneg: MOV A, R4 ; A is negative JNB ACC.7, wcerror ANL A, #80h MOV R2, A POP ACC PUSH ACC ANL A, #80h SUBB A, R2 ; Subtract normal temperature from wind chill JNC wcsuccess JMP wcerror ; Jump to error, since wind chill is greater than temperature wcsuccess: SUBB A, #06h ; Check if the difference is less than 5 JC nochange MOV R2, #01h JMP calc_wc_out wcerror: MOV R2, #02h JMP calc_wc_out calc_wc_out: POP ACC POP 00H ; Restore R0 RET ;;;;;;;;;;;;;;;;;;;;;; ; INITIALIZE LCD ; PASSED - none ; RETURNS - none ;;;;;;;;;;;;;;;;;;;;;; initlcd: CALL delay4 ; Delay 40ms CALL delay4 CALL delay4 CALL delay4 MOV A, #38h ; Write 1st initialization command CALL send_lcd_command CALL delay4 ; Delay 10ms MOV A, #38h ; Write 2nd initialization command CALL send_lcd_command CALL delay ; Delay 130ms MOV A, #38h ; Write 3rd initialization command CALL send_lcd_command CALL delay1 ; Delay 1ms MOV A, #38h ; Write 4th initialization command CALL send_lcd_command displayoff: CALL delay1 ; Delay 2ms CALL delay1 MOV A, #08h ; Write display off CALL send_lcd_command displayclear: CALL delay1 ; Delay 2ms CALL delay1 MOV A, #01h ; Write clear display CALL send_lcd_command entrymode: CALL delay1 ; Delay 2ms CALL delay1 MOV A, #06h ; Write enter entry mode CALL send_lcd_command displayon: CALL delay1 ; Delay 2ms CALL delay1 MOV A, #0ch ; Write display on CALL send_lcd_command displayclear2: CALL delay1 ; Delay 2ms CALL delay1 MOV A, #01h ; Write clear display CALL send_lcd_command RET ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; PUTSTRING ; PASSED - A: address of the zero terminated string to display on LCD ; - R7: specify line to write to (only 0-4 allowed, 0 for current position) ; 0 - current position, 1 - line 1, 2 - line 2, 3 - line 3, 4 - line 4 ; ; This routine displays the zero terminated string from the address passed into A ; to a specific line on the LCD passed into R7. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; putstring: ; Get address of zero terminated string MOV R0, A ; Move string address to R0 MOV R6, #14h ; LCD line length ; Set cursor position zero: CJNE R7, #00h, one JMP dloop one: CJNE R7, #01h, two CALL delay1 CALL delay1 MOV A, #firstline CALL send_lcd_command ; Set to first line JMP dloop two: CJNE R7, #02h, three CALL delay1 CALL delay1 MOV A, #secondline CALL send_lcd_command ; Set to second line JMP dloop three: CJNE R7, #03h, four CALL delay1 CALL delay1 MOV A, #thirdline CALL send_lcd_command ; Set to third line JMP dloop four: CJNE R7, #04h, out CALL delay1 CALL delay1 MOV A, #fourthline CALL send_lcd_command ; Set to fourth line dloop: CALL delay1 ; Delay 2ms CALL delay1 MOV A, @R0 ; Move character at R0 address to A JZ out ; Jump out if the character is zero CALL send_lcd_data ; Send character to LCD INC R0 DJNZ R6, dloop ; Continue to send character to LCD if it's not the end of the line out: RET ;;;;;;;;;;;;;;;;;;;;;;;;;;; ; PRINT ERROR ; PASSED - A: error code ; RETURNS - none ;;;;;;;;;;;;;;;;;;;;;;;;;;; print_err: CALL i8toa ; Display error code CALL delay1 ; Delay 2ms CALL delay1 MOV A, #0D3h CALL send_lcd_command ; Set current position to end of second line MOV A, #buffer MOV R7, #00h CALL putstring ; Put error code onto LCD MOV R0, #buffer ; Display E MOV @R0, #'E' INC R0 MOV @R0, #00h ; Null terminated string CALL delay1 ; Delay 2ms CALL delay1 MOV A, #93h CALL send_lcd_command ; Set current position to end of first line MOV A, #buffer MOV R7, #00h CALL putstring RET ;;;;;;;;;;;;;;;;;;;;;;;; ; SHOW WELCOME SCREEN ; PASSED - none ; RETURNS - none ;;;;;;;;;;;;;;;;;;;;;;;; show_welcome: CALL delay1 ; Clear LCD CALL delay1 ; Delay 2ms MOV A, #01h ; Write clear display CALL send_lcd_command MOV R0, #linetext ; Clear line text MOV R6, #14h c1: MOV @R0, #' ' INC R0 DJNZ R6, c1 MOV R0, #linetext ; Get first line MOV DPTR, #james CALL read_code MOV R0, #linetext+0Eh MOV DPTR, #stefan CALL read_code ; Print first line CALL delay1 ; Delay 2ms CALL delay1 MOV A, #linetext MOV R7, #01h ; Set to 1st line CALL putstring MOV R0, #linetext ; Clear line text MOV R6, #14h c2: MOV @R0, #' ' INC R0 DJNZ R6, c2 MOV R0, #linetext+07h ; Get third line MOV DPTR, #rws CALL read_code ; Print third line CALL delay1 ; Delay 2ms CALL delay1 MOV A, #linetext MOV R7, #03h ; Set to 3rd line CALL putstring MOV R0, #linetext ; Clear line text MOV R6, #14h c3: MOV @R0, #' ' INC R0 DJNZ R6, c3 MOV R0, #linetext ; Get fourth line MOV DPTR, #derek CALL read_code MOV R0, #linetext+0Fh MOV DPTR, #khanh CALL read_code ; Print fourth line CALL delay1 ; Delay 2ms CALL delay1 MOV A, #linetext MOV R7, #04h ; Set to 4th line CALL putstring RET ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; READ CODE ; PASSED - R0: address of a variable ; - DPTR: address of code string ; RETURNS - none ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; read_code: rcloop: MOV A, #00h MOVC A, @A+DPTR JZ rcout MOV @R0, A INC R0 INC DPTR JMP rcloop rcout: RET ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; DECODE WIND DIRECTION ; PASSED - A: 8 bit unsign number ; RETURNS - R2: 0 - fail, 1 - success ; ; This subroutine decodes an 8 bit number from A to wind direction ; and places the null terminated string in buffer. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; decode_dir: MOV R2, #01h MOV R0, #buffer ; Get buffer's address CJNE A, #0Fh, st JMP noval st: PUSH ACC ; Save A ANL A, #0F0h ; Mask out the LOWER nibble N: CJNE A, #10h, E ; North MOV @R0, #'N' INC R0 JMP next E: CJNE A, #20h, S ; East MOV @R0, #'E' INC R0 JMP next S: CJNE A, #40h, W ; South MOV @R0, #'S' INC R0 JMP next W: CJNE A, #80h, nzero ; West MOV @R0, #'W' INC R0 JMP next nzero: CJNE A, #00h, pnoval next: POP ACC ; Restore A PUSH ACC ANL ACC, #0Fh ; Mask out the HIGH nibble MOV R3, A POP ACC ANL ACC, #0F0h ; Mask out the LOWER nibble CJNE R3, #0Eh, SE JB ACC.4, NE1 JB ACC.5, NE1 CJNE A, #00h, noval NE1: MOV @R0, #'N' INC R0 MOV @R0, #'E' INC R0 JMP dout SE: CJNE R3, #0Dh, SW JB ACC.5, SE1 JB ACC.6, SE1 CJNE A, #00h, noval SE1: MOV @R0, #'S' INC R0 MOV @R0, #'E' INC R0 JMP dout SW: CJNE R3, #0Bh, NW JB ACC.6, SW1 JB ACC.7, SW1 CJNE A, #00h, noval SW1: MOV @R0, #'S' INC R0 MOV @R0, #'W' INC R0 JMP dout NW: CJNE R3, #07h, fff JB ACC.7, NW1 JB ACC.4, NW1 CJNE A, #00h, noval NW1: MOV @R0, #'N' INC R0 MOV @R0, #'W' INC R0 JMP dout fff: CJNE R3, #0Fh, noval JMP dout pnoval: POP ACC noval: MOV R2, #00h dout: MOV @R0, #00h ; Add null to the end RET ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; CHECK_NUM ; PASSED - A: signed integer ; - R7: weather type(01 - temp, 02 - humid, 03 - wind speed) ; - R4: wind gust ; RETURNS - R2: fail - 00, success - 01 ; REGISTERS AFFECTED - R0, R2, ACC ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; check_num: PUSH ACC ; Save ACC CJNE R7, #01h, hnum JNB ACC.7, suc CJNE A, #80h, k JMP fa k: ANL A, #7Fh ; Mask out the negative bit MOV R0, A MOV A, #28h ; 40d CLR C SUBB A, R0 JNC suc JMP fa hnum: CJNE R7, #02h, wsnum JB ACC.7, fa MOV R0, A MOV A, #64h ; 100d CLR C SUBB A, R0 JNC suc JMP fa wsnum: CJNE R7, #03h, cout JB ACC.7, fa MOV A, R4 JB ACC.7, fa ; Wind gust failed suc: MOV R2, #01h JMP cout fa: MOV R2, #00h cout: POP ACC RET ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; INTEGER TO ASCII ; PASSED - A: signed integer ; RETURNS - buffer: null terminated string ; ; This routine converts an 8 bit signed integer from A ; to an ASCII character and returns the string. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; i8toa: ; Save R0 and ACC PUSH 00h ; R0 PUSH ACC MOV R0, #buffer ; Buffer's address PUSH ACC ; Check for type of number ANL A, #80h CJNE A, #80h, notNegative MOV @R0, #'-' ; Store sign if it's negative INC R0 ; Increment character pointer POP ACC ; Restore integer ANL A, #7Fh ; Mask out the negative bit PUSH ACC notNegative: POP ACC PUSH ACC ; Reserve integer MOV R5, #0h ; R5 holds number of digits countDigits: MOV B, #0Ah ; Move 10 to B INC R5 DIV AB CJNE A, #00h, countDigits convert: MOV A, R0 ADD A, R5 MOV R0, A MOV @R0, #00h DEC R0 convertLoop: POP ACC cloop: MOV B, #0Ah ; Move 10 to B DIV AB PUSH ACC MOV A, B ADD A, #30h ; Add 30h to digit to make it ASCII MOV @R0, A DEC R0 POP ACC DJNZ R5, cloop ; Restore R0 and ACC POP ACC POP 00h ; R0 RET ;;;;;;;;;;;;;;;;;;;;;;;;;;; ; SEND LCD COMMAND ; PASSED - A: command ; RETURNS - none ;;;;;;;;;;;;;;;;;;;;;;;;;; send_lcd_command: CLR P1.0 ; Set RS low CLR P1.1 ; Set RW low MOV P0, A ; Write command CALL delay1 ; Delay 1ms SETB P1.2 ; Set E high CALL delay1 ; Delay 1ms CLR P1.2 ; Set E low RET ;;;;;;;;;;;;;;;;;;;;; ; SEND LCD DATA ; PASSED - A: data ; RETURNS - none ;;;;;;;;;;;;;;;;;;;;; send_lcd_data: SETB P1.0 ; Set RS high CLR P1.1 ; Set RW low MOV P0, A ; Write command CALL delay1 ; Delay 1ms SETB P1.2 ; Set E high CALL delay1 ; Delay 1ms CLR P1.2 ; Set E low RET ;;;;;;;;;;;;;;;;;;;;;;; ; DELAY 130ms ; PASSED - nothing ; RETURNS - nothing ;;;;;;;;;;;;;;;;;;;;;;; delay: MOV R2, #02h loop0: MOV R3, #count250 loop3: MOV R1, #count250 loop4: DJNZ R1, loop4 DJNZ R3, loop3 DJNZ R2, loop0 RET ;;;;;;;;;;;;;;;;;;;;;;; ; DELAY 10ms ; PASSED - nothing ; RETURNS - nothing ;;;;;;;;;;;;;;;;;;;;;;; delay4: MOV R1, #28h loop5: MOV R2, #count250 loop6: DJNZ R2, loop6 DJNZ R1, loop5 RET ;;;;;;;;;;;;;;;;;;;;;;;; ; DELAY 1ms ; PASSED - nothing ; RETURNS - nothing ;;;;;;;;;;;;;;;;;;;;;;;; delay1: MOV R1, #04h loop1: MOV R2, #count250 loop2: DJNZ R2, loop2 DJNZ R1, loop1 RET ;***************String Constants*************** temp: db 'Temperature: ',0 twc: db 'Temp/WC: ',0 humid: db 'Rel Humidity: ',0 wspeed: db 'Wind Speed: ',0 wspg: db 'W Sp/G: ',0 wdir: db 'Wind Direction: ',0 stefan: db 'Stefan',0 derek: db 'Derek',0 rws: db 'R W S',0 khanh: db 'Khanh',0 james: db 'James',0 END