Digi BL1800 user manual Int vswitch

Page 53

int vswitch;

// state of virtual

switch controlled by button

S1

 

 

 

 

main(){

// begin main program

 

 

// set up parallel port A as output

 

WrPortI(SPCR,NULL,0x84);

 

 

 

WrPortI(PADR,&PADRShadow,0xff);

//

turn off all LEDs

 

vswitch=0;

 

// initialize virtual switch off

(1)

while (1) {

 

//

Endless loop

 

BigLoopTop();

// Begin a big endless loop

 

// first task flash LED DS4 every second

for 200 milliseconds

(2)

costate {

 

//

begin a costatement

 

BitWrPortI(PADR,&PADRShadow,0,3);

//

LED DS4 on

(3)

waitfor(DelayMs(200));

//

light on for 200 ms

 

BitWrPortI(PADR,&PADRShadow,1,3);

//

LED DS4 off

 

waitfor(DelayMs(800));

//

light off for 800 ms

(4)

}

 

//

end of costatement

//second task - debounce switch #1 and toggle virtual switch vswitch

//check button 1 and toggle vswitch on or off

costate {

(5)if(BitRdPortI(PBDR,2)) abort; // if button not down skip out

waitfor(DelayMs(50));

//

wait 50 ms

 

if(BitRdPortI(PBDR,2)) abort;

//

if button not still down skip

out

 

 

 

vswitch=!vswitch; // toggle virtual switch- button

was down 50

ms

 

 

 

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)if( (PADRShadow & 1) == vswitch) { BitWrPortI(PADR,&PADRShadow,!vswitch,0);

 

)

(7) }

// 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

User’s Manual

49

Image 53
Contents Programmable Single-Board Computer Jackrabbit BL1800Digi International Inc TrademarksTable of Contents Index Schematics Introduction FeaturesDevelopment and Evaluation Tools Jackrabbit FeaturesOnline Documentation How to Use This ManualAdditional Product Information Emissions CE ComplianceImmunity Interfacing the Jackrabbit to Other Devices SafetyDesign Guidelines General Jackrabbit BL1800 Getting Started Development Kit ContentsDevelopment Hardware Connections Attach Jackrabbit to Prototyping Board BoardAssemble AC Adapter Connect Programming CableConnect Power Installing Dynamic C Run a Sample Program TroubleshootingTechnical Support Where Do I Go From Here?Real-Time Clock BL1800 SubsystemsHeaders Jackrabbit PinoutsDigital Inputs Digital Inputs/OutputsHV3 Sourcing Output Digital OutputsConfigurable High-Current Output Changing HV3 to a Sinking Output Bidirectional I/OA/D Converter Schematic Diagram of A/D ConverterJackrabbit BL1800 D/A Converters Schematic Diagram of D/A Converters1 DA1 V ⋅ 1 e RCTypical DA1 Voltages for Various Duty Cycles Typical DA0 Voltages for Various Duty Cycles 2 DA0User’s Manual 2 RS-485 Serial Communication1 RS-232 Ground recommended 485 R16 Programming PortUser’s Manual Programming Cable Changing Between Program Mode and Run ModeFlash Eprom MemorySram Clock Doubler Other HardwareExternal Interrupts Spectrum Spreader Jackrabbit BL1800 An Overview of Dynamic C Software ReferenceJackrabbit BL1800 Jackrabbit Sample Programs Sample ProgramsSample Program DEMOJR1.C DEMOJR1.CWatch Expression Break Point Single-SteppingWatching Variables Dynamically Summary of FeaturesEditing the Program User’s Manual Other Sample Programs Illustrating Digital I/O R/W pin and DB0-DB3 on 3 RS-232 Serial Communication Sample Programs 4 RS-485 Serial Communication Sample Program Cooperative Multitasking Int vswitch Advantages of Cooperative Multitasking 1 I/O Drivers Jackrabbit Function CallsVoid digOutint channel, int value Void anaOutint channel, int value Void anaInint channel, int *value Serial Communication Drivers Add-On Modules Upgrading Dynamic CPatches and Bug Fixes Appendix A. Specifications Figure A-1shows the mechanical dimensions for the Jackrabbit Electrical and Mechanical SpecificationsTable A-1. Jackrabbit Board Specifications Exclusion Zones Exclusion ZoneFigure A-3. User Board Footprint for Jackrabbit Figure A-4. Location of Jackrabbit Configurable Positions Jumper ConfigurationsTable A-2. Jackrabbit Jumper Configurations Conformally coated area Conformal CoatingJackrabbit Use of Rabbit 2000 Parallel PortsTable A-3. Jackrabbit Pinout Configurations PD0 PD1 Jackrabbit BL1800 Appendix B. Prototyping Board Prototyping Board Overview Jackrabbit Connectors User LEDs BuzzerPrototyping Board Features Top Side Mechanical Dimensions and LayoutTop Side Using the Prototyping BoardRelay Demonstration BoardExisting Top Side Prototyping BoardPE0 VCC HV0 SM1 SM0 HV2 Stat Jackrabbit BL1800 Power Supplies Appendix C. Power ManagementDcin Current mA 950 mA·h = 5.4 years 20 µA Batteries and External Battery ConnectionsFigure C-5shows the Jackrabbit battery backup circuitry Battery Backup CircuitReset Generator Power to Vram SwitchChip Select Circuit Figure C-7shows a schematic of the chip select circuitJackrabbit BL1800 SMODE0 SMODE1 IndexRABDB01.C RABDB02.C Schematics