Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $MODDE2
- org 0000H
- ljmp myprogram
- Load32 MAC
- mov %0 + 0, #low(%1 % 10000H)
- mov %0 + 1, #high(%1 % 10000H)
- mov %0 + 2, #low(%1 / 10000H)
- mov %0 + 3, #high(%1 / 10000H)
- ENDMAC
- SCLK EQU P1.1
- MOSI EQU P1.2
- MISO EQU P1.3
- CE_ADC EQU P1.4
- cseg
- Name1:
- DB 'T: Celsius'
- DB 0
- Name2:
- DB ' '
- DB 0
- Wait40us:
- mov R5, #149
- X1:
- djnz R5, X1 ; 3 machine cycles-> 3*90ns*149=40us
- ret
- INIT_SPI:
- orl P1MOD, #00010110b ; Set SCLK, MOSI, CE_ADC as outputs
- anl P1MOD, #11110111b ; Set MISO as input
- clr SCLK ; Mode 0,0 default
- ret
- Delay:
- mov R3, #20
- Delay_loop:
- djnz R3, Delay_loop
- ret
- DO_SPI_G:
- push acc
- mov R1, #0 ; Received byte stored in R1
- mov R2, #8 ; Loop counter (8-bits)
- DO_SPI_G_LOOP:
- mov a, R0 ; Byte to write is in R0
- rlc a ; Carry flag has bit to write
- mov R0, a
- mov MOSI, c
- setb SCLK ; Transmit
- mov c, MISO ; Read received bit
- mov a, R1 ; Save received bit in R1
- rlc a
- mov R1, a
- clr SCLK
- djnz R2, DO_SPI_G_LOOP
- pop acc
- ret
- LCD_command:
- mov LCD_DATA, A
- clr LCD_RS
- setb LCD_EN
- clr LCD_EN
- ljmp Wait40us
- ret
- LCD_put:
- mov LCD_DATA, A
- setb LCD_RS
- setb LCD_EN
- clr LCD_EN
- ljmp Wait40us
- ret
- LCDON:
- setb LCD_ON
- lcall Wait40us
- mov LCD_MOD, #0xff ; Use LCD_DATA as output port
- clr LCD_RW ; Only writing to the LCD in this code.
- mov a, #0CH ; Display on command
- lcall LCD_command
- mov a, #38H ; 8-bits interface, 2 lines, 5x7 characters
- lcall LCD_command
- mov a, #01H ; Clear screen (Warning, very slow command!)
- lcall LCD_command
- ; Delay loop needed for 'clear screen'
- ; command above (1.6ms at least!)
- mov R1, #40
- clr_loop:
- lcall Wait40us
- djnz R1, Clr_loop
- ret
- send_msg:
- clr a
- movc a, @a+dptr
- jz second
- inc dptr
- lcall LCD_put
- sjmp send_msg
- ret
- send_msg2:
- clr a
- movc a, @a+dptr
- jz forever
- inc dptr
- lcall LCD_put
- sjmp send_msg2
- ret
- myprogram:
- mov SP, #7FH
- mov LEDRA, #0 ; Turn off all LEDs
- mov LEDRB, #0
- mov LEDRC, #0
- mov LEDG, #0
- lcall INIT_SPI
- lcall LCDON
- mov a,#80H
- lcall LCD_command
- mov dptr, #Name1
- lcall send_msg
- second:
- mov a, #0C0H
- lcall LCD_command
- mov dptr, #Name2
- lcall send_msg2
- forever:
- clr CE_ADC
- mov R0, #00000001B ; Start bit:1, Single:1, D2: 0
- lcall DO_SPI_G
- Read_Temp:
- mov R0, #10000000B ; Read channel 0; D1 (bit 7): 0, D0 (bit 6):0
- lcall DO_SPI_G
- mov a, R1 ; R1 contains bits 8 to 9
- anl a, #03H
- mov LEDRB, a
- mov R7, a
- mov R0, #55H ; It doesn't matter what we transmit...
- lcall DO_SPI_G
- mov LEDRA, R1 ; R1 contains bits 0 to 7
- mov a,R1
- mov R6,a
- lcall display_temp
- setb CE_ADC
- lcall Delay
- ljmp forever
- display_temp:
- mov a, #83H
- lcall LCD_command
- lcall ADC_to_Celcius
- ret
- ADC_to_Celcius:
- ; [R7,R6] has the 10-bit value
- ; from the converter
- mov x+0, R6
- mov x+1, R7
- mov x+2, #0
- mov x+3, #0
- Load32 (y, 500000)
- lcall mul32
- Load32 (y, 1024)
- lcall div32
- Load32 (y, 50000)
- lcall sub32
- lcall hex2bcd
- ; Display temperature in LCD
- ;*******************************NEED TO FIGURE OUT THE SIGFIGS
- ;most sig digit
- mov a, bcd+2
- swap a
- anl a, #0FH
- add a, #30h
- orl a, #'0'
- lcall LCD_put
- ;2nd most sig
- mov a, bcd+2
- anl a, #0FH
- add a, #30h
- orl a, #'0'
- lcall LCD_put
- ; Decimal point
- mov a, #'.'
- lcall LCD_put
- ; 3rd
- mov a, bcd+1
- swap a
- anl a, #0FH
- add a, #30h
- orl a, #'0'
- lcall LCD_put
- ret
- ; start here
- $include(math32.asm)
- END
Add Comment
Please, Sign In to add comment