Hallo zusammen. Ich bräuchte mal Hilfe beim Switchport. Ich habe an einem XMEGA256A3BU am PortA 4 Taster (Bit 3 bis 6) die gegen Low gezogen werden. Die arbeiten auch ordentlich, der Pegel geht sauber von 3,3V auf 0V beim Drücken. Dennoch liefert INP_STABLE1(x) kein Ergebnis. hab schon alle möglichen Sachen ausprobiert und weiß nicht mehr weiter.
Hier mal mein aktueller Code.
program Stepperfoc3;
Device = xmega256A3BU, VCC=3.3;
{ $BOOTRST $20000} {Reset Jump to $20000}
Define_Fuses
Override_Fuses;
NoteBook = D;
COMport = USB;
LockBits0 = []; // protect boot and app against read back
FuseBits0 = [];
FuseBits1 = [];
FuseBits2 = []; // mandatory !!
// Brown-out is obligatory with USB !!!
FuseBits5 = [BODACT0, BodLevel0, BodLevel1, BodLevel2];
Import SysTick, FlashWrite, SwitchPort1, SerportF0, TickTimer,USBSmart,QDEC_C0;
Import WatchDog,StepL6470;
From System Import LongWord, LongInt,Float, Processes, Tasks, Pipes, {SwitchPTimer1,} FlashCheck_S, FlashCheck_B;
From SerPort Import SerPortSelect;
Define
// XMega USB must use the internal 32MHz OSC. So the system must use the 2MHz OSC
// Wegen USB Port
OSCtype = int2MHz,
PLLmul = 16,
prescB = 1,
prescC = 1;
SysTick = 10,User; {msec}
StackSize = $0080, iData;
FrameSize = $0080, iData;
Scheduler = iData;
TaskStack = $0020, iData;
TaskFrame = $0010;
FlashChksum = ProgEnd; {or absolute address}
TickTimer = Timer_C1;
SerPortF0 = 56000,Stop1,timeout; {Baud, StopBits|timeout}
RxBufferF0 = 64, iData;
TxBufferF0 = 64, iData;
//QuadraturDecoder
QDECphase_C0 = PortD, 0, 1; // Port, Phase0, Phase90 input pin
QDECres_C0 = 32; // Resolution QDEC C0, 16 or 32
QDECevChan_C0 = 1; // 0..7
Watchdog = msec2000; //Watchdog auf 2 Sek setzen.
SwitchPort1 = PinA;
PolarityP1 = %10000111; // polarity
Debounce = 5;
//Definitionen für die USB Schnittstelle
USBmanufact = 'xxxx'; // max 31 bytes
USBprodName = 'xxx'; // " "
USBpid = 30;
USBvid = $0569;
USBprodRel = 300;
USBcurrent = 200;
USBvBUS = PortC.0; // port and pin
StepL6470drvs = 1; // driver stage count
StepL6470port = SPI_Soft, PortB.2, PortB.3, PortB.4;
StepL6470SS_1 = PortB.5, PortB.7; // chipselect and SingleStep pin //ToDo
uses uL6470,lcd144Ser;
Implementation
{$IDATA}
{--------------------------------------------------------------}
{ Type Declarations }
type
tBuf64 = Array[0..63] of byte;
{--------------------------------------------------------------}
{ Const Declarations }
const
//Downloader ID muss mit der im Bootloader übereinstimmen, damit Firmware
//geflasht werden kann
DownLoaderID : word = $1234; // mandatory constant
{--------------------------------------------------------------}
{ Var Declarations }
{$IDATA}
var
// these two buffers must be aligned to even addresses !!
RxBuf : tBuf64, align2; // USB incomming Buffer
TxBuf : tBuf64, align2; // USB outgoing Buffer
usbCommand : byte;
{--------------------------------------------------------------}
{ functions }
{--------------------------------------------------------------}
// User function to receive EP0 ControlRequests from Host
Function myUSB_ControlRequest(bRequest : Byte; wValue : word) : boolean;
// need always answer from device
begin
usbCommand:=bRequest;
case (bRequest) of
$00 : // do a real RESET
USB_ControlSend(nil, 0);
mDelay(100);
HardWareReset;
|
else
USB_ControlSend(nil, 0); // unknown vendor request, do an ACK
Return(true);
endcase;
end;
{--------------------------------------------------------------}
Procedure USB_CheckRxTx;
Var Count, C: byte;
begin
if USB_RxDataAvail then
Count:= USB_RxCount;
c:=RXBuf[0];
//writeln(Serout,'USBChar:'+bytetostr(c));
//writeln(Serout,'USBCount:'+bytetostr(count));
case C of
$02: //IPAdressen aus dem USBPuffer in den EEprom
// writeln(serout,'USBConfig');
// CopyBlock(@rxBuf+1,@elocalIP,4);
// writeln(serout,'IP:'+IPToStr(elocalIP));
// CopyBlock(@rxBuf+5,@eremoteIP,4);
// CopyBlock(@rxBuf+9,@eGateway,4);
// CopyBlock(@rxBuf+13,@eMask,4);
// CopyBlock(@rxBuf+17,@eMAC,6);
mdelay(200);
HardWareReset;
|
endcase;
// Daten als Response zurücksenden
CopyBlock(@rxBuf,@txBuf,word(count));
USB_TxSend(@TxBuf,64);
USB_RxSetBuf(@RxBuf); // we need more data ..
USBCommand:=0;
endif;
end;
// PORTS definieren
procedure InitPorts;
begin
//Für die Tasten
PortA:= %01111110;
DDRA := DDRA AND %10000111; //inputs auf die schalter
DDRE:=$FF;
PortE:=$FF;
lcd_Reset;
end; //InitPorts
process SendStatus(20,20:iData;3,suspended);
begin
// Sendflag:=true;
// mdelay(100);
end;
//Prozess für die USB Kommunikation
process RunUSB(80,80:iData);
begin
USB_ControlJob; // or run in Systick every < 40ms
USB_CheckRxTx;
end RunUSB;
{--------------------------------------------------------------}
{ Main Program }
{$IDATA}
begin
EEprom[EEpromEnd]:= $00;
initports;
//USB initialisierung
USB_SetControlCallback(@myUSB_ControlRequest); // optional, if you need it!
USB_Init(@RxBuf); // Attach USB and connect RxBuf for FIRST RX INT
USB_RxSetBuf(@RxBuf); // we need more data ..
SerPortSelect:= UsartF0;
EnableInts($87);
Start_Processes($87);
mdelay(3000); //Auf das Display warten
//lcd_init;
//lcd_cls;
//Die Hauptschleife
loop
if Inp_STABLE1(3) then // SWITCHPORT1 Bit3 = TRUE
lcd_Text('Key1',7,5,white);
endif;
if Inp_STABLE1(4) then // SWITCHPORT1 Bit4 = TRUE
lcd_Text('Key2',7,5,white);
endif;
if Inp_STABLE1(5) then // SWITCHPORT1 Bit5 = TRUE
lcd_Text('Key3',7,5,white);
endif;
if Inp_STABLE1(6) then // SWITCHPORT1 Bit6 = TRUE
lcd_Text('Key4',7,5,white);
endif;
endloop;
end Stepperfoc3.
Meine Compilerversion ist die 5.04.50.
Für sachdienliche Hinweise bin ich sehr dankbar.
Hier mal mein aktueller Code.
Code
program Stepperfoc3;
Device = xmega256A3BU, VCC=3.3;
{ $BOOTRST $20000} {Reset Jump to $20000}
Define_Fuses
Override_Fuses;
NoteBook = D;
COMport = USB;
LockBits0 = []; // protect boot and app against read back
FuseBits0 = [];
FuseBits1 = [];
FuseBits2 = []; // mandatory !!
// Brown-out is obligatory with USB !!!
FuseBits5 = [BODACT0, BodLevel0, BodLevel1, BodLevel2];
Import SysTick, FlashWrite, SwitchPort1, SerportF0, TickTimer,USBSmart,QDEC_C0;
Import WatchDog,StepL6470;
From System Import LongWord, LongInt,Float, Processes, Tasks, Pipes, {SwitchPTimer1,} FlashCheck_S, FlashCheck_B;
From SerPort Import SerPortSelect;
Define
// XMega USB must use the internal 32MHz OSC. So the system must use the 2MHz OSC
// Wegen USB Port
OSCtype = int2MHz,
PLLmul = 16,
prescB = 1,
prescC = 1;
SysTick = 10,User; {msec}
StackSize = $0080, iData;
FrameSize = $0080, iData;
Scheduler = iData;
TaskStack = $0020, iData;
TaskFrame = $0010;
FlashChksum = ProgEnd; {or absolute address}
TickTimer = Timer_C1;
SerPortF0 = 56000,Stop1,timeout; {Baud, StopBits|timeout}
RxBufferF0 = 64, iData;
TxBufferF0 = 64, iData;
//QuadraturDecoder
QDECphase_C0 = PortD, 0, 1; // Port, Phase0, Phase90 input pin
QDECres_C0 = 32; // Resolution QDEC C0, 16 or 32
QDECevChan_C0 = 1; // 0..7
Watchdog = msec2000; //Watchdog auf 2 Sek setzen.
SwitchPort1 = PinA;
PolarityP1 = %10000111; // polarity
Debounce = 5;
//Definitionen für die USB Schnittstelle
USBmanufact = 'xxxx'; // max 31 bytes
USBprodName = 'xxx'; // " "
USBpid = 30;
USBvid = $0569;
USBprodRel = 300;
USBcurrent = 200;
USBvBUS = PortC.0; // port and pin
StepL6470drvs = 1; // driver stage count
StepL6470port = SPI_Soft, PortB.2, PortB.3, PortB.4;
StepL6470SS_1 = PortB.5, PortB.7; // chipselect and SingleStep pin //ToDo
uses uL6470,lcd144Ser;
Implementation
{$IDATA}
{--------------------------------------------------------------}
{ Type Declarations }
type
tBuf64 = Array[0..63] of byte;
{--------------------------------------------------------------}
{ Const Declarations }
const
//Downloader ID muss mit der im Bootloader übereinstimmen, damit Firmware
//geflasht werden kann
DownLoaderID : word = $1234; // mandatory constant
{--------------------------------------------------------------}
{ Var Declarations }
{$IDATA}
var
// these two buffers must be aligned to even addresses !!
RxBuf : tBuf64, align2; // USB incomming Buffer
TxBuf : tBuf64, align2; // USB outgoing Buffer
usbCommand : byte;
{--------------------------------------------------------------}
{ functions }
{--------------------------------------------------------------}
// User function to receive EP0 ControlRequests from Host
Function myUSB_ControlRequest(bRequest : Byte; wValue : word) : boolean;
// need always answer from device
begin
usbCommand:=bRequest;
case (bRequest) of
$00 : // do a real RESET
USB_ControlSend(nil, 0);
mDelay(100);
HardWareReset;
|
else
USB_ControlSend(nil, 0); // unknown vendor request, do an ACK
Return(true);
endcase;
end;
{--------------------------------------------------------------}
Procedure USB_CheckRxTx;
Var Count, C: byte;
begin
if USB_RxDataAvail then
Count:= USB_RxCount;
c:=RXBuf[0];
//writeln(Serout,'USBChar:'+bytetostr(c));
//writeln(Serout,'USBCount:'+bytetostr(count));
case C of
$02: //IPAdressen aus dem USBPuffer in den EEprom
// writeln(serout,'USBConfig');
// CopyBlock(@rxBuf+1,@elocalIP,4);
// writeln(serout,'IP:'+IPToStr(elocalIP));
// CopyBlock(@rxBuf+5,@eremoteIP,4);
// CopyBlock(@rxBuf+9,@eGateway,4);
// CopyBlock(@rxBuf+13,@eMask,4);
// CopyBlock(@rxBuf+17,@eMAC,6);
mdelay(200);
HardWareReset;
|
endcase;
// Daten als Response zurücksenden
CopyBlock(@rxBuf,@txBuf,word(count));
USB_TxSend(@TxBuf,64);
USB_RxSetBuf(@RxBuf); // we need more data ..
USBCommand:=0;
endif;
end;
// PORTS definieren
procedure InitPorts;
begin
//Für die Tasten
PortA:= %01111110;
DDRA := DDRA AND %10000111; //inputs auf die schalter
DDRE:=$FF;
PortE:=$FF;
lcd_Reset;
end; //InitPorts
process SendStatus(20,20:iData;3,suspended);
begin
// Sendflag:=true;
// mdelay(100);
end;
//Prozess für die USB Kommunikation
process RunUSB(80,80:iData);
begin
USB_ControlJob; // or run in Systick every < 40ms
USB_CheckRxTx;
end RunUSB;
{--------------------------------------------------------------}
{ Main Program }
{$IDATA}
begin
EEprom[EEpromEnd]:= $00;
initports;
//USB initialisierung
USB_SetControlCallback(@myUSB_ControlRequest); // optional, if you need it!
USB_Init(@RxBuf); // Attach USB and connect RxBuf for FIRST RX INT
USB_RxSetBuf(@RxBuf); // we need more data ..
SerPortSelect:= UsartF0;
EnableInts($87);
Start_Processes($87);
mdelay(3000); //Auf das Display warten
//lcd_init;
//lcd_cls;
//Die Hauptschleife
loop
if Inp_STABLE1(3) then // SWITCHPORT1 Bit3 = TRUE
lcd_Text('Key1',7,5,white);
endif;
if Inp_STABLE1(4) then // SWITCHPORT1 Bit4 = TRUE
lcd_Text('Key2',7,5,white);
endif;
if Inp_STABLE1(5) then // SWITCHPORT1 Bit5 = TRUE
lcd_Text('Key3',7,5,white);
endif;
if Inp_STABLE1(6) then // SWITCHPORT1 Bit6 = TRUE
lcd_Text('Key4',7,5,white);
endif;
endloop;
end Stepperfoc3.
Meine Compilerversion ist die 5.04.50.
Für sachdienliche Hinweise bin ich sehr dankbar.