int vswitch;
S1
main(){
// state of virtual switch controlled by button
// begin main program
// set up parallel port A as output
WrPortI(SPCR,NULL,0x84);
WrPortI(PADR,&PADRShadow,0xff);
vswitch=0;
(1) while (1) {
BigLoopTop();
// turn off all LEDs
// initialize virtual switch off
// Endless loop
// Begin a big endless loop
// first task flash LED DS4 every second for 200 milliseconds
(2)
(3)
(4)
costate {
BitWrPortI(PADR,&PADRShadow,0,3);
waitfor(DelayMs(200));
BitWrPortI(PADR,&PADRShadow,1,3);
waitfor(DelayMs(800));
}
//
//
//
//
//
//
begin a costatement
LED DS4 on
light on for 200 ms
LED DS4 off
light off for 800 ms
end of costatement
// second task - debounce switch #1 and toggle virtual switch vswitch
// check button 1 and toggle vswitch on or off
costate {
(5)
out
if(BitRdPortI(PBDR,2)) abort;
waitfor(DelayMs(50));
if(BitRdPortI(PBDR,2)) abort;
// if button not down skip out
// wait 50 ms
// if button not still down skip
ms
vswitch=!vswitch;
// toggle virtual switch- button was down 50
while (1) {
//
wait for button to be off 200 ms
waitfor(BitRdPortI(PBDR,2)); //
wait for button to go up
waitfor(DelayMs(200));
//
wait for 200 milliseconds
if(BitRdPortI(PBDR,2)) break; //
if button up break
}
}
//
//
end of while(1)
end of costatement
// make LED agree with vswitch if vswitch has changed
(6)
(7) }
}
if( (PADRShadow & 1) == vswitch) {
BitWrPortI(PADR,&PADRShadow,!vswitch,0);
)
// end of while loop, go back to start
// end of main, never come here
The numbers in the left margin are reference indicators and are not a part of the code.
Load and run the program. Note that LED DS4 flashes once per second. Push button S1
several times and note how LED DS1 is toggled.
The flashing of LED DS4 is performed by the costatement starting at the line marked (2).
Costatements need to be executed regularly, often at least every 25 ms. To accomplish
this, the costatements are enclosed in a while loop. The term while loop is used as a handy
way to describe a style of real-time programming in which most operations are done in
one loop. The while loop starts at (1) and ends at (7). The function BigLoopTop() is
Getting Started Manual
27
相关PDF资料
101-0523 KIT DEV RABBIT3000/RCM3000
101-1109 KIT EMBEDDED PLC APPLICATION
101-1147 KIT RIO PROGRAM I/O
101-606 CONN SOCKET IDC 60POS W/KEY GOLD
10113616-01531LF CONN MOD JACK 8PORT 8/8 R/A PCB
10117863-5036010LF CONN MOD JACK 8/8 R/A PCB
10118061-5005010LF CONN MOD JACK 2PORT 8/8 R/A PCB
10118062-5001310LF CONN MOD JACK 4PORT 8/8 R/A PCB
相关代理商/技术参数
101-0359-000 制造商:ITT Interconnect Solutions 功能描述:1010359000 / 101-0359-000 / Circular
10103592 制造商:FCI-CONNECTOR 制造商全称:FCI connector 功能描述:MICRO-USB B-TYPE REVERSE
10103592-0001LF 功能描述:USB接头 5P Quick Connect Micro USB TypeB Plug RoHS:否 制造商:FCI 产品:USB Type A Connectors 标准:USB 3.0 端口数量: 位置/触点数量:9 型式:Female 电流额定值:1.8 A 安装风格:Through Hole 端接类型:Solder Pin 连接器类型:USB 3.0 Receptacle
10103593 制造商:FCI-CONNECTOR 制造商全称:FCI connector 功能描述:MICRO-USB B-TYPE MID-MOUNT
10103593-0001LF 功能描述:USB接头 5P Quick Connect Micro USB TypeB RCPT RoHS:否 制造商:FCI 产品:USB Type A Connectors 标准:USB 3.0 端口数量: 位置/触点数量:9 型式:Female 电流额定值:1.8 A 安装风格:Through Hole 端接类型:Solder Pin 连接器类型:USB 3.0 Receptacle
10103593-0001LF 制造商:FCI 功能描述:MICRO USB B, RECEPTACLE, 5POS, SMT RT AN
10103594 制造商:FCI-CONNECTOR 制造商全称:FCI connector 功能描述:MICRO-USB B-TYPE RECEP.
10103594-0001LF 功能描述:USB接头 5P Quick Connect Micro USB TypeB Rcpt RoHS:否 制造商:FCI 产品:USB Type A Connectors 标准:USB 3.0 端口数量: 位置/触点数量:9 型式:Female 电流额定值:1.8 A 安装风格:Through Hole 端接类型:Solder Pin 连接器类型:USB 3.0 Receptacle