Moin!
Wie angekündigt hier nun der Code, den ich zurzeit für die Ansteuerung des TLC5940 nutze.
Er ist noch nicht kommentiert, aber dem geneigten Leser wird es nicht schwerfallen, ihn zu verstehen.
Gruß
Jan
[code:1]'###################################################################################################################################
'##### #######
'##### Ansteuerung des TLC5940 PWM-ICs von Texas Instruments (http://focus.ti.com/docs/prod/folders/print/tlc5940.html) #######
'##### #######
'##### Projekt: tlc5940.bas #######
'##### Erstellt: 08.02.2008 #######
'##### Version: 0.3 #######
'##### Erstellt durch: Jan #######
'##### #######
'##### Change history: #######
'##### 08.02.2008 -- initial release #######
'##### 12.02.2008 -- Adding variable dot correction and usage of timer interrupt for pwm-clock #######
'##### 14.02.2008 -- code cleanup #######
'##### #######
'##### #######
'###################################################################################################################################
'################################
'##### #######
'##### Gen.-Settings #######
'##### #######
'################################
$regfile = "m32def.DAT"
$crystal = 16000000
$hwstack = 64
$swstack = 64
$framesize = 64
$baud = 9600
'################################
'##### #######
'##### Timer-Konfig. #######
'##### #######
'################################
On Timer0 Pwm
Config Timer0 = Timer , Prescale = 1024
Enable Timer0
Enable Interrupts
'################################
'##### #######
'##### Port-Konfig. #######
'##### #######
'################################
Config Portc = Output
Vprg Alias Portc.0
Si Alias Portc.1
Sclk Alias Portc.2
Xlat Alias Portc.3
Blank Alias Portc.4
Dcprog Alias Portc.5
Gsclk Alias Portc.6
'################################
'##### #######
'##### Deklarationen #######
'##### #######
'################################
Declare Sub Setdc
Dim Pulse As Integer
Dim A As Integer , B As Integer
Dim Led As Byte , Channels As Byte
Dim Gsout As Integer , Dcout As Byte
'################################
'##### #######
'##### Initialisierung #######
'##### #######
'################################
Const Tlcs = 1 'Anzahl der TLCs
#if Tlcs = 1
Dim Channel(16) As Integer , Channeldc(16) As Byte
#elseif Tlcs = 2
Dim Channel(32) As Integer , Channeldc(32) As Byte
#endif
#if Tlcs = 3
Dim Channel(48) As Integer , Channeldc(48) As Byte
#endif
#if Tlcs = 4
Dim Channel(64) As Integer , Channeldc(64) As Byte
#endif
Channels = Tlcs * 16
'################################
'##### #######
'##### DotCorrection #######
'##### #######
'################################
For A = 1 To Channels
Channeldc(a) = 63 'Keine DotCorrection, volles Rohr
Next
Call Setdc
'################################
'##### #######
'##### Hauptschleife #######
'##### #######
'################################
Do
For A = 1 To Channels
For B = 0 To 4095
Channel(a) = B
Waitus 25
Next
Next
For A = Channels To 1 Step -1
For B = 4095 To 0 Step -1
Channel(a) = B
Waitus 25
Next
Next
Loop
End
'################################
'##### #######
'##### Methoden und #######
'##### Funktionen #######
'##### #######
'################################
Sub Setdc 'DotCorrection
Set Dcprog
Set Vprg
Set Blank
Reset Si
Reset Xlat
Dim Dotcorrection As Byte
For Dotcorrection = Channels To 1 Step -1
Dcout = Channeldc(dotcorrection)
Shiftout Si , Sclk , Dcout , 0 , 6
Next
Set Xlat
Reset Xlat
Reset Vprg
'Lt. Datenblatt notwendig, funzt aber genausogut ohne
'Set Sclk
'Reset Sclk
Reset Blank
End Sub
'###############################
'##### #######
'##### PWM-Timer #######
'##### Interrupt #######
'##### #######
'###############################
Pwm:
For Led = Channels To 1 Step -1
Gsout = Channel(led)
Rotate Gsout , Right , 12
Shiftout Si , Sclk , Gsout , 0 , 12
Next
Set Xlat
Reset Xlat
For Pulse = 0 To 4095
Set Gsclk
Reset Gsclk
Next
Set Blank
Reset Blank
Return
[/code:1]