Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
8XC196Kx,8XC196Jx,87C196CA microcontroller family user's manual.1995.pdf
Скачиваний:
70
Добавлен:
23.08.2013
Размер:
3.97 Mб
Скачать

EVENT PROCESSOR ARRAY (EPA)

10.9 PROGRAMMING EXAMPLES FOR EPA CHANNELS

The three programming examples provided in this section demonstrate the use of the EPA channel for a compare event, for a capture event, and for generation of a PWM signal. The programs demonstrate the detection of events by a polling scheme, by interrupts, and by the PTS. All three examples were created using ApBUILDER, an interactive application program available through Intel Literature Fulfillment or the Intel Applications Bulletin Board system (BBS). See Chapter 1, “Guide to This Manual,” for information about ordering information from Intel Literature and downloading files from the BBS. These sample program were written in the C programming language. ASM versions are also available from ApBUILDER.

NOTE

The initialization file (80c196kr.h) used in these examples is available from the Intel Applications BBS.

10.9.1 EPA Compare Event Program

This example C program demonstrates an EPA compare event. It sets up EPA channel 0 to toggle its output pin whenever timer 1 is zero. This program uses no interrupts; a polling scheme detects the EPA event. The program initializes EPA channel 0 for a compare event.

#pragma model(KR) #include <80c196kr.h>

#define

COMPARE

0x40

#define

RE_ENABLE

0x08

#define

TOGGLE_PIN

0x30

#define

USE_TIMER1

0x00

#define

EPA0_INT_BIT

47

void init_epa0()

 

{

 

 

epa0_con

= COMPARE |

 

 

TOGGLE_PIN|

 

 

RE_ENABLE |

 

 

USE_TIMER1;

 

epa0_time = 0;

 

 

setbit(p1_reg, 0); /*

int reg */

 

clrbit(p1_dir, 0); /*

make output pin

*/

setbit(p1_mode, 0);/*

select EPA mode

*/

}

 

 

void init_timer1()

{

t1control = COUNT_ENABLE | COUNT_UP | CLOCK_INTERNAL | DIVIDE_BY_1;

}

10-33

8XC196Kx, Jx, CA USER’S MANUAL

void poll_epa0()

{

if(checkbit(int_pend, EPA0_INT_BIT))

{

/* User code for event channel 0 would go here. */

/* Since this event is absolute and re-enabled, no polling is neccessary.*/ clrbit(int_pend, EPA0_INT_BIT);

}

}

void main(void)

{

/* Initialize the timers before using the epa */ init_timer1();

init_epa0();

/* EPA events can be serviced by polling int_pend or epa_pend. */

while(1)

{

poll_epa0();

}

}

10.9.2 EPA Capture Event Program

This example C program demonstrates an EPA capture event. It sets up EPA channel 0 to capture edges (rising and falling) on the EPA0 pin. The program also shows how to set up the EPA interrupts. You can add your own code for the interrupt service routine.

#pragma model(KR) #include <80c196kr.h>

#define

COUNT_ENABLE

 

0x80

 

 

 

#define

COUNT_UP

 

0x40

 

 

 

#define

CLOCK_INTERNAL

 

0x00

 

 

 

#define DIVIDE_BY_1

 

0x00

 

 

 

#define

CAPTURE

 

0x00

 

 

 

#define

BOTH_EDGE

 

0x30

 

 

 

#define

USE_TIMER1

 

0x00

 

 

 

#define EPA0_INT_BIT

 

4

 

 

 

void init_epa0()

 

 

 

 

 

{

 

 

 

 

 

 

epa0_con = CAPTURE |

 

 

 

 

 

 

BOTH_EDGE |

 

 

 

 

 

USE_TIMER1;

 

 

 

 

setbit(p1_reg, 0);

/*

int reg

*/

 

setbit(p1_dir, 0);

/*

make input pin

*/

setbit(p1_mode, 0);

/*

select EPA mode

*/

setbit(int_mask, EPA0_INT_BIT);

/*

unmask EPA interrupts */

}

#pragma interrupt(epa0_interrupt=EPA0_INT_BIT) void epa0_interrupt()

{

unsigned int time_value;

10-34

EVENT PROCESSOR ARRAY (EPA)

time_value = epa0_time; /* must read to prevent overrun */

}

/* To generate have code for the epax interrupt,select the ICU design screen.*/ void init_timer1()

{

t1control = COUNT_ENABLE | COUNT_UP | CLOCK_INTERNAL | DIVIDE_BY_1;

}

void main(void)

{

unsigned int time_value;

/* Initialize the timers and interrupts before using the EPA */ init_timer1();

init_epa0();

 

 

enable();

/*

Globally enable interrupts */

while(1);

/*

loop forever, wait for interrupts to occur */

}

 

 

10.9.3 EPA PWM Output Program

This example C program demonstrates the generation of a PWM signal using the EPA’s PWM toggle mode (see “PWM Modes” on page 5-31) and shows how to service the interrupts with the PTS. The PWM signal in this example has a 50% duty cycle.

#pragma model(KR)

 

#include <80c196kr.h>

 

#define

PTS_BLOCK_BASE

0x98

/* Create

typedef template for the PWM_TOGGLE mode control block.*/

typedef struct PWM_toggle_ptscb_t {

 

unsigned char

unused;

 

unsigned char

ptscon;

 

void *pts_ptr;

 

unsigned int constant1; unsigned int constant2; } PWM_toggle_ptscb;

/* This locates the PTS block mode control block in register ram. This */ /* control block may be located at any quad-word boundary. */

register PWM_toggle_ptscb PWM_toggle_CB_3; #pragma locate(PWM_toggle_CB_3=PTS_BLOCK_BASE)

/* The PTS vector must contain the address of the PTS control block.*/ #pragma pts(PWM_toggle_CB_3=0x3)

10-35

8XC196Kx, Jx, CA USER’S MANUAL

/* Sample PTS control block initialization sequence.*/

void Init_PWM_toggle_PTS3(void)

 

 

{

 

 

 

disable();

/* disable all

interrupts */

disable_pts();

/* disable the

PTS interrupts */

PWM_toggle_CB_3.constant2

= 127;

 

PWM_toggle_CB_3.constant1

= 127;

 

PWM_toggle_CB_3.pts_ptr

= (void

*)&EPA0_TIME;

PWM_toggle_CB_3.ptscon

= 0x42;

 

/* Sample code that could be used to generate a PWM with an EPA channel.*/

setbit(p1_reg, 0x1);

/*

init output

*/

clrbit(p1_dir, 0x1);

/*

set to output

*/

setbit(p1_mode, 0x1); /*

set special function*/

setbit(ptssel, 0x3);

 

 

 

setbit(int_mask, 0x3)

 

 

 

}

 

 

 

void main(void)

 

 

 

{

 

 

 

Init_PWM_toggle_PTS3();

 

 

 

epa1_con = 0x78;

/* toggle, timer1, compare, re-enable */

epa1_timer = 127;

 

 

 

t1control = 0xC2;

/* enable timer, up 1 micrsecond @ 16 MHz */

enable_pts();

 

 

 

while(1);

}

10-36

11

Analog-to-digital

Converter

Соседние файлы в предмете Электротехника