logboek practicum electronica iiwillem.engen.nl/uni/elec/eleciireport.pdf3 opdracht 2 7 3.2 program...
TRANSCRIPT
Logboek
practicum Electronica II
door Willem van Engen9 Jan 2001 - 12 Jan 2001
CONTENTS 2
Contents
1 Voorwoord 3
2 Opdracht 1 42.1 Flowchart . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42.2 Program . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
3 Opdracht 2 63.1 Flowchart . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63.2 Program . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
4 Opdracht 3 84.1 Flowchart . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 84.2 Program . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
5 Opdracht 4 105.1 Flowchart . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 105.2 Program . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
6 Opdracht 5 146.1 Flowchart . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 146.2 Program . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
7 Opdracht 6 167.1 Flowchart . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 167.2 Program . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
8 Opdracht 7 188.1 Flowchart . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 188.2 Program . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
9 Opdracht 8 209.1 Flowchart . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 209.2 Program . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
10 Opdracht 9 2310.1 Flowchart . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2310.2 Program . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
11 Opdracht 10 2611.1 Flowchart . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2611.2 Program . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27
See also the website at http://www.stack.nl/˜wvengen/elec/
Logboek practicum electronica II Willem van Engen
1 Voorwoord 3
1 Voorwoord
In dit logboek is voor iedere opdracht opgenomen:
• Een of meerdere flowcharts
• Het betreffende programma(deel)
Alleen de relevante flowcharts zijn weergegeven. Als het hoofdprogramma uit een sim-pele lus bestaat en de vraag gericht is op andere dingen, is het hoofdprogramma nietopgenomen bij de flowcharts; wel bij de programmacode. Subroutines die reeds in eerdereopdrachten zijn voorgekomen zijn noch bij de flowcharts, noch in de programmacodeopgenomen, tenzij er iets veranderd is. De meeste programma’s wachten aan het eindeop een toetsdruk en beginnen weer opnieuw. Dit is niet in de flowcharts weergegeven,evenals een eventueel bericht dat aan het begin van het programma op het scherm gezetwordt. De flowchart geeft aan wat het programma of de subroutine doet, en laat geenprecieze details zien.De opmerkingen en motivaties zijn over het algemeen te vinden in de commentaren vande programmacode.
Logboek practicum electronica II Willem van Engen
2 Opdracht 1 4
2 Opdracht 1
1. Schrijf een programma dat een toets inleest van het keyboard en de waarde van detoets op de eerste positie van het display plaatst.
2. Beeld de waarde van de toets af in binary code op het led array
3. Pas het programma zo aan dat het alleen reageert op de toetsen 0 ... 9
2.1 Flowchart
∨∨
Read key
∨∨
nokey > 9 ?
yes∨∨
Display hex on display
∨∨
Display on led array
∨∨<<
Logboek practicum electronica II Willem van Engen
2 Opdracht 1 5
2.2 Program
start1:
lcall BLANK_DISPLAY
myloop:
lcall GETKEY ; Wait for keypress
mov a, KEY
clr c
subb a, #10 ; Check if key is 0..9
jnc nodisplay ; No? Then don’t display
lcall BLANK_DISPLAY
mov a, KEY
mov LEDS, a ; otherwise display on leds
lcall DISPLAY_HEX ; and show on display
lcall SET_LEDS
nodisplay:
ljmp myloop ; and start over again
Logboek practicum electronica II Willem van Engen
3 Opdracht 2 6
3 Opdracht 2
1. Schrijf een programma dat twee toetsen inleest (0..9) en de waarde op de eerste tweeposities van het display schrijf (gebruik GETKEY).
2. Maak van deze twee cijfers een hexadecimaal getal en zit dit op het display.
3. Schrijf dit getal naar het externe geheugen (gebruik hierbij DPTR).
4. Lees dit getal terug en beeld het decimaal af op cursorpositie 3 van het display.
3.1 Flowchart
∨∨
Read key1
∨∨
Read key2
∨∨
Combine key1 and key2 toobtain value
∨∨
Display hex value
∨∨
Write value to mem
∨∨
Read from mem
∨∨
Display dec
∨∨
Logboek practicum electronica II Willem van Engen
3 Opdracht 2 7
3.2 Program
RSEG IDATA
mynum: ds 1
RSEG MAIN
start2:
myloop:
lcall GETKEY ; Get two keys:
mov A, KEY
swap A ; first in high nibble
mov R1, A
lcall GETKEY
lcall BLANK_DISPLAY
mov A, KEY
add A, R1 ; 2nd in low nibble
lcall BCDBIN ; convert from bcd
lcall DISPLAY_HEX ; show number
mov DPTR, #mynum ; address of our variable
movx @DPTR, A ; put number
movx A, @DPTR ; and get it again
lcall DISPLAY_DEC ; show on screen decimally
ljmp myloop
Logboek practicum electronica II Willem van Engen
4 Opdracht 3 8
4 Opdracht 3
Schrijf een jump tabel. Hiermee kan je door middel van een toetsaanslag (0...f) de ver-volgopdrachten aanroepen. Zorg ervoor dat na de toetsaanslag het display gewist wordt.
4.1 Flowchart
∨∨
Wait for key
∨∨
Clear screen
∨∨
nokey is 0...a?
yes∨∨
jmpaddr =keyno × 4 + baseaddr
∨∨
jump to jumpaddr
<<
Logboek practicum electronica II Willem van Engen
4 Opdracht 3 9
4.2 Program
myloop:
lcall BLANK_DISPLAY
mov DPTR, #CHOOSE_TXT
lcall DISPLAY_TXT ; Show message
lcall GETKEY ; And wait for keypress
lcall BLANK_DISPLAY ; Clear display
mov A, KEY
clr C ; because when jump, no carryclr
cjne A,#11, $+3 ; cmp A, #12
jnc myloop ; only valid choices (0..A)
mov DPTR, #jmptable
clr C ; each jmp instruction
rlc A ; is 4 bytes, so divide by 4
clr C
rlc A
jmp @A+DPTR
jmptable: ljmp jmptable ; nothing for opdr0, loop 4ever
db 0
ljmp start1
db 0
ljmp start2
db 0
ljmp start3
db 0
ljmp start4
db 0
ljmp start5
db 0
ljmp start6
db 0
ljmp start7
db 0
ljmp start8
db 0
ljmp start9
db 0
ljmp start10
start3:
mov DPTR, #TEXT_OPDR3
lcall DISPLAY_TXT
noendloop: ljmp noendloop
CHOOSE_TXT: db ’MAKE YOUR CHOICE’
db ’ 0 ... A’,0h
TEXT_OPDR3: db ’THIS MENUSYSTEM ’
db ’ IS OPDRACHT3’,0h
Logboek practicum electronica II Willem van Engen
5 Opdracht 4 10
5 Opdracht 4
1. Schrijf een subroutine die de inhoud van de registers A, B, R0..R7, DPTR, SP enPSW op het display weergeeft.
(a) Een subroutine mag de waarden van de registers niet veranderen
(b) Display de waarde die SP heeft voor de subroutine aanroep
(c) Controleer de waarde van SP in LINK.LST
2. Laat in een programma zien dat de subroutine werkt
5.1 Flowchart
∨∨
Save used registers
∨∨
Clear screen
∨∨
Show A, B, PSW, DPH, DPL
∨∨
Show SP-#usedstackbytes
∨∨
Wait for key & clear screen
∨∨
Display R0..R7
∨∨
Wait for key & clear screen
∨∨
Restore registers
∨∨
Logboek practicum electronica II Willem van Engen
5 Opdracht 4 11
5.2 Program
start4:
myloop:
lcall BLANK_DISPLAY ; Allright, a simple program
lcall GETKEY ; which reads in a key
mov A, KEY ; and puts it’s value in A
lcall DISPLAY_REG ; and, of course, shows the regs
ljmp myloop ; Yes, again!
DISPLAY_REG:
; Save regs
push PSW
push ACC
push DPL
push DPH
push PSW ; Save it before modification
; Clear screen
lcall BLANK_DISPLAY
mov DPTR, #txtA ; First reg A
lcall DISPLAY_TXT
lcall DISPLAY_HEX
mov DPTR, #txtB ; Register B
lcall DISPLAY_TXT
mov A, B
lcall DISPLAY_HEX
pop ACC ; Program Status Word
mov DPTR, #txtPSW
lcall DISPLAY_TXT
lcall DISPLAY_HEX
mov DPTR, #txtDPTR ; DPTR, consists of
lcall DISPLAY_TXT
pop ACC ; DPH
lcall DISPLAY_HEX
mov DPH, A
pop ACC ; and DPL
lcall DISPLAY_HEX
mov DPL, A
push DPL ; We don’t want to lose them!
push DPH
mov DPTR, #txtSP ; Stack Pointer
lcall DISPLAY_TXT
mov A, SP
clr C
subb A, #6 ; substract 6, because of pushes
lcall DISPLAY_HEX ; and the call itself
lcall GETKEY ; Display is full, so wait4key
lcall BLANK_DISPLAY ; and clearscreen
mov DPTR, #txtR ; R registers
Logboek practicum electronica II Willem van Engen
5 Opdracht 4 12
lcall DISPLAY_TXT
mov A, R0 ; R0
lcall DISPLAY_HEX
mov A, #020h ; space
lcall DISPLAY_ASC
mov A, R1 ; R1
lcall DISPLAY_HEX
mov A, #020h
lcall DISPLAY_ASC
mov A, R2 ; R2
lcall DISPLAY_HEX
mov A, #020h
lcall DISPLAY_ASC
mov A, R3 ; R3
lcall DISPLAY_HEX
mov DPTR, #txtR_2 ; Next line
lcall DISPLAY_TXT
mov A, R4 ; R4
lcall DISPLAY_HEX
mov A, #020h
lcall DISPLAY_ASC
mov A, R5 ; R5
lcall DISPLAY_HEX
mov A, #020h
lcall DISPLAY_ASC
mov A, R6 ; R6
lcall DISPLAY_HEX
mov A, #020h
lcall DISPLAY_ASC
mov A, R7 ; R7
lcall DISPLAY_HEX
mov A, #020h
lcall DISPLAY_ASC
lcall GETKEY ; and let the user watch it
lcall BLANK_DISPLAY ; before the prog continues
; Restore everything
pop DPH
pop DPL
pop ACC
pop PSW
ret
txtA: db ’ A=’,00h
txtB: db ’ B=’,00h
txtDPTR: db ’DPTR=’,00h
txtSP: db ’ SP=’,00h
Logboek practicum electronica II Willem van Engen
5 Opdracht 4 13
txtR: db ’R: ’,00h
txtR_2: db ’ ’,00h
txtPSW: db ’PSW=’,00h
Logboek practicum electronica II Willem van Engen
6 Opdracht 5 14
6 Opdracht 5
• Zet de inhoud van de EPROM van de adressen 2ch t/m 4bh vanaf positie nul ophet scherm.
• Controleer deze code d.m.v. het uitlezen van de file main.lst
6.1 Flowchart
∨∨
datapointer = startaddress
∨∨
get byte @datapointer
∨∨
print byte hex
∨∨
noScreen full?
yes∨∨
Wait for key & clear screen
∨∨
set datapointer to next byte
∨∨
no Is thisthe last byte?
yes∨∨
>>
<<
Logboek practicum electronica II Willem van Engen
6 Opdracht 5 15
6.2 Program
startoffset EQU 02ch ; Read from here
endaddress EQU 04bh +1 ; until here
middleaddr EQU startoffset+0fh ; Wait in between for keypress here
start5:
myloop:
lcall BLANK_DISPLAY ; Show greeting and wait4key
mov DPTR, #BEGIN_TXT
lcall DISPLAY_TXT
lcall GETKEY
lcall BLANK_DISPLAY
mov R0, #startoffset; starting variables
mov DPTR, #0
displayloop:
mov A, R0
movc A, @A+DPTR ; There isn’t have much operand choice
lcall DISPLAY_HEX ; show value
cjne R0,#middleaddr,nowait; should we wait?
lcall GETKEY ; then wait4keypress
nowait:
inc R0 ; next byte
cjne R0,#endaddress,displayloop
; and loop until we’ve reached the end
lcall GETKEY
ljmp myloop
BEGIN_TXT db ’ PRESS THE ’
db ’ ANY KEY’,00h
Logboek practicum electronica II Willem van Engen
7 Opdracht 6 16
7 Opdracht 6
1. Maak een programma dat een led laat branden. Laat deze led op het led-displayvan onder naar boven roteren (looplampje), met een vertraging van 0.5s.
2. Beeld het bitpatroon van de led’s in binaire code af op het display (msb...lsb).
Het programma moet beendigd worden als er op een toets gedrukt wordt.
7.1 Flowchart
Main program Subroutine DISPLAY BIN
∨∨
Initialize num
∨∨
Rotate num
∨∨
Set num on leds
∨∨
Display bin num
∨∨
Wait 500ms
∨∨
Get key status
∨∨
no Keypressed?
yes∨∨
>>
∨∨
counter=8
∨∨
yescurrentbit zero?
no∨∨
"1"
∨∨
Display digit
∨∨
Decrease counter
∨∨
no counterzero?
yes∨∨
>>
∨∨
"0"
<<
Logboek practicum electronica II Willem van Engen
7 Opdracht 6 17
7.2 Program
; BUGS:
; * No keycheck while waiting, so user could press key and release it
; within 0.5s and it would not be noticed by the program.
start6:
myloop:
lcall BLANK_DISPLAY ; Greeting
mov DPTR, #BEGIN_TXT
lcall DISPLAY_TXT
lcall GETKEY
mov A, #80h ; This is the value for the
; upper led, but we rotate
; first, so we begin down.
ledloop:
lcall BLANK_DISPLAY
rl A ; rotate bit
mov LEDS, A
lcall SET_LEDS ; set leds
lcall DISPLAY_BIN ; and show on display
lcall DELAY ; 500ms delay (=125ms*4)
lcall DELAY
lcall DELAY
lcall DELAY
lcall KBDPRESSED ; check if key is pressed
jnb KBDHIT, ledloop ; and rotate if no key pressed
ljmp ledloop ; Restart whole program
; Puts register A binary on display
DISPLAY_BIN:
push ACC
push B
mov B, R0 ; Save R0 too
push B
mov R0, #8 ; R0: counter (8 bits to display)
DB_binloop:
clr B ; B is 0 for now
rlc A ; rotate bit into carry
jnc DB_iszero ; Skip next cmd if bit == 0
inc B ; B = 1
DB_iszero:
push ACC ; we need A here
mov A, B
lcall DISPLAY_ASC ; show digit
pop ACC
djnz R0,DB_binloop ; and do it 8 times
pop B
mov R0, B
pop B
pop ACC
ret
BEGIN_TXT db ’HIT TO START’,0h
Logboek practicum electronica II Willem van Engen
8 Opdracht 7 18
8 Opdracht 7
1. Schrijf een subroutine die de inhoud van de variabelen UUR, MIN en SEC als een klokweergeeft op het display (<UUR>:<MIN>:<SEC>).
2. Maak een subroutine die de tijdvariabelen met een seconde ophoogt.
3. Maak hiermee een hoofdprogramma die de lopende tijd op het display zet. Test ditprogramma door de wachtlus voldoende klein te maken.
8.1 Flowchart
Subroutine INC TIME Subroutine SHOW TIME
∨∨
Increment SEC
∨∨
noSEC== 60?
yes∨∨
SEC= 0
∨∨
Increment MIN
∨∨
noMIN== 60?
yes∨∨
MIN= 0
∨∨
Increment UUR
∨∨<<<<
∨∨
Display UUR
∨∨
Display ”:”
∨∨
Display MIN
∨∨
Display ”:”
∨∨
Display SEC
∨∨
Logboek practicum electronica II Willem van Engen
8 Opdracht 7 19
8.2 Program
start7:
myloop:
lcall BLANK_DISPLAY
lcall SHOW_TIME
lcall INC_TIME
lcall DELAY
ljmp myloop
INC_TIME:
push ACC
inc SEC ; increase seconds
mov A, SEC
cjne A,#60,ITret ; sec <60? Then we’re done
clr A ; secs=0
mov SEC, A
inc MIN ; and inc minutes
mov A, MIN
cjne A, #60,ITret ; min <60? Then we’re done
clr A ; mins=0
mov MIN, A
inc UUR ; and inc hours
ITret:
pop ACC
ret
SHOW_TIME:
push ACC
mov A, UUR ; Display hour
lcall DISPLAY_DEC
mov A, #03ah ; ’:’
lcall DISPLAY_ASC
mov A, MIN ; minutes
lcall DISPLAY_DEC
mov A, #03ah ; ’:’
lcall DISPLAY_ASC
mov A, SEC ; seconds
lcall DISPLAY_DEC
mov A, SEC ; seconds
lcall DISPLAY_DEC
pop ACC
ret
Logboek practicum electronica II Willem van Engen
9 Opdracht 8 20
9 Opdracht 8
1. Initialiseer de interne timer (TIMER0) van de 80552, zodat deze iedere 50ms eeninterrupt genereert.
2. Zet in de ISR de flag F0
3. Test de routine door een hoofdprogramma te schrijven die de flag F0 uitleest. Schrijfop het led-array een variabele die elke 50ms met een verhoogd wordt.
4. Pas het hoofdprogramma zo aan dat het klokprogramma uit opdracht 7 uitgevoerdwordt (zonder gebruik te maken van een software vertraging).
9.1 FlowchartMain program
∨∨
INIT TIMER0
∨∨
INC TIME
∨∨
Incrementled value
∨∨
Updateled array
∨∨
SHOW TIME
∨∨
noFlagF0 set?
yes∨∨
Clear F0
>>
<<
Subroutine INIT TIMER0
∨∨
Set timer-mode
∨∨
Loadtimervalue
∨∨
Enabletimer &
interrupts
∨∨
Subroutine ISR TIMER0
∨∨
Stop timer& in-
terrupts
∨∨
Set bit F0
∨∨
Reloadtimer value
∨∨
Enabletimer &
interrupts
∨∨
Logboek practicum electronica II Willem van Engen
9 Opdracht 8 21
9.2 Program
; ...
; (at address 00bh, timer0 interrupt entry point)
ljmp ISR_TIMER0
; ...
TMODVAL EQU 1 ; Timer mode
TIMERVAL_HIGH EQU 100h-0b4h ; Counting up till 0ffffh
TIMEVAL_LOW EQU 100h-0h
RSEG IDATA
milli50sec ds 1
RSEG MAIN
start8:
mov LEDS, #0
lcall INIT_TIMER0
lcall BLANK_DISPLAY
myloop:
lcall INC_TIME
inc LEDS
lcall SET_LEDS
mov CURSOR, 0 ; instead of BLANK_DISPLAY to reduce
; flicker
lcall SHOW_TIME
waitloop: jbc F0, myloop ; wait for timer to reach 50ms
ljmp waitloop
INIT_TIMER0:
mov TMOD, #TMODVAL ; timer mode and timer value
mov TL0, #TIMERVAL_LOW
mov TH0, #TIMERVAL_HIGH
setb ET0 ; enable timer0 interrupts
setb EA ; enable interrupts
setb TR0 ; start timer
ret
ISR_TIMER0:
clr EA ; we want no interrupts during ISR
clr TR0 ; stop timer
setb F0 ; message to main program
mov TL0, timerlow ; reset timer value
mov TH0, timerhigh
setb TR0 ; start timer again
setb EA ; enable interrupts again
reti
INC_TIME: ; We update every 50ms, so we need a
; slightly different INC_TIME sub.
push ACC
inc milli50sec
mov A, milli50sec
Logboek practicum electronica II Willem van Engen
9 Opdracht 8 22
cjne A, #20,ITret
clr A
mov milli50sec, A
inc SEC
mov A, SEC
cjne A,#60,ITret
clr A
mov SEC, A
inc MIN
mov A, MIN
cjne A, #60,ITret
clr A
mov MIN, A
inc UUR
ITret:
pop ACC
ret
Logboek practicum electronica II Willem van Engen
10 Opdracht 9 23
10 Opdracht 9
De 10 bits A/D convertor van de 80552.
1. Sluit een potentiometer aan op de klemmen van een adc kanaal.
2. Schrijf een subroutine voor de analoog-digitaal conversie. Lees de waarde van deadc uit en zet deze op het display.
3. Druk de waarde van de gemeten spanning uit in mV, schrijf hiervoor een subroutine.
10.1 FlowchartSubroutine GET ADC
∨∨
Start conversion
∨∨
noConversiondone?
yes∨∨
valuelow =ADCH << 2 +ADCON >> 6
∨∨
valuehigh =ADCH >> 6
∨∨
Make adc readyfor next conversion
∨∨
<<
Subroutine DISPLAY MV
∨∨
×5000
∨∨
: 1023
∨∨
Displayon screen
∨∨
Logboek practicum electronica II Willem van Engen
10 Opdracht 9 24
10.2 Program
ADC_channel EQU 0
start9:
mov ADCON, ADC_channel
lcall BLANK_DISPLAY
mov R0, #X0
myloop:
mov CURSOR, 0
lcall GET_ADC
lcall DISPLAY_INTHEX ; Display raw value
mov CURSOR,#10h
lcall DISPLAY_MV
ljmp myloop
GET_ADC:
push ACC
push B
orl ADCON, #8 ; ADCS=1: start conversion
waitconversion:
mov A, ADCON
anl A, #16
jz waitconversion ; wait until conversion finished
mov A, ADCON ; 2 lowest bits
rl A
rl A
anl A, #3
mov B, A
mov A, ADCH ; add 6 bits shifted
rl A
rl A
push ACC
anl A, #0fch
add A, B ; allright, we have the lowest byte
mov B, A
pop ACC ; for 2 highest bits (alrdy shifted)
anl A, #3 ; only 2 bits
mov X0+1, A
mov X0, B ; lowest byte
anl ADCON, #0e7h ; next time, we can restart conversion
pop B
pop ACC
ret
DISPLAY_MV:
push B
mov B, R0
mov R1, #X1
mov R2, #X2
mov R3, #X3
mov X1, #088h ; Multiply by 5000
mov X1+1, #13h
Logboek practicum electronica II Willem van Engen
10 Opdracht 9 25
mov X2, #0ffh ; Divide by 1023
mov X2+1, #03h
mov R4, #X4
lcall MUL_DIV_R0R1R2R3R4
mov R0, #X3
lcall DISPLAY_INTDEC ; Display result decimal
mov R0, B
pop B
ret
Logboek practicum electronica II Willem van Engen
11 Opdracht 10 26
11 Opdracht 10
Om de waarde van een condensator te meten kun je gebruik maken van een RC-netwerk.Voor de overdracht geldt:
Vuit = Vref (1− e− tRC )
1. Sluit het RC-netwerk aan.
2. Om de waarde van de condensator te meten, moet begonnen worden met het ont-laden van de condensator door een wachttijd in te bouwen. Er geldt dan Vuit = 0.Vervolgens zet je een logische "1" op de ingang, zodat de condensator zich oplaadt.Als nu t = RC, dan is Vuit = 0.63 · Vref .
3. Schrijf een programma dat de waarde van de condensator bepaaldt. Gegeven is eenweerstand van 10 kΩ.
11.1 FlowchartSubroutine MEASURE RC
∨∨
Setup counter &select adc channel
∨∨
Discharge capacitor
∨∨
Start counter
∨∨
Get adc value
∨∨
noVadc >0.63 · Vref?
yes∨∨
Stop counter &get elapsed ticks
∨∨
<<
Subroutine CONVERT2NF
∨∨
×1085
∨∨
: 10000
∨∨
Displayon screen
∨∨
Logboek practicum electronica II Willem van Engen
11 Opdracht 10 27
11.2 Program
DC_channel EQU 1
TTL_channel EQU 0
;Vcheck EQU 645 ; 0.63*Vcc, where Vcc=03ffh
Vcheck_high EQU 02h
Vcheck_low EQU 085h
tmodval EQU 1h ; T/C mode 1: 16-bits timer/counter
start10:
lcall BLANK_DISPLAY
myloop:
lcall MEASURE_RC
mov R0, #X0
mov CURSOR, 0
lcall SET_CURSOR
lcall CONVERT2NF
mov DPTR, #AFTER_MSG
lcall DISPLAY_TXT
ljmp myloop
MEASURE_RC:
; First setup stuff
mov TMOD, #tmodval
mov TL0, #0 ; Clear counter
mov TH0, #0
orl ADCON, #ADC_channel ; Select right ADC channel
; Uncharge C if charged
clr P4.0
lcall DELAY
MEASURE_RC:
; First setup stuff
mov TMOD, #tmodval
mov TL0, #0 ; Clear counter
mov TH0, #0
orl ADCON, #ADC_channel ; Select right ADC channel
; Uncharge C if charged
clr P4.0
lcall DELAY
clr ET0
clr EA ; no interrupts, please
setb TR0 ; Start timer
setb P4.0
; Loop until Vout >= Vcheck
V_waitloop:
lcall GET_ADC ; Get ADC value
cjne R1,#Vcheck_high,checkhigh; check Vhigh
; now Vhigh=Vcheck_high
cjne R0,#Vcheck_low+1,$+3 ; cmp R0, #Vcheck_low
Logboek practicum electronica II Willem van Engen
11 Opdracht 10 28
jc V_waitloop ; if voltage not reached, wait
Vreachedit:
; Allright, Vout has reached it
clr TR0 ; Stop timer
clr P4.0 ; to gnd again
setb EA ; allow interrupts again
; Timer overflow checking not needed, because overflow
; will not occur for C < 10 muF.
; One could check for 1 overflow and add
; 65536 to the time, but that would only be once
; and for more overflows, a seperate ISR should be
; written.
mov X0, TL0 ; Put counter value into regs
mov X0+1, TH0
ret
checkhigh: jc V_waitloop
ljmp Vreachedit
CONVERT2NF:
; Because the timer has a fixed frequency of 921.6kHz, the
; minimal capacity is around 0.001 nF. So it’s only useful to
; display the highest byte.
mov R0, #X0
mov R1, #X1
mov X1, #03dh
mov X1+1, #04h ; Multiply by 1085
mov R2, #X2
mov X2, #010h
mov X2+1, #27h ; Divide by 10000
mov R3, #X3
mov R4, #X4
lcall MUL_DIV_R0R1R2R3R4
mov R0, #X3
lcall DISPLAY_INTDEC
ret
Logboek practicum electronica II Willem van Engen