Hallo Bascom Freunde, ich habe auf der MCS Page folgendes Beispiel für den AD-Converter TLC 2543 gefunden, leider ist es nur für 8051er geschrieben. Könnt Ihr mir behilflich sein bei der der Anpassung an einen AVR 90S2333. Gruß Heiko ' ' 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
Hallo Heiko Warum Externe AD-Wandler?. Der 2333 hat doch 6 Stück an Bord ;-) Mit BASCOM-AVR ist es doch einfacher die Internen AD-Wandler zu programmieren,siehe Anhang MfG ThomasB
Hi Thomas, Nur leider sind die internen ADC´s auf 10Bit begrenzt. und der TLC2543 hat 12Bit also 4096 nicht nur 1024, das macht schon eine Menge aus. MFG Heiko
Bitte melde dich an um einen Beitrag zu schreiben. Anmeldung ist kostenlos und dauert nur eine Minute.
Bestehender Account
Schon ein Account bei Google/GoogleMail? Keine Anmeldung erforderlich!
Mit Google-Account einloggen
Mit Google-Account einloggen
Noch kein Account? Hier anmelden.