Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ;********************************************************************
- ; Authors : Tomer Gross - 322712753, Yaniv Korobkin - 207329525
- ; Date : 14 on January, 2020
- ; File : voltmeter_project.asm
- ; Description : sample the voltage of the analog signal and send it through the uart
- ; every time that 'M' pressed
- ;********************************************************************
- #include<ADUC841.H>
- BSEG ; define flags
- ADC_FLAG: DBIT 0 ; set when adc done sample
- TI_FLAG: DBIT 0 ; set when TI is set
- RI_FLAG: DBIT 0 ; set when we received 'M'
- CSEG AT 00h
- JMP START
- CSEG AT 23h ; serial ISR
- JMP CHECK_INPUT
- CSEG AT 33H ; adc ISR
- SETB ADC_FLAG
- RETI
- CSEG AT 0100H
- ;______________________________________________________________________________
- ; SERIAL INTERRUPT HANDLING
- ; in addition to prevent ovarlapping we handling the serial interrupt outside of the ISR
- CHECK_INPUT:
- JBC TI, DONE_TRANSMITTING ; if done transmiting then jump and clear TI
- CHECK:
- MOV R1, SBUF ; get the pressed key's ASCII value
- CJNE R1, #'M', NOT_M ; in the case which the pressed key isnt 'M'
- SETB RI_FLAG
- JMP NOT_M ; we need to clear TI&RI anyway to prevent redundent call for the interrupt service routine
- DONE_TRANSMITTING:
- SETB TI_FLAG ; set to alert that a new character can be trasmitting
- NOT_M:
- CLR RI
- JMP INVALID_INPUT
- RETI
- ;____________________________________________________________________
- ; MAIN PROGRAM
- START:
- ; set UART
- ; puts the UART in 8-bit variable baud rate mode
- CLR SM0
- SETB SM1
- SETB REN ;allow recieved signals
- ; setting timer 3
- ANL T3CON, #11111010B ; bit7 = enable bit, reserving bits 6-3, we allow only mode 010 (DIV=2)
- ORL T3CON, #10000010B ; bit7 = enables Timer 3 to provide the clock to the UART, bits 2-0: DIV = 2 = 010
- MOV T3FD, #32 ; baud-rate=115200bps according to formulas (as shown in the documentations)
- ; ADC setup
- MOV ADCCON1, #10111000B ; bit7 = adc mode is on, bit6 = disable external vref (as default its 2.5[v] - as we want), reserving bits 5-3, disable 3 last bits
- MOV ADCCON2, #00000000B ; we want to ensure that adc2 isnt working
- SETB ES ; allow serial interrupts
- SETB EADC ; allow adc interrupts
- SETB EA ; allow global interrupts (should be last!)
- POLLING:
- ; busy wait - release when we receive 'M'
- ;JNB RI_FLAG, $
- CLR RI_FLAG ; allow to get more 'M's
- ;____________________________________________________________________
- ; SUBROUTINES
- SAMPLE:
- PUSH PSW
- PUSH ACC
- SETB SCONV ; sample the analog signal
- ; waiting for the adc to finish sample
- JNB ADC_FLAG, $
- CLR ADC_FLAG
- PROGRAM:
- MOV A, ADCDATAL ; save the low order adc data into the accumulator (we will take only the 4MSBs)
- SWAP A ; we want the 4MSBs to be in the low order location
- ANL A, #00001111B ; we dont care about 4 MSB now because they were the 4LSBs before the swap
- MOV R2, A ; R2 saves the 4lsb in the new 8bit combined register
- MOV A, ADCDATAH ; we know that in 8 bit mode the 4 high bits of ADCDATAH are zeros anyway
- SWAP A ; we want the 4LSBs to be in the high order location
- MOV R3, A ; R3 saves the 4msbs in the new 8bit combined register
- CLR A ; ensures that accumulator is cleared
- ; combine the results into 8bit register
- MOV A, R2
- ADD A, R3
- MOV R4, A ; combined
- MOV A, R4 ; the accumulator saves the offset divided by 4, from the start of the volts table
- MOV B, #4D ; multiply it by 4 to get the real offset of the 4 bits string (any volt lvl is in the format: "x.xx", length of 4)
- MUL AB ; according to table we built, each voltage level its in location of multiplication of 4
- MOV DPTR, #VOLTS ; dptr point to the start of the table
- ; max offset is 250(for 2.5 volts)*4 = 1000d that can be represented in atleast 10 bits so its devided between two 8 bits register
- ; that can save together offset of length 16 bits
- ; A contains the 8 low bits of the offset - going to DPL
- ADD A, DPL
- MOV DPL, A
- ; B contains the 8 high bits of the offset - going to DPH
- MOV A, B
- ADD A, DPH
- MOV DPH, A
- ;MOV R3, A ; the string address
- ;MOV DPTR, A
- MOV R5, #4D ; repeat 4 times - length of output
- CLR REN ; block received signals while transmiting string
- TRAN_STRING:
- CLR A
- MOVC A, @A+DPTR ; get character
- MOV SBUF, A ; transmit to the uart
- JNB TI_FLAG, $ ; wait for transmitting over
- CLR TI_FLAG ; allow transmitting other characters
- INC DPTR ; move on to the next character
- DJNZ R5, TRAN_STRING ; repeat r5 times
- MOV SBUF, #13D ; transmit carriage return
- JNB TI_FLAG, $
- CLR TI_FLAG
- MOV SBUF, #10D ; transmit line feed
- JNB TI_FLAG, $
- CLR TI_FLAG
- SETB REN ; allow signals again
- POP ACC
- POP PSW
- JMP POLLING
- INVALID_INPUT: CLR REN
- PUSH PSW
- PUSH ACC
- CLR A
- MOV DPTR, #ERR
- MOV R5, #16D
- PRINTING:
- MOVC A, @A+DPTR
- MOV SBUF, A
- JNB TI_FLAG, $ ; wait for transmitting over
- CLR TI_FLAG
- INC DPTR ; move on to the next character
- DJNZ R5, PRINTING
- SETB REN ; allow signals again
- POP ACC
- POP PSW
- SETB REN
- RETI
- ;____________________________________________________________________
- ; VOLTS TABLE
- CSEG AT 0150H
- ERR:
- DB 'Invalid input'
- DB 13
- DB 10
- DB 0
- CSEG AT 0200H
- VOLTS:
- ; theoretically the voltage that can be represented in 8 bit register can arrive to 2.55[v] but
- ; practically the Vref is just 2.5[v] so its never can reach this value
- DB '0.00'
- DB '0.01'
- DB '0.02'
- DB '0.03'
- DB '0.04'
- DB '0.05'
- DB '0.06'
- DB '0.07'
- DB '0.08'
- DB '0.09'
- DB '0.10'
- DB '0.11'
- DB '0.12'
- DB '0.13'
- DB '0.14'
- DB '0.14'
- DB '0.15'
- DB '0.16'
- DB '0.17'
- DB '0.18'
- DB '0.19'
- DB '0.20'
- DB '0.21'
- DB '0.22'
- DB '0.23'
- DB '0.24'
- DB '0.25'
- DB '0.26'
- DB '0.27'
- DB '0.28'
- DB '0.29'
- DB '0.30'
- DB '0.31'
- DB '0.32'
- DB '0.33'
- DB '0.34'
- DB '0.35'
- DB '0.36'
- DB '0.37'
- DB '0.38'
- DB '0.39'
- DB '0.40'
- DB '0.41'
- DB '0.42'
- DB '0.43'
- DB '0.44'
- DB '0.45'
- DB '0.46'
- DB '0.47'
- DB '0.48'
- DB '0.49'
- DB '0.50'
- DB '0.51'
- DB '0.52'
- DB '0.53'
- DB '0.54'
- DB '0.55'
- DB '0.56'
- DB '0.57'
- DB '0.58'
- DB '0.59'
- DB '0.60'
- DB '0.61'
- DB '0.62'
- DB '0.63'
- DB '0.64'
- DB '0.65'
- DB '0.66'
- DB '0.67'
- DB '0.68'
- DB '0.69'
- DB '0.70'
- DB '0.71'
- DB '0.72'
- DB '0.73'
- DB '0.74'
- DB '0.75'
- DB '0.76'
- DB '0.77'
- DB '0.78'
- DB '0.79'
- DB '0.80'
- DB '0.81'
- DB '0.82'
- DB '0.83'
- DB '0.84'
- DB '0.85'
- DB '0.86'
- DB '0.87'
- DB '0.88'
- DB '0.89'
- DB '0.90'
- DB '0.91'
- DB '0.92'
- DB '0.93'
- DB '0.94'
- DB '0.95'
- DB '0.96'
- DB '0.97'
- DB '0.98'
- DB '0.99'
- DB '1.00'
- DB '1.01'
- DB '1.02'
- DB '1.03'
- DB '1.04'
- DB '1.05'
- DB '1.06'
- DB '1.07'
- DB '1.08'
- DB '1.09'
- DB '1.10'
- DB '1.11'
- DB '1.12'
- DB '1.13'
- DB '1.14'
- DB '1.15'
- DB '1.16'
- DB '1.17'
- DB '1.18'
- DB '1.19'
- DB '1.20'
- DB '1.21'
- DB '1.22'
- DB '1.23'
- DB '1.24'
- DB '1.25'
- DB '1.26'
- DB '1.27'
- DB '1.28'
- DB '1.29'
- DB '1.30'
- DB '1.31'
- DB '1.32'
- DB '1.33'
- DB '1.34'
- DB '1.35'
- DB '1.36'
- DB '1.37'
- DB '1.38'
- DB '1.39'
- DB '1.40'
- DB '1.41'
- DB '1.42'
- DB '1.43'
- DB '1.44'
- DB '1.45'
- DB '1.46'
- DB '1.47'
- DB '1.48'
- DB '1.49'
- DB '1.50'
- DB '1.51'
- DB '1.52'
- DB '1.53'
- DB '1.54'
- DB '1.55'
- DB '1.56'
- DB '1.57'
- DB '1.58'
- DB '1.59'
- DB '1.60'
- DB '1.61'
- DB '1.62'
- DB '1.63'
- DB '1.64'
- DB '1.65'
- DB '1.66'
- DB '1.67'
- DB '1.68'
- DB '1.69'
- DB '1.70'
- DB '1.71'
- DB '1.72'
- DB '1.73'
- DB '1.74'
- DB '1.75'
- DB '1.76'
- DB '1.77'
- DB '1.78'
- DB '1.79'
- DB '1.80'
- DB '1.81'
- DB '1.82'
- DB '1.83'
- DB '1.84'
- DB '1.85'
- DB '1.86'
- DB '1.87'
- DB '1.88'
- DB '1.89'
- DB '1.90'
- DB '1.91'
- DB '1.92'
- DB '1.93'
- DB '1.94'
- DB '1.95'
- DB '1.96'
- DB '1.97'
- DB '1.98'
- DB '1.99'
- DB '2.00'
- DB '2.01'
- DB '2.02'
- DB '2.03'
- DB '2.04'
- DB '2.05'
- DB '2.06'
- DB '2.07'
- DB '2.08'
- DB '2.09'
- DB '2.10'
- DB '2.11'
- DB '2.12'
- DB '2.13'
- DB '2.14'
- DB '2.15'
- DB '2.16'
- DB '2.17'
- DB '2.18'
- DB '2.19'
- DB '2.20'
- DB '2.21'
- DB '2.22'
- DB '2.23'
- DB '2.24'
- DB '2.25'
- DB '2.26'
- DB '2.27'
- DB '2.28'
- DB '2.29'
- DB '2.30'
- DB '2.31'
- DB '2.32'
- DB '2.33'
- DB '2.34'
- DB '2.35'
- DB '2.36'
- DB '2.37'
- DB '2.38'
- DB '2.39'
- DB '2.40'
- DB '2.41'
- DB '2.42'
- DB '2.43'
- DB '2.44'
- DB '2.45'
- DB '2.46'
- DB '2.47'
- DB '2.48'
- DB '2.49'
- DB '2.50'
- END START
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement