'*******************************************************************************
'Compiler 2.0.8.1.000
'
'Cpu : AtxMega32a4u
'crystal : 8Mhz external
'eprom size 1024 byte's
'
'Fuses:
'
' WDWP = 8CLK
' WDP = 8CLK
' BOOTRST = BOOTLDR
' TOSCSEL = XTAL
' BODPD = DISABLED
' RSTDISBL = [unchecked]
' SUT = 4MS
' WDLOCK = [unchecked]
' BODACT = CONTINUOUS
' EESAVE = [unchecked]
' BODLVL = 2V4
'
'*******************************************************************************
$regfile = "xm32a4udef.dat"
$crystal = 8000000
$hwstack = 120 'setup Stacks
$swstack = 120
$framesize = 120
'$loadersize = 4096 ' bootloader starts after the application
'*******************************************************************************
' constanten
'*******************************************************************************
Config_constanten:
Config Submode = New
Const Buildnumber = " 1.0.0.0"
Const Debugoutput = 1
'*******************************************************************************
' Config i/o
'*******************************************************************************
Config_io:
' Config Porta.0 = '
' Config Porta.1 =
' Config Porta.2 =
Config Porta.3 = Output
Config Porta.4 = Output
' Config Porta.5 =
Config Porta.6 = Input
Config Porta.7 = Input
' Config Portb.0 =
' Config Portb.1 =
' Config Portb.2 = '
' Config Portb.3 =
Config Portc.0 = Output 'SDA
Config Portc.1 = Input 'SCL
Config Portc.2 = Input
Config Portc.3 = Output 'TXD Debug
Config Portc.4 = Input
Config Portc.5 = Input
' Config Portc.6 =
' Config Portc.7 =
Config Portd.0 = Input
Config Portd.1 = Input
' Config Portd.2 =
Config Portd.3 = Output 'Led 1
Config Portd.4 = Output 'Led 2
Config Portd.5 = Output 'Led 3
' Config Portd.6 =
' Config Portd.7 =
' Config Porte.0 =
' Config Porte.1 =
' Config Porte.2 =
' Config Porte.3 =
' Config Portr.0 =
' Config Portr.1 =
'*******************************************************************************
' Config dim
'*******************************************************************************
Config_dim:
Dim I2c_receivebyte(10) As Byte
Dim I2c_receiverstop As Bit
'*******************************************************************************
' Config alias
'*******************************************************************************
Config_alias:
Led1 Alias Portd.3
Led2 Alias Portd.4
Led3 Alias Portd.5
'*******************************************************************************
' Config Clock
' Enable the external oscillator with Range 2MHz....9MHz
'*******************************************************************************
Config_clock:
Config Osc = Disabled , Extosc = Enabled , Range = 2mhz_9mhz , Startup = Xtal_256clk
Config Sysclock = External , Prescalea = 1 , Prescalebc = 1_1
'*******************************************************************************
' Config timer 0 as 100mS ticker
'
' 1
' ----------
' (8MHz/256) = 0.00032 x 3125 --> 100mSecOne Tick
' Setup overflow interrupt of Timer/Counter C0 and
' Enable overflow interrupt in LOW Priority
'
'*******************************************************************************
Config_tcc0:
Config Tcc0 = Normal , Prescale = 256
Tcc0_per = 3125
On Tcc0_ovf Tc0_isr
Enable Tcc0_ovf , Lo
'*******************************************************************************
' Config compoort
'*******************************************************************************
Config_comport:
Config Com1 = 115200 , Mode = Asynchroneous , Parity = None , Stopbits = 1 , Databits = 8
Open "COM1:" For Binary As #1
'*******************************************************************************
' Config eeprom
'*******************************************************************************
Config_eeprom:
Config Eeprom = Mapped
'*******************************************************************************
' Configure TWI Slave hardware registers. Base address is 90 but we twiddle
' the TWAR register if we want a secondary address
'*******************************************************************************
Config_twi:
Config Scl = Portc.1 ' we need to provide the SCL pin name
Config Sda = Portc.0 ' we need to provide the SDA pin name
Dim Twi_start As Byte , B As Byte
Config Twicslave = &H46 , Btr = 2 'use address &H70 which is
'*******************************************************************************
' Config Defaults
'*******************************************************************************
Config_defaults:
'*******************************************************************************
' Config interrupts
'*******************************************************************************
Config_interupts:
Config Priority = Static , Vector = Application , Lo = Enabled , Med = Enabled , Hi = Enabled
Enable Interrupts 'TWIC needs interrupts
'*******************************************************************************
' Enter main loop
'*******************************************************************************
Main:
Set Led2
Reset Led3
Dim Tempb As Byte
Tempb = &HFF
Dim Tt As Byte
Do
If I2c_receiverstop = 1 Then 'all data is received
#if Debugoutput = 1
Print #1 , "recieve completed"
#endif
I2c_receiverstop = 0
Select Case I2c_receivebyte(1)
Case 10:
Case 11:
Case 12:
Case 13:
End Select
End If
Loop
End
'*******************************************************************************
' Timer 0 isr routine
'*******************************************************************************
Tc0_isr:
Toggle Led1
Return
'*******************************************************************************
' TWIC routines
'*******************************************************************************
Twi_stop_rstart_received: 'Single byte commands
#if Debugoutput = 1
Print #1 , "Master sent stop or repeated start"
#endif
Set I2c_receiverstop
Return
Twi_addressed_goread:
#if Debugoutput = 1
Print #1 , "We were addressed and master will send data"
#endif
Return
Twi_addressed_gowrite:
#if Debugoutput = 1
Print #1 , "We were addressed and master will read data"
#endif
Return
Twi_gotdata:
#if Debugoutput = 1
Print #1 , "Twic: " ; Twic ; " Twic_btw : " ; Twic_btw
#endif
I2c_receivebyte(twic_btw) = Twic
Return
Twi_master_needs_byte:
#if Debugoutput = 1
Print #1 , "Master needs byte : " ; Twic_btr
#endif
Twic = 56
Return
Twi_master_need_nomore_byte:
#if Debugoutput = 1
Print #1 , "Master does not need anymore bytes"
#endif
Return
End
|