' #############################################################################
' ##### Basisroutinen für das Mega128-EvalBoard ###############################
' #############################################################################
' (c) 27.06.2010 by Dino
' BASCOM 2.0.7.0
'
'
' Prozessor ATmega128
$regfile = "m128def.dat"
' 14,7456MHz Quarztakt (Baudraten-Quarz)
$crystal = 14745600
$hwstack = 128
$swstack = 128
$framesize = 128
' =============================================================================
' ===== PortD =================================================================
' =============================================================================
' PD0 ---->-- SCL | I2C
' PD1 --<->-- SDA | TWI
'
' PD2 --<---- RxD1 | UART1
' PD3 ---->-- TxD1 | TTL-Pegel
'
' PD4 --<---- Taster1 (links)
' PD5 --<---- Taster2
' PD6 --<---- Taster3
' PD7 --<---- Taster4 (rechts)
'
' I=7= I=6= I=5= I=4= O=3= I=2= I=1= O=0= => 00001001 => DDRD
' T4 T3 T2 T1 TxD1 RxD1 SDA SCL => 11110110 => PORTD (init)
' | | | | | | | |
'
Ddrd = &B0000_1001
Portd = &B1111_0110
'
' =============================================================================
' ===== I2C/TWI initialisieren ================================================
' =============================================================================
$lib "i2c_twi.lbx" ' Bibliothek fuer Hardware-TWI einbinden
Config Scl = Portd.0
Config Sda = Portd.1
I2cinit
Config Twi = 300000 ' Taktfrequenz 300 kBit/s
' TWI gleich einschalten, das macht BASCOM ansonsten erst beim I2CStart
'Twcr = &B00000100 ' nur TWEN setzen
' Optionale Einstellungen für TWI Kommunikation die nicht zwingend erforderliche sind
' Twsr = 0 ' Status und Prescaler Register
' Twbr = 152 ' Bit Rate Register, 72 = 100kHz 152 = 50kHz(0 bis 255)
' Config I2cdelay = 40
I2cstart
I2cstop
'
' =============================================================================
' ===== UART1 (TTL) initialisieren ============================================
' =============================================================================
Config Com2 = 57600 , Synchrone = 0 , Parity = None , Stopbits = 1 , Databits = 8 , Clockpol = 0
Config Serialin1 = Buffered , Size = 16
Open "com2:" For Binary As #2
' =============================================================================
' ===== PortE =================================================================
' =============================================================================
' PE0 --<---- RxD0 | UART0
' PE1 ---->-- TxD0 | RS232-Pegel
' PE2 --<---- CTS | mit Hardware-
' PE3 ---->-- RTS | Handshake
'
' PE4 -- frei
' PE5 -- frei
' PE6 --<---- DS1307 SQWout (auf INT6)
' PE7 --<---- DCF77-Empfaenger
'
' I=7= I=6= I=5= I=4= O=3= I=2= I=1= O=0= => 00001010 => DDRD
' DCF SQW ---- ---- RTS CTS TxD0 RxD0 => 11111111 => PORTD (init)
' | | o o | | | |
'
Ddre = &B0010_1010
Porte = &B1111_1111
'
' ===== UART1 (RS232) initialisieren ==========================================
Config Com1 = 460800 , Synchrone = 0 , Parity = None , Stopbits = 1 , Databits = 8 , Clockpol = 0
Config Serialin = Buffered , Size = 16
Open "com1:" For Binary As #1