Академический Документы
Профессиональный Документы
Культура Документы
Project
Functionality : Every second, display time & temperature on LCD line 1 (& on PC
terminal, via serial port, if time permits). Include timer set control
via keypad.
LCD line 1
13:43:27 T=000 On-chip temp sensor value
24-hr clock display
Read On-chip temperature sensor every second using built-in ADC (Analog to
Digital Converter). Device pin not required since temp sensor is on chip.
Software : Aspire
Support documentation :
Microconverter data sheet (ADuC831.pdf)
ADC circuit information pp 18-24 (includes reference to temperature sensor)
UART Serial interface, pp 55-58
on-chip
temperature
sensor
tmr0 ISR :
call chkIfKPadTmrUpd ; Chk if key press instructs update of timer value, using LCD to view
; field selection
MAIN:
; Initialise LCD control sigs, ADC, TMR0 (to provide 50ms interval), Serial port (for transmit to PC)
sjmp $ ; loop forever
end
updateTime routine
Example time format (13hr:43min:27sec):
1 3 : 4 3 : 2 7
else
increment sec1 updateTime routine
sec1=0
if sec10 < 5 then
else
increment sec10 pseudo code # 1
sec10=0
if min1 < 9 then
increment min1
else
min1=0
Difficult to perform
if min10 < 5 then
increment min10
‘<‘ equality check using
else assembly code
min10=0
if hr10 < 2 then ; hr10 = 0 or 1, allow hr1 values 0 -> 9
if hr1 < 9 then
increment hr1
else
hr1=0
increment hr10
end if
else ; hr10 = 2, allow only hr1 values 0, 1, 2, 3
if hr1 < 3 then
increment hr1
else ; time is 00:00:00
hr1=0
hr10=0
end if
end if
end if
end if
end if
end if
if sec1 = 9 then
sec1=0
updateTime routine
pseudo code # 2
if sec10 = 5 then
sec10=0
if min1 = 9 then
min1=0
if min10 = 5 then
min10=0
Better suited to 8051 instruction set
if hr10 = 2 then ; if hr10 = 2, allow only hr1 values 0, 1, 2, 3
if hr1 = 3 then ; time => 00:00:00
hr1= 0
hr10=0
else ; label hr1_LT3
increment hr1
end if
else ; label hr10_LT2 (hr10 = 0 or 1, allow hr1 values 0 -> 9)
if hr1 = 9 then
hr1=0
increment hr10
else ; label hr1_LT9 Can perform equality checks using
increment hr1
end if CJNE A, #data, rel
end if
else ; label min10_LT5
increment min10
end if
else ; label min1_LT9
INC source :
increment min1
end if
increment value at address source
else ; label sec10_LT5
increment sec10
end if
else ; label sec1_LT9
increment sec1
end if
Pseudo code #2 Assembly code
if sec1 = 9 then MOV A, sec1 CJNE A, #9, sec1_LT9
sec1=0 CLR sec1
if sec10 = 5 then MOV A, sec10 CJNE A, #5, sec1_LT5
sec10=0 CLR sec10
if min1 = 9 then MOV A, min1 CJNE A, #9, min1_LT9
min1=0 CLR min1
if min10 = 5 then MOV A, min10 CJNE A, #5, min10_LT5
min10=0 CLR min10
if hr10 = 2 then ; if hr10 = 2, allow only hr1 values 0, 1, 2, 3 MOV A, hr10 CJNE A, #2, hr10_LT2
if hr1 = 3 then ; time => 00:00:00 MOV A, hr1 CJNE A, #3, hr1_LT3
hr1= 0 CLR hr1
hr10=0 CLR hr10
else hr1_LT3:
increment hr1 INC hr1
end if
else ; (hr10 = 0 or 1, allow hr1 values 0 -> 9) hr10_LT2:
if hr1 = 9 then MOV A, hr1 CJNE A, #9, hr1_LT9
hr1=0 CLR hr1
increment hr10 INC hr10
else hr1_LT9:
increment hr1 INC hr1
end if
end if
else min10_LT5:
increment min10 INC min10
end if
else min1_LT9:
increment min1 INC min1
end if
else sec10_LT5:
increment sec10 INC sec10
end if
else sec1_LT9:
increment sec1 INC sec1
end if
Successive Approximation ADC operation
• SAR inputs bit pattern to DAC to generate an analogue voltage to compare with analogue
input signal.
• SAR monitors comparator’s o/p, checking if analogue i/p is greater or less that Vin
Adjusts DAC input bit values accordingly
• SAR adjusts DAC input bit pattern to find DAC ouput which is closest to Vin
• First, SAR asserts DAC input bits in turn (8 in this illustration), starting with MSB to find
required MSB asserted bit
• SAR counting strategy results in a fast solution; DAC binary output quickly converges on
the analogue signal input
Successive Approx
Register (SAR), [counter] clk
strtConv
12-bit digital
output signal
(parallel form),
ADCDATAH(3:0)
Analogue input ADCDATAL(7:0)
signal (only 8 bits
comparator
(range 0 -> Vref) illustrated
en here)
endConv clk
ADuC831 ADC Operation (pp 18-24 of spec)
• ADuC831 incorporates fast 8-channel 12-bit single supply ADC
• Conventional successive approximation converter based around capacitor DAC
• Reliable, accurate and fast
• Accepts analogue i/p voltage range 0 -> Vref
• If input changes during conversion, error is no greater than the change during conversion
• Multiple steps are required to convert input signal
• I/P signals :
clk
Vin
strtConv : start of conversion
• O/P signals :
endConv (end of conversion )
12-bit digital parallel o/p
ADCDATH(3:0), ADCDATAL(7:0)
ADC Operation
• ADC input : on-chip temperature sensor : voltage proportional to absolute
temperature
• Use on-chip reference voltage [Vref = 2.5V] (defines max sampled input voltage)
• ADCCON2 (7) - : ADC interrupt bit, set by h/w at end of ADC conversion cyc
Not using ADC interrupts in this course. Defaults to disabled
(6) 0 : DMA mode enable bit
(5) 0 : Continuous conversion bit
(4) 1 : Single conversion bit, set to initiate a single conversion cyc
Automatically reset to 0 on completion of single conv cyc
Assert (bit addressable) to start ADC conversion
(3:0) 1000 : Channel selection bits, 1000 => temperature monitor
ADCCON3 bit settings
• ADCCON3 (7) - : ADC busy status bit (read only)
Suggest poll of ADCCON3(7) to detect conversion complete
(6) 0 : gain calibration disable
(5:4) 00 : number of averages selection bits
(3:0) 0100 : ADC calibration bits (see data sheet)
Total ADC conversion time is 15 ADC clks plus 1 ADC clock for synchronisation,
plus the selected ADC acquisition time (4 ADC clocks when using the temp sensor)
ADC Functionality not used in this course
• Continuous ADC conversion, external trigger conversion etc
• Continuous ADC conversion & capture samples to external RAM space (without
interaction of MCU core)
• Offset and gain calibration
• ADC DMA Mode
readTemperature routine
Refer to ADC section in ADuC831 data sheet (pp 18-24)
Some changes are required since accessing the temperature sensor ADC channel
chkIfKPadTmrUpd routine
Store timeStrtAdd in R0 ; store pointer to start mem location of 24 hr time values, will use later
If keypadPressed then
if keyA pressed then set updFlg (bit). Default setting is clear (0)
Use 9600 baud rate for 11.0592MHz clk 8031 and preconfigured 9600 baud hyperterminal
program provided by C:\ADuC\9600com1.ht
C:\ADuC\Code\831\UART\UART1.asm
Description : saves 16 numbers in order initially, starting with 0, into memory locations 40h to 50h.
When finished, the values in these locations are transmitted down the UART in ASCII form to the PC
where they can be viewed using the preconfigured hyperterminal program (c:\ADuC_Beta832\9600com1.ht).
After the transmission of the 16 bytes, a 5 second delay is called and the process is repeated
rx buffer RxD
rx buffer RxD
8051 UART samples 16 times / bit (timer overflows 16 times before bit is
transmitted or received)
Central sample
points
(mid point of 16
samples per bit)
Additional Serial port signals
Transmit Data (TxD) – serial transmit data
Used in formal assignment
Receive Data (RxD) – serial receive data
Serial port flow control is provided by the following signals (not required in
assignment application)
Carrier Detect (CD) determines if modem connected to working phone line
Data Terminal Ready (DTR) embedded system available for communication
Data Set Ready (DSR) destination device available for communication
Request To Send (RTS) embedded system requests authorisation to send data
Clear To Send (CTS) destination device acknowledges embedded system that data
can be sent
Ring Indicator (RI) when call has been placed (to modem), embedded system
acknowledges signal (sent from modem) that a ring is detected
Serial port operation : synchronisation
Baud rate set by TMR1, TMR2 or TMR3 overflow rate
Can have define separate tx & rx baud rates
Baud rates up to 460kbps supported by some UARTS
rx buffer RxD
If SCON(7:6) = 01, Receive Interrupt (RI) = 0 and stop bit received, then :
data is placed in SBUF & RI is asserted
Otherwise frame is lost & RI is not asserted.
rx buffer RxD