home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #20 / NN_1992_20.iso / spool / sci / electron / 15482 < prev    next >
Encoding:
Text File  |  1992-09-10  |  2.3 KB  |  81 lines

  1. Newsgroups: sci.electronics
  2. Path: sparky!uunet!usc!sdd.hp.com!spool.mu.edu!uwm.edu!csd4.csd.uwm.edu!pegasus
  3. From: pegasus@csd4.csd.uwm.edu (David R Hucke)
  4. Subject: 8051 Interupt help needed
  5. Message-ID: <1992Sep11.031034.2048@uwm.edu>
  6. Originator: pegasus@csd4.csd.uwm.edu
  7. Sender: news@uwm.edu (USENET News System)
  8. Organization: Computing Services Division, University of Wisconsin - Milwaukee
  9. Date: Fri, 11 Sep 1992 03:10:34 GMT
  10. Lines: 69
  11.  
  12. Hello everybody!
  13.  
  14. Got another programming problem with my 8051.
  15.  
  16. I am trying to get an LED to blink every second for 1 second using
  17. Timer 0.  The program is supposed to Interupt driven.
  18.  
  19. I have been able to write the program using a polling method..  I just
  20. am having trouble getting the Interupt driven program to work.
  21.  
  22. I want the LED to change state once every second..  So, for my 8 Mhtz
  23. 8051, that would mean that about one second would elapse after
  24. Timer 0 has overflowed the FULL 16 bits 11 times.
  25.  
  26. So,  I have Timer 0 interupt enabled and wrote the interupt handler.
  27.  
  28. The handler checks to see how many times the Interupt has been called.  The
  29. value is stored in R3.  Each time the interupt is called, R3 is incremented.
  30. If R3 = 11, then one second has passed, time to change the state of the
  31. LED.  If R3 <> 11, just reti.
  32.  
  33. THis is not working....  The LED blinks randomly for about 2 seconds, then
  34. turns off and stays off...  
  35.  
  36. Anybody have any ideas about what is going on here?
  37.  
  38.  
  39.  
  40. =====
  41. seg data at 0
  42. REGISTERS: rb 8
  43.  
  44. seg code 
  45. anl 0x087, #11111011b         ;;; Turn off watchdog timer.
  46.  
  47. STROBE      equ  P0.0
  48.  
  49.  
  50. clr TR1             ;;;  Stop Timer1
  51.  
  52. mov TMOD, #00000001b ;;;  Timer 0 in 16 bit mode
  53.  
  54. setb EA
  55. setb ET0             ;;;  Timer0 Interupt Enabled
  56.  
  57. mov TH0, #0d         ;;;  Set High Byte of Timer Val
  58. mov TL0, #0d         ;;;  Set Low Byte of Timer Val
  59.              ;;;  Sets the Timer for full Time.
  60.                      ;;;  ie.   256 - 256 = 0
  61.  
  62. mov R3, #0d          ;;;  TimerInts = 0
  63. setb STROBE          ;;;  LED is off
  64.  
  65. setb TR0             ;;;  Start Timer0
  66. sjmp $               ;;;  Loop until Interupt...
  67.  
  68. org 0x0B             ;;; Timer Interupt service routine.
  69. Service_Timer:
  70.    inc R3   
  71.    cjne R3,#11d,Cont   
  72.    cpl STROBE
  73.    mov R3, #0d
  74.    reti
  75.    Cont:  reti 
  76.  
  77. -- 
  78. pegasus@csd4.csd.uwm.edu                David R. Hucke
  79.                                         UW-Milwaukee Film Major
  80. --
  81.