background image

14

Rabbit 2000 Development Kit

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 

used to collect some operations that are helpful to do once on every pass through the loop.  
Place the cursor on this function name 

BigLoopTop()

 and hit 

<ctrl-H>

 to learn more.

Содержание 2000

Страница 1: ...Rabbit 2000 Microprocessor Development Kit Getting Started 010118 D...

Страница 2: ...nst consequences resulting from system failure is the buyer s responsibility This device is not approved for life support or medical systems All Rabbit Semiconductor products are 100 percent functiona...

Страница 3: ...3 2 4 Watching Variables Dynamically 12 3 2 5 Summary of Features 12 3 3 Cooperative Multitasking 13 3 4 Advantages of Cooperative Multitasking 15 4 Software Reference 17 4 1 More About Dynamic C 17 4...

Страница 4: ...Rabbit 2000 Development Kit...

Страница 5: ...of the basics of operating a software program and editing files under Windows on a PC Knowledge of basic assembly language and architecture for controllers For a full treatment of C refer to the follo...

Страница 6: ...ng Board includes various accessories such as pushbutton switches LEDs and a beeper In addition you can add your own circuitry Programming cable This is a cable that is used to connect your PC serial...

Страница 7: ...yping Board that includes pushbutton switches LEDs and a beeper can be plugged into the Jackrabbit board By writing pro grams that run on the Jackrabbit board you can flash the LEDs beep the beeper an...

Страница 8: ...s whenever a break point is set in the program This can crash fast interrupt routines that are running while you stop at a breakpoint or single step the program Flash or RAM is selected on the Options...

Страница 9: ...4 Rabbit 2000 Development Kit...

Страница 10: ...ely 10 megabytes of free space on your hard disk The software can be installed on your C drive or any other convenient drive 2 2 Getting Hooked Up Figure 1 below shows an overview of how the serial an...

Страница 11: ...ND RXC TXC PC1 PC3 PC5 PC7 AGND DA1 PD1 PD3 PD5 PD7 GND 485 VCC SM1 STAT VBAT GND Z World Inc GND PA0 PA2 PA4 PA6 GND PB0 PB2 PB4 PB6 WDO GND PE6 PE4 PE2 PE0 HV0 HV2 K GND VCC PA1 PA3 PA5 PA7 GND PB1...

Страница 12: ...VIN positive voltage is the middle pin and GND is available on both ends of the three pin header J1 3 Plug in the wall transformer The Jackrabbit board and the Prototyping Board are ready to be used...

Страница 13: ...y the different COM ports in the OPTIONS menu until you find the one you are connected to If you can t get Dynamic C to recognize the target on any port then the hookup may be wrong or the COM port is...

Страница 14: ...sample programs are listed in Table 1 The first five sample programs provide a step by step introduction to the Jackrabbit board Additional sample programs illustrate more advanced topics Each sample...

Страница 15: ...evelopment Board should start flashing if everything went well If this doesn t work review the follow ing points The target should be ready which is indicated by the message BIOS successfully compiled...

Страница 16: ...to single step Each time the F8 key is pressed the cursor will advance one statement When you get to the for j 0 j statement it becomes impractical to single step further because you would have to pre...

Страница 17: ...ble to view variables while the program is running Use the F9 key to compile and run DEMOJR2 C Now type ctrl W to open the watch window and add the watch expression k to the top of the list of watch e...

Страница 18: ...on is evaluated as if it were in a separate function with no local variables 3 3 Cooperative Multitasking Cooperative multitasking is a convenient way to perform several different tasks at the same ti...

Страница 19: ...itfor 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 vswit...

Страница 20: ...bort state ment is illustrated at 5 If executed the internal statement pointer is set back to the first statement within the costatement and a jump to the closing brace of the costatement is made At 6...

Страница 21: ...16 Rabbit 2000 Development Kit...

Страница 22: ...le debugging is being done because it is more flexible than flash memory Dynamic C does not use include files rather it has libraries which are used for the same purpose that is to supply function pro...

Страница 23: ...t E bits 0 3 for digital output and starts up the pulse width modulation routines for the A D and D A channels Note that these routines can consume up to 20 of the CPU s processing power the routines...

Страница 24: ...oth D A channels are used A voltage is selected by giving a value from 0 to 1024 to the driver corresponding roughly to 0 1 V to 3 5 V on DA0 Because of the PWM interrupt frequency the PWM driver can...

Страница 25: ...y the driver and cause fluctuations in the voltage out puts Avoid using serial communications or printf statements during portions of your program where the voltage must remain steady Also be aware th...

Страница 26: ...only on the Jackrabbit An integer between 0 and 1024 will be returned in value corresponding to a voltage obtained if output channel DA0 was set to that value If a value is found but the voltage has...

Страница 27: ...llowing groups Open and Close Functions Non Cofunction Blocking Input Functions Non Cofunction Blocking Output Functions Single User Cofunction Input Functions Single User Cofunction Output Functions...

Страница 28: ...able Parameters None Return Value An integer with return character in the low byte No character is represented by a return of 1 int serXread void data int length unsigned long tmout Reads a block of c...

Страница 29: ...te Return Value 1 for success 0 if the character could not be written to the port int serXputs char s Calls serXwrite s strlen s Parameters s Null terminated character string source to write to the se...

Страница 30: ...ecution and only returns control to the following statement in its own costatement block when it completes Parameters data Destination data structure The user must ensure data is allocated for at leas...

Страница 31: ...Parameters c Character to write to the serial port Return Value None scofunc void cof_serXputs char s Writes a null terminated character string to the serial port yielding to other tasks when unsucces...

Страница 32: ...ze of 31 will be used and a compiler warn ing will be given When using cofunctions smaller buffer sizes can yield more frequently to other tasks but have the risk of a large input data stream overrunn...

Страница 33: ...becoming full int serXwrFree Calculates the free space in the serial port transmit buffer Parameters None Return Value The number of characters the serial port transmit buffer can accept before becom...

Страница 34: ...de A D input input range 0 V to 3 V 10 bit resolution 8 bit accuracy average acquisition time 150 ms 165 ms maximum with 14 7 MHz clock Analog Outputs Two filtered and buffered PWM outputs Digital Out...

Страница 35: ...30 Rabbit 2000 Development Kit...

Страница 36: ...Getting Started Manual Schematics...

Страница 37: ...B DRAWING CONTENT APPROVALS INITIAL RELEASE SIGNATURES 2900 SPAFFORD ST DAVIS CA 95616 530 757 4616 THIS DOCUMENT APPEND THE FOLLOWING DOCUMENTS WHEN CHANGING ECO APPROVAL APPROVAL CONTROL DOCUMENT DA...

Страница 38: ...B NONE B NONE...

Страница 39: ...B NONE B NONE...

Страница 40: ...B DRAWING CONTENT APPROVALS INITIAL RELEASE SIGNATURES 2900 SPAFFORD ST DAVIS CA 95616 530 757 4616 THIS DOCUMENT APPEND THE FOLLOWING DOCUMENTS WHEN CHANGING ECO APPROVAL APPROVAL CONTROL DOCUMENT DA...

Страница 41: ...B NONE B NONE...

Страница 42: ...ALS INITIAL RELEASE DRAWING CONTENT B 2900 SPAFFORD ST DAVIS CA 95616 ZWORLD DATE NONE 530 757 4616 THIS DOCUMENT APPEND THE FOLLOWING DOCUMENTS WHEN CHANGING ECO APPROVAL APPROVAL CONTROL DOCUMENT DA...

Страница 43: ......

Отзывы: