home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: sci.electronics
- Path: sparky!uunet!usc!sdd.hp.com!spool.mu.edu!uwm.edu!csd4.csd.uwm.edu!pegasus
- From: pegasus@csd4.csd.uwm.edu (David R Hucke)
- Subject: 8051 Interupt help needed
- Message-ID: <1992Sep11.031034.2048@uwm.edu>
- Originator: pegasus@csd4.csd.uwm.edu
- Sender: news@uwm.edu (USENET News System)
- Organization: Computing Services Division, University of Wisconsin - Milwaukee
- Date: Fri, 11 Sep 1992 03:10:34 GMT
- Lines: 69
-
- Hello everybody!
-
- Got another programming problem with my 8051.
-
- I am trying to get an LED to blink every second for 1 second using
- Timer 0. The program is supposed to Interupt driven.
-
- I have been able to write the program using a polling method.. I just
- am having trouble getting the Interupt driven program to work.
-
- I want the LED to change state once every second.. So, for my 8 Mhtz
- 8051, that would mean that about one second would elapse after
- Timer 0 has overflowed the FULL 16 bits 11 times.
-
- So, I have Timer 0 interupt enabled and wrote the interupt handler.
-
- The handler checks to see how many times the Interupt has been called. The
- value is stored in R3. Each time the interupt is called, R3 is incremented.
- If R3 = 11, then one second has passed, time to change the state of the
- LED. If R3 <> 11, just reti.
-
- THis is not working.... The LED blinks randomly for about 2 seconds, then
- turns off and stays off...
-
- Anybody have any ideas about what is going on here?
-
-
-
- =====
- seg data at 0
- REGISTERS: rb 8
-
- seg code
- anl 0x087, #11111011b ;;; Turn off watchdog timer.
-
- STROBE equ P0.0
-
-
- clr TR1 ;;; Stop Timer1
-
- mov TMOD, #00000001b ;;; Timer 0 in 16 bit mode
-
- setb EA
- setb ET0 ;;; Timer0 Interupt Enabled
-
- mov TH0, #0d ;;; Set High Byte of Timer Val
- mov TL0, #0d ;;; Set Low Byte of Timer Val
- ;;; Sets the Timer for full Time.
- ;;; ie. 256 - 256 = 0
-
- mov R3, #0d ;;; TimerInts = 0
- setb STROBE ;;; LED is off
-
- setb TR0 ;;; Start Timer0
- sjmp $ ;;; Loop until Interupt...
-
- org 0x0B ;;; Timer Interupt service routine.
- Service_Timer:
- inc R3
- cjne R3,#11d,Cont
- cpl STROBE
- mov R3, #0d
- reti
- Cont: reti
-
- --
- pegasus@csd4.csd.uwm.edu David R. Hucke
- UW-Milwaukee Film Major
- --
-