Вы находитесь на странице: 1из 33

Microprocessor Systems II

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.

Timer control (using keypad keys A, B, C, D) :


A: Update time mode (ON/OFF)
B: toggle time field (Hr10 -> Sec1)
C: increment selected time field
D: decrement selected time field
E: apply changes and return to normal operation
Keypad actions are monitored and take effect only at one second intervals
Main program remains in idle mode since tmr0 triggers all activity within ISR
Microprocessor Systems II
Project
Hardware : ADuC831 (on-chip temperature sensor/ADC/Timer)
Keypad, LCD unit

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

PC Software : C:\ADuC\9600com1.ht (preconfigured hyperterminal program)


ADuC831 Block Diagram

on-chip
temperature
sensor

Serial port (if


time allows)

Timer 0 [generate 1 sec interrupt, use to trigger 24 hr tmr


updates, temp sensor reads, LCD writes]
ADCs & DACs
Ref : www.allAboutCircuits.com/vol_4/chpt_13/
Analog-to-Digital Converter (ADC)
electronically translates analogue signal
into digital quantity

Digital-to-Analog Converter (DAC) translates


digital quantity into analogue signal

Often used together in digital


systems to provide complete
interface with analogue sensors
and o/p devices for control
systems
Microprocessor Systems II
Project Assignment
Suggested approach/tasks (groups of 4 maximum)
– High level program structure / LCD control
– 24 hour timer code (based on flashing LED lab) / Include timer set control
via keypad.
– Temperature sensor using ADC
– Transfer time, keypad input, temperature to PC monitor via serial port

Refer to programming guidelines document in course notes, e.g., structured


programming, flow charts, pseudo code, clear comments and label names etc

This project provides an opportunity to design & implement an embedded


system and serve as a good foundation for 3rd year and final year work.
Microprocessor Systems II
Project Assignment
Submission details :

Email zipped copy of project to fearghal.morgan@nuigalway.ie


Submit hardcopy of code (font 8) to EE departmental office
[Deadline Mon 5th April, 5pm]
Include team member names, main creator name for each code section
Include readme.txt indicating overall status and status of each sub-section

Mon 21st Feb : Assignment introduction


Mon 28th Feb : Lab3 completion and assessment (kpad lab) : No lecture.
All other mondays : lecture (9-11am)
Tues 8th & 15th Mar : lab (4-6pm, 1st and 2nd floor labs are available)
Mon 4th Apr : (2-6pm) Demo & Assessment of project in lab
Copies of Aspire software and 8051 hardware available from Technicians
High level program structure
Define symbols etc 13:43:27 T=000
CSEG • Aids high level understanding of program structure
ORG 0000H • Similar to flowchart description
JMP MAIN

tmr0 ISR :
call chkIfKPadTmrUpd ; Chk if key press instructs update of timer value, using LCD to view
; field selection

restart tmr0 ; restart timer (to measure next 50ms interval)


if ticks < 19 ; 1 sec interval has not yet passed
ticks = ticks + 1
else ; if ticks=20 => 1 sec interval has passed
ticks = 0 ; clr value before restarting 1 sec delay sequence
call updateTime ; update timer (using 1 second resolution)
call readTemperature ; read temperature sensor value using ADC
call displayOnLCDLine1 ; display time and temp sensor data on LCD
call txViaUART2PC ; transmit on serial port to PC terminal
RETI ; return from ISR

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

sym names used


hr10 hr1 : min10 min1 : sec10 sec1

Define 6 mem locations holding these values


timeStrtAdd is addr of sec1 value
timeStrtAdd+5 is addr of hr10 value
timStrtAdd
if sec1 < 9 then

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)

• 12-bit ADC resolution :


2.5V/4096 = 0.61mV
01h represents 0.61mV, 0FFFh represents 2.5V

• ADC configured via 3 register SFR interface (ADCCON1, ADCCON2, ADCCON3)

• Single step ADC conversion


Trigger ADC (every one second) & write value to defined memory location
defined tempAdd as address of temperature value

• Refer to sample .asm files in C:\ADuC\Code\831\ADC


ADCCON1 bit settings

• ADCCON1 (7) 1 : powerup ADC


(6) 0 : internal reference voltage
(5:4) 00 : divide ratio = 16 for master clock
If using temp sensor, ADC should be configured to use an
ADCCLK of MCLK/16 (and 4 acquisition clocks)
(3:2) 11 : ADC acquisition select bits
If using temp sensor, ADC should be configured to use an
4 acquisition clocks
(1) 0 : tmr2 o/flow not used to trigger ADC conversion
(0) 0 : p3.5 external ADC trigger input not used
ADCCON2 bit settings

• 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)

Also, refer to C:\ADuC\Code\831\ADC\ADCsingl.asm :


Performs repeated single ADC conversions and moves results to P0 & P2.
Sets the red LED on the eval board upon completion of each conversion.
A new conversion is initiated every 200ms
All rate calculations assume an 11.0592MHz Mclk

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)

if updFlg set then


if keyB pressed then ; select field for update
if tmrFieldIndex = 0 then
tmrFieldIndex=5 ; hr10 field is selected for update
else
decrement tmrFieldIndex ; select hr1(4), min10(3), min1(2), sec10(1), sec1(0)
end if

elsif keyC pressed then increment value in address R0+tmrFieldIndex


elsif keyD pressed then decrement value in address R0+tmrFieldIndex
elsif keyE pressed then clr updFlg
end if
end if
Timer control (using keypad keys A, B, C, D, E) :
A: Update time mode (ON/OFF)
B: toggle time field (Hr10 -> Sec1)
C: increment selected time field
D: decrement selected time field
E: apply changes and return to normal operation
Keypad actions are monitored and take effect only at second intervals
displayOnLCDLine1 routine
Display format : 13:43:27 T=000
Time and temperature
If updFlg asserted, position flashing cursor at appropriate field

