CPSC 250

Fall 2006

Lab 4 InterruptService Routine

1.

  • Use the “CodeVisionAVR C compiler” hand out, implement the code in Fig.2-9 below to work with STK 500 starter kit.
  • In CodeVisionAVR, project/configure/c compiler, choose:ATMega8515L, otherwise you will get “chip signature error” message. Check the COM1,COM2 port in Setting/Programmer and Setting/Terminal.
  • Get familiar with the interrupt registers: GIMSK, MCUCR and interrupt service routine.
  • Get familiar with the STK 500 board. Note: LED connect to PORTA, switch will connect to PORTD (PD2,PD3, are associated with external interrupt ports- INT0, INT1) in this particular example.

2. Setup STK 500 starter kit

  • Setup the starter kit according to the instructions in the STK500 User Guide.

(ATmega8515L would be in the STK500 board, if not, make sure the power is off and insert theATmega8515L chip into the appropriate socket marked SCKT3000D3.)

  • Set the XTAL1 jumper. Also set the OSCSEL jumper between pins 1 and 2.
  • Connect one 10 pin ribbon cable between the PORTA and LEDS headers.This will allow displaying the state of ATMEGA8515L’s PORTA outputs.
  • Connect PORTD with the header marked “SWITCHES” using another 10-pin cable.
  • Connect one 6 pin ribbon cable between the ISP6PIN and SPROG3 headers.

This will allow CodeVisionAVR to automatically program the AVR chip after a

successful compilation.

  • Power up the STK500 starter kit and press the program button to start the automatic chip programming. After the programming process is complete, the code will start to execute in the target microcontroller on the STK500 starter kit.

3.

Suppose microcontroller is used to monitor whether you put on the seat belt or not. If people on your driver side or passenger side forgets to put it on, the LED should turn on. Design a C program to work with STK 500 start kit to implement this function.

Appendix:

Bit 7 / Bit 6 / Bit 5 / Bit 4 / Bit 3 / Bit 2 / Bit 1 / Bit 0
INT1 / INT0 / -- / -- / -- / -- / -- / --

mask bit for external interrupt 0

mask bit for external interrupt 1

Figure 2.8 GIMSK

#include <90s8535.h>

interrupt [EXT_INT0] void ext_int0_isr(void)

{

PORTA = PORTA ^ 0x1; //

}

void main(void)

{

DDRA=0x01; //

GIMSK=0x40; //

MCUCR=0x02; //

#asm("sei") //

while (1)

; //do nothing - the interrupt does it all

}

Figure 2.9 Interrupt Example Program

Bit 7 / Bit 6 / Bit 5 / Bit 4 / Bit 3 / Bit 2 / Bit 1 / Bit 0
ISC11 / ISC10 / ISC01 / ISC00

sense control bits for external interrupt 1

sense control bits for external interrupt 0

ISCx1 / ISCx0 / Interrupt function
0 / 0 / Interrupt x is triggered by a low level
0 / 1 / Reserved – do not use
1 / 0 / Interrupt x is triggered by a falling edge
1 / 1 / Interrupt x is triggered by a rising edge

Figure 2.11 MCUCR Interrupt Sense Control Bits

1