Manne - There is a big problem that everyone runs into when trying to sense switches with an interrupt. It is called "switch bounce". It happens fairly slowly compared to the speed of the micro. You get MANY interrupts every time the switch opens or closes. There are several ways to deal with this. One is to "poll" (that is, read) the port pin regularly (maybe once every 1ms or so). Make a little "debounce" counter in software and a bit to remember the LAST state read. Every time you make a poll, compare the current state to the last state. If it is the same, count 1. If not the same, put the new state into the last-state bit. When the debounce counter reaches some convenient value (say 4 or 8), then the switch state is "stable" and you then do what ever else needs to be done (like increment your LED counter. Jim On Sat, 17 Feb 2007 00:37:04 +0100 (CET) "Manne Tallmarken" <mannet@kth.se> wrote: > Hi all, > I am trying to make my first assembler program that > handles interrupts. On > PB[6:0] I have som leds and on PA[7:6] i have two > buttons. The leds goes > on with a logic one from the port and the buttons is in > tri-state when not > pushed and goes to logic zero when pushed. > I just trying to get a binary counter to show up on the > leds when i am > pushing the buttons but nothing happens. > Does anyone know what could be wrong? > Regards, Manne > > Here is the code: > > .include "tn26def.inc" > > ; Interrupt service vectors > > .org $0000 > rjmp Reset > .org IOPINSaddr > rjmp IntPins > > ; define registers > .def TIME=r16 > .def TEMP=r17 > > ; define constants > .equ PORTB_IO=$7f ; pb[6:0] = output > .equ PORTA_IO=$00 ; pa[7:0] = input > > Reset: > ldi TEMP, RAMEND ; set stack pointer to > RAMEND > out SP, TEMP ; (SP is one byte on > attiny26) > > ldi TEMP, PORTB_IO > out DDRB, TEMP > ldi TEMP, $00 ; all lights off > out PORTB, TEMP > > ldi TEMP, PORTA_IO > out DDRA, TEMP > ldi TEMP, (1<<PA3) + (1<<PA6) + (1<<PA7) > ; enable > pullup resistors > out PORTA, TEMP > > > ; set up interrupts > > ldi TEMP, (1<<PCIE1) > out GIMSK, TEMP ; enable individual interrupt > PCIE1 ( PB[7:4], > PA[7:6], PA3 ) > ldi TIME, $00 ; start from 0 > > sei > > loop: > rjmp loop > > > IntPins: > inc TIME > out PORTB, TIME > reti > > --------------------------------------------------------------- The Think Different Store http://www.thinkdifferentstore.com/ For All Your Mac Gear ---------------------------------------------------------------
Message
Re: [AVR-Chat] Basic interrupts on ATtiny26
2007-02-17 by Jim Wagner
Attachments
- No local attachments were found for this message.