Refer to LCD instruction set


ASCII Conversions & ASCII Table
To convert from BCD (time vlaues) to ASCII, add 30hex (48d)
Other examples : line feed #10 (decimal), Carriage return is ASCII 13 (decimal)
Serial Port References
http://www.ctips.com/rs232.html
http://computer.howstuffworks.com/serial-port.htm

Microconverter data sheet (ADuC831.pdf) UART Serial interface, pp 55-58

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

C:\ADuC\Code\831\UART\UARTIO.asm for standard UART I/O subroutines


SENDSTRING - sends a string of characters SENDCHAR - sends a single character
SENDVAL - sends a byte as 2 ASCII characters HEX2ASCII - converts from HEX to ASCII
ASCII2HEX - converts from ASCII to HEX GETCHAR - gets a single character;
GETVAL - gets a byte as 2 ASCII characters
Serial Port Operation
Serial ports provide standard connector & protocol to support attaching of devices,
such as modems, to an embedded system.
Serial port transmits byte of data one bit at a time
Adv : requires only one wire to transmit data (lower cable costs, smaller cables)
Disadv : takes minimum 8 times as long to transmit data
Full duplex : rx & tx processing at the same time
Serial communications method is known as asynchronous communication because
sending & receiving ends of the communication are not precisely synchronised
using a synchronising signal line (e.g., clk)
Serial port uses UART (Universal Asynchronous Receiver Transmitter) device
8031 UART PC UART
TxD

rx buffer RxD

8031 signal interface :


Transmit Start bit & LSB first RxD (P3.0), TxD (P3.1)
rx buffer enables buffering received
pkts while processing tx pkts
Serial port operation : synchronisation
Markers added to help track each data bit
Single ‘0’ start bit transmitted before each byte of data
Two systems don't require synchronising clock signal
Both systems must be set at the same port speed/baud rate, e.g., 9600 baud
Definition : speed of info being transmitted across serial interface (bits/sec (bps))
8-bit ASCII character plus start bit plus one stop bit (total 10 bits) at 9600 baud
would be transmitted in 10/9600 sec. = 1.042 ms or about 960 characters/sec.
When receive UART receives start bit, it starts a short term timer.
By keeping streams short, there's not enough time for the timer to get out of sync
Stop bit (optional parity bit and second stop bit) transmitted after each byte of data
8031 UART PC UART
TxD

rx buffer RxD

8031 signal interface :


Transmit Start bit & LSB first RxD (P3.0), TxD (P3.1)
Serial port operation : synchronisation
Example asynch serial data packet transfer using 8 bit word, even parity, 1 stop bit
Course assignment uses asynch serial data packet transfer using
8 bit word, no parity, 1 stop bit

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

8031 UART PC UART


TxD

rx buffer RxD

Transmit Start bit & LSB first


Serial Port Baud Rate using TMR3
Use 9600 baud rate for 11.0592MHz clk 8031 and preconfigured 9600 baud
hyperterminal program provided by C:\ADuC\9600com1.ht
TMR3 can be used for generating very accurate high speed baud rates & free up
other timers for other uses

T3CON & T3FD register settings :


T3CON(7) = 1 enables baud rate generation using timer 3
T3CON(6:3) are don’t care
T3CON(2:0) = 101
and T3FD (fractional divider ratio to generate required baud rate) = 08h

Table XXVII extract


Other Serial Port Baud Rate options
TMR1 is suitable for providing 9600 baud rate in the assignment application
Baud rate calculation = core clock rate / (32 x 12 x (256-TH1))
= 1105900 / (32 x 12 x 3) = 9600

Other baud rate generation options


If SMOD (PCON(7)) = 1, baud rate is doubled.
A wider range of baud rates is possible using timer 2, compared to timer 1.
Serial port transmit only : SFR settings
SCON (98h), bit addressable. Program Value = 42h
(7:6) 01 => 8-bit UART mode, variable baud rate
(5) 0 => byte received
(4) 0 => enable serial port reception
(3:2) 00
(1) 1 => TI flag, default ‘1’, Serial port TX interrupt flag. Set by hardware
when previous byte transmission complete
Must be cleared by s/w before performing new transmit
(0) 0 => Serial port RX interrupt flag, set on completion of byte receipt
Must be cleared by s/w

SBUF (SFR address 99h)


write TxD data : write to SBUF initiates new tx (this loads ‘1’ stop bit into
transmit shift reg bit 9)
Data is o/p bit-by-bit until stop bit appears on TxD and TI is automatically set
Serial port (Rx & Tx) : SFR settings
SCON (98h), bit addressable. Program Value = 52h
(7:6) 01 => 8-bit UART mode, variable baud rate
(5) 0 => RIflag assertion indicates byte received (note error in ADuC831.pdf
table XXIII, SM2 description
(4) 1 => enable serial port reception
(3:2) 00
(1) 1 => TI flag, default ‘1’, Serial port TX interrupt flag. Set by hardware
when previous byte transmission complete
Must be cleared by s/w before performing new transmit
(0) 0 => Serial port RX interrupt flag, set on completion of byte receipt
Must be cleared by s/w

SBUF (SFR address 99h)


write TxD data : serial transmission occurs automatically
read SBUF : reads receive register contents
Serial port receive operation
For Mode 1 operation (SCON(7:6)=01) :

Receive operation initiated when 1->0 transition detected on RxD.


If start bit valid, 8 following characters are registered into serial port shift reg
(SBUF)

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.

8031 UART PC UART


TxD

rx buffer RxD

Вам также может понравиться