|
Reading the TLC2543 A/D converter The TLC2543 A/D converter is on a new PLC from Ibercomp SA.
This PLC named DOMO, will have special BASCOM-DOMO BASIC.
Miguel Zúńiga, has written the following code to read the A/D converter.
Download source code in Zip file
'
' EXAMPLE PROGRAM
FOR DOMO - I
'
' READ ANALOG
INPUTS
'
' (C) 1999
IBERCOMP SA - Writen by MIGUEL ZUŃIGA
'
$large
Config Lcdpin , Db4 = P2.4 , Db5 = P2.5 , Db6 = P2.6 , Db7 = P2.7 , E = P2.1 , Rs = P2.2
Config Sda = P1.0
Config Scl = P1.1
Dim Num As Byte
Dim State As Word
Declare Sub
Rw_tlc2543c (num As Byte)
declare Sub
Read_analog (num As Byte)
Init:
'Assembler code
is needed because BASCOM do not handle R/-W line
'for LCD, so this
must be put manually to low before initialise
'display.
$asm
MOV C, P2.0
CLR P2.0
JNC continue
LJMP 0
Continue:
$end Asm
Waitms 500 'Needed to prevent ISP accesing (ATMEL ISP Bug)
Cls
Lcd " "
Locate 1 , 1
Lcd " ANALOG INPUTS "
Do
State = 9
Read_analog 0
Locate 2 , 3
Lcd State ; " "
Locate 2 , 1
Lcd " "
Waitms 500
Locate 2 , 1
Lcd "*"
Waitms 500
Loop
Eoc Alias P3.3 ' End of Conversión
Clk Alias P3.4 ' Comunications clock
Di Alias P3.5 ' Data In
Do Alias P1.2 ' Data Out
Cs Alias P1.3 ' Chip Select
'
' Routine that
reads an analog Input
'
Sub Read_analog (num As Byte)
Num = Num * 16 ' Ask conversion on requested chanel
Rw_tlc2543c Num
Rw_tlc2543c 0 'Read result of conversion
End Sub
'
' Routine that
access to TLC 2543C Anlog->Digital conversor
' (LOW LEVEL)
Sub Rw_tlc2543c (num As Byte)
$asm
mov DPL, {num}
setb CS ;Initially chip is not selected
clr CLK ;Clock signal is at low level
nop ;Wait at leat 1 us for stability
nop
clr CS ;Select conversor
mov B, #8 ;First write/read 8 bits
Bucle0:
mov A, DPL ;Puts the most significative bit on C
rlc A
mov DPL, A
mov DI, C ;Write C value to DI signal
mov C, DO ;Reads DO signal in Carry
mov A, DPH ;and save it
with a carry rotation
rlc A
mov DPH, A
setb CLK ;Pulse on CLK signal
nop
nop
clr CLK
djnz B, bucle0
mov DPL, #0
mov B, #4 ;Now reads 4 bits
Bucle1:
mov C, DO ;Reads DO signal in Carry bit
mov A, DPL ;and save it
with a carry rotation
rlc A
mov DPL, A
setb CLK ;Pulse on CLK signal
nop
nop
clr CLK
djnz B, bucle1
; Dpl Contents 4 Less Significant Bits
; Dph Contents 8 Most Significant Bits
setb CS
mov A, DPH
Swap A
push ACC
anl A, #15
mov DPH, A
pop ACC
anl A, #&H0F0
orl A, DPL
mov DPL, A
Bucle2:
jnb EOC, bucle2 ;Wait for conversion
mov {state}, DPL ;LSB
mov {state+1}, DPH ;MSB
$end Asm
End Sub |