Code
[linereset]
program MINI3_X1;
{$NOWATCHDOGAUTO}
{$NOSHADOW}
{$WG}
Device = xmega256A3BU, VCC=3.3;
{ $BOOTRST $20000} {Reset Jump to $20000}
Define_Fuses
Override_Fuses;
NoteBook = D;
COMport = USB;
LockBits0 = [];
FuseBits0 = [];
FuseBits1 = [];
FuseBits2 = [];
FuseBits5 = [BODACT0, BodLevel0, BodLevel1, BodLevel2];
Import SysTick,WatchDog, SerPortC0, SerPortC1, SerPortE0, SerPortF0, I2Cport;
Import RTclock, UserPort, TWI_E, TickTimer, ADC_A;
Import BeepPort, SerPortCDC;
From System Import Float,LongWord;
Define
// XMega USB must use the internal 32MHz OSC. So the system must use the 2MHz OSC
OSCtype = int2MHz,
PLLmul = 16,
prescB = 1,
prescC = 1;
SysTick = 10, User; // msec
StackSize = $0128, iData;
FrameSize = $0128, iData;
WatchDog = msec2000; {2048msec}
USBmanufact = 'AVRco Pascal'; // max 31 bytes
USBprodName = 'Serial CDC-USB'; // "
USBpid = $77;
USBvid = $BCDE;
USBprodRel = 203;
USBcurrent = 100;
// USBvBUS = PortB.7; // port und pin, optional
SerPortCDC = TimeOut;
RxBufferCDC = 64, iData;
TxBufferCDC = 100, iData;
ADCrefA = REFextA;
ADCprescA = 256,12; // prescaler 64
ADCchansA = [0..2];
I2Cport = PortC;
I2Cdat = 0;
I2Cclk = 1, 255;
TWIprescE = TWI_BR400;
UserPort = 65535;
BeepPort = PortR,0;
{ RTC-CPU-Uhr intern }
TickTimer = Timer_C0; // use Timer_C0 and no PortPin
RTclock = iData, DateTime; {Time, DateTime}
RTCsource = SysTick; {, adj} { adj = +/-100}
// RS232
SerPortC0 = 115200,Stop1,timeout;
RxBufferC0 = 40, iData;
TxBufferC0 = 100, iData;
// RS232
SerPortC1 = 115200,Stop1,timeout;
RxBufferC1 = 40, iData;
TxBufferC1 = 100, iData;
// RS485
SerPortE0 = 38400, Stop1, timeout; {Baud, StopBits|Parity}
SerCtrlE0 = PortE, 4, positive;
RxBufferE0 = 40, iData;
TxBufferE0 = 100, iData;
// RS485
SerPortF0 = 115200, Stop1, timeout; {Baud, StopBits|Parity}
SerCtrlF0 = PortF, 1, positive;
RxBufferF0 = 40, iData;
TxBufferF0 = 100, iData;
Uses uXmega_CDC,
EcoDef_01,
EcoDOS1,
ModUST1,
EcoReg01;
Implementation
{$IDATA}
{------------------------------------------------------------------------------}
{ Type Declarations }
Type
{--------------------------------------------------------------}
{ Const Declarations }
Const
{--------------------------------------------------------------}
{ Var Declarations }
{$IDATA}
Var
ww : Word;
ch : char;
st : string[16];
{$IDATA}
{$NoSave} // standard register save is sufficient
{--------------------------------------------------------------}
{--------------------------------------------------------------}
Interrupt TCD0_INTOVF;
begin
ASM: CALL System.$INTERRUPT_SYSTICK_USER;
end;
{--------------------------------------------------------------}
{--------------------------------------------------------------}
Procedure onTickTimer; // onTickTimer(SaveAllRegs);SaveAllRegs not necessary here
begin
ASM: CALL System.$INTERRUPT_SYSTICK_USER;
end;
{--------------------------------------------------------------}
{--------------------------------------------------------------}
(* for a UserDevice the following 3 function must be implemented *)
UserDevice UsrDevIni;
begin
end;
{--------------------------------------------------------------}
{--------------------------------------------------------------}
UserDevice UsrDevInp (adr : word) : byte;
var
ERR : Byte;
EEByte : Byte;
begin
If TWIOutE($50,adr) Then
Err:=50;
Repeat
uDelay(15);
Dec(Err);
Until TWIInpE($50,EEByte) Or (Err=0);
If Err=0 Then Return($ff); Else Return(EEByte); EndIf;
EndIf;
end;
{--------------------------------------------------------------}
{--------------------------------------------------------------}
UserDevice UsrDevOut (adr : word; outp : byte);
var
ERR : Byte;
begin
If TWIOutE($50,adr,outp) Then
Err:=50;
Repeat
uDelay(15);
Dec(Err);
Until (TWIStatE($50)) Or (Err=0);
EndIf;
End;
{--------------------------------------------------------------}
{ Init System und Ports }
{ Ports DDR = Output=1 Input=0 }
{--------------------------------------------------------------}
Procedure InitSystem;
Begin
InitPorts;
If RTCOk=True Then DS1307SetTime(16,10,00); EndIf;
SetIntTime(18,38,00);
SetIntDate(16,12,02,5);
WatchDogStart;
If RTCOk=False Then
GetIntTime;
GetIntDate;
EndIf;
// TestI2CUST;
End;
(*------------------------------------------------------------------*)
(* Interrupt durch interne Uhr *)
(*------------------------------------------------------------------*)
Procedure RTCtickMinute;
Begin
GetIntTime;
GetIntDate;
Write(SerOutC0,DateToString+' '+TimeToString+#13+#10);
End;
(*------------------------------------------------------------------*)
(*------------------------------------------------------------------*)
Procedure SendTabloDaten;
Begin
Case (RTC.Second And $03) Of
// 0: MB_VB_FlagAmp2;|
// 2: MB_Send_Akt_Systemdaten;|
EndCase;
End;
{--------------------------------------------------------------------}
(* Interrupt durch interne Uhr *)
{--------------------------------------------------------------------}
Procedure RTCtickSecond;
Var
xy : Byte;
begin
WatchDogTrig;
If SysTic=False Then
SysTic:=True;
StopRegelung:=True;
Inc(RTC.Second);
If RTC.Second>59 Then RTC.Second:=0; EndIf;
If SysDatPoll=True Then
xy:=0;
Repeat
(*
SetSerEnable(UsartE0, true);
WriteLn(SerOutE0,ByteToStr(xy));
SetSerEnable(UsartE0, false);
SetSerEnable(UsartF0, true);
// WriteLn(SerOutF0,ByteToStr(xy));
SetSerEnable(UsartF0, false);
*)
If Mod_2REL[xy]=$0 Then Mod_2REL[xy]:=$FF; Else Mod_2REL[xy]:=$0; EndIf;
Read_IOD_Modul_2REL(xy);
mDelay(15);
Inc(xy);
Until xy>5;
EndIf;
StopRegelung:=False;
EndIf;
End;
{--------------------------------------------------------------}
{--------------------------------------------------------------}
{ Main Program }
{$IDATA}
begin
StopRegelung:=True;
SysTic:=True;
EnableInts($87); // mandory for USB_ControlJob
TickTimerTime(10000); // 10000usec = 10msec
TickTimerStart;
InitSystem;
ProgVersion;
PollLED:=True;
BeepChirpL(1);
StopRegelung:=False;
SysTic:=False;
SetSerEnable(UsartE0, true);
WriteLn(SerOutE0,'Start');
SetSerEnable(UsartE0, false);
loop
WatchDogTrig;
If SysTic Then
PollLED:=False;
// Regeln;
mDelay(100);
PollLED:=True;
SysTic:=False;
EndIf;
endloop;
end.