I'am getting this error "16 327 Incompatible types ("complex type" to "simple type") Stucture_test.mbas" when the called routine with the structure type is in a module.
program Stucture_test
include "Def_test_I2C1"
main:
dim ts1 as Time_Struct
ts1.ss = 55 'seconds
ts1.mn = 59 'minutes
ts1.hh = 23 'hours
ts1.wd = 7 'weekday
ts1.md = 31 'day
ts1.mo = 12 'month
ts1.yy = 09 'year
I2C_Set_Time(ts1)
end.
module Def_test_I2C1
structure Time_Struct
dim ss as byte ' seconds
dim mn as byte ' minutes
dim hh as byte ' hours
dim wd as byte ' day in week, 1 to 7
dim md as byte ' day in month, 1 to 31
dim mo as byte ' month, 1 to 12
dim yy as byte ' year 00-99
end structure
sub procedure I2C_Set_Time (dim byref ts2 as Time_Struct)
implements
sub procedure I2C_Set_Time (dim byref ts2 as Time_Struct)
' ts2.ss = (((ts2.ss div 10) and 0x07) << 4) or (ts2.ss mod 10)
' ts2.mn = (((ts2.mn div 10) and 0x07) << 4) or (ts2.mn mod 10)
' ts2.hh = (((ts2.hh div 10) and 0x03) << 4) or (ts2.hh mod 10)
' ts2.wd = (((ts2.wd div 10) and 0x00) << 4) or (ts2.wd mod 10)
' ts2.md = (((ts2.md div 10) and 0x03) << 4) or (ts2.md mod 10)
' ts2.mo = (((ts2.mo div 10) and 0x01) << 4) or (ts2.mo mod 10)
' ts2.yy = (((ts2.yy div 10) and 0x0F) << 4) or (ts2.yy mod 10)
RCON.5 = 1 ' enable SWDTEN
' address = %11010000 ' slave RTC address 1101 x A1 A0 RnW
I2C1_Start()
I2C1_Write(0xD0)
I2C1_Write(0x00) ' Start from word at address 0
I2C1_Write(0x02) ' Set W bit = 1 reg 0x00
I2C1_Write(0x80) ' CAL/Control reg 0x01
I2C1_Stop() ' Issue stop signal
I2C1_Start() ' Issue start signal
I2C1_Write(0xD0) ' send address for write
I2C1_Write(0x02) ' Start from word at address 2
I2C1_Write(ts2.ss) ' Write seconds reg 0x02
I2C1_Write(ts2.mn) ' Write minutes reg 0x03
I2C1_Write(ts2.hh) ' Write hours reg 0x04
I2C1_Write(ts2.wd) ' Write weekday reg 0x05
I2C1_Write(ts2.md) ' Write date reg 0x06
I2C1_Write(ts2.mo) ' Write month reg 0x07
I2C1_Write(ts2.yy) ' Write year reg 0x08
I2C1_Stop() ' Issue stop signal
I2C1_Start() ' Issue start signal
I2C1_Write(0xD0) ' Address
I2C1_Write(0x00) ' Start from word at address 0
I2C1_Write(0x00) ' Write 0 to config. byte
I2C1_Write(0x00) ' CAL/Control reg 0x01
I2C1_Stop() ' Issue stop signal
RCON.5 = 0 ' disable SWDTEN
end sub
end.
However, when the routine is included in the main program, it will compile without errors.
program Stucture_test
include "Def_test_I2C1"
sub procedure I2C_Set_Time (dim byref ts2 as Time_Struct)
' ts2.ss = (((ts2.ss div 10) and 0x07) << 4) or (ts2.ss mod 10)
' ts2.mn = (((ts2.mn div 10) and 0x07) << 4) or (ts2.mn mod 10)
' ts2.hh = (((ts2.hh div 10) and 0x03) << 4) or (ts2.hh mod 10)
' ts2.wd = (((ts2.wd div 10) and 0x00) << 4) or (ts2.wd mod 10)
' ts2.md = (((ts2.md div 10) and 0x03) << 4) or (ts2.md mod 10)
' ts2.mo = (((ts2.mo div 10) and 0x01) << 4) or (ts2.mo mod 10)
' ts2.yy = (((ts2.yy div 10) and 0x0F) << 4) or (ts2.yy mod 10)
RCON.5 = 1 ' enable SWDTEN
' address = %11010000 ' slave RTC address 1101 x A1 A0 RnW
I2C1_Start()
I2C1_Write(0xD0)
I2C1_Write(0x00) ' Start from word at address 0
I2C1_Write(0x02) ' Set W bit = 1 reg 0x00
I2C1_Write(0x80) ' CAL/Control reg 0x01
I2C1_Stop() ' Issue stop signal
I2C1_Start() ' Issue start signal
I2C1_Write(0xD0) ' send address for write
I2C1_Write(0x02) ' Start from word at address 2
I2C1_Write(ts2.ss) ' Write seconds reg 0x02
I2C1_Write(ts2.mn) ' Write minutes reg 0x03
I2C1_Write(ts2.hh) ' Write hours reg 0x04
I2C1_Write(ts2.wd) ' Write weekday reg 0x05
I2C1_Write(ts2.md) ' Write date reg 0x06
I2C1_Write(ts2.mo) ' Write month reg 0x07
I2C1_Write(ts2.yy) ' Write year reg 0x08
I2C1_Stop() ' Issue stop signal
I2C1_Start() ' Issue start signal
I2C1_Write(0xD0) ' Address
I2C1_Write(0x00) ' Start from word at address 0
I2C1_Write(0x00) ' Write 0 to config. byte
I2C1_Write(0x00) ' CAL/Control reg 0x01
I2C1_Stop() ' Issue stop signal
RCON.5 = 0 ' disable SWDTEN
end sub
main:
dim ts1 as Time_Struct
ts1.ss = 55 'seconds
ts1.mn = 59 'minutes
ts1.hh = 23 'hours
ts1.wd = 7 'weekday
ts1.md = 31 'day
ts1.mo = 12 'month
ts1.yy = 09 'year
I2C_Set_Time(ts1)
end.
module Def_test_I2C1
structure Time_Struct
dim ss as byte ' seconds
dim mn as byte ' minutes
dim hh as byte ' hours
dim wd as byte ' day in week, 1 to 7
dim md as byte ' day in month, 1 to 31
dim mo as byte ' month, 1 to 12
dim yy as byte ' year 00-99
end structure
implements
end.