A few months ago, I was informed that my project team would be needing me to write some firmware for the PIC 16f877. Since I won't be taking my "Introduction to Microcontrollers" class until this summer, I began to teach myself about assembler, the chip and MPLAB. After running around in circles for quite awhile, I found a copy of Myke's book and finally started making some real progress. (THANKS MYKE!!!) Earlier this week, I finally felt comfortable enough to start writing some code. My team leader advised me to become very familiar with interrupts, so I decided to design an 8-bit binary counter, utilizing an interrupt routine. The algorithm is simple: All necessary registers are initialized The program waits in MAIN for TMR1 to overflow, setting TMR1IF The value in COUNTER is written to PORTC (which is connected to a bank of LEDs) The COUNTER is incremented and the whole thing starts again. I spent a few days stomping bugs using MPLAB SIM. Once I got everything working, I loaded my demo board and used MPLAB ICD to see it in action. I expected everything to work perfectly (silly me). However, I have observed three problems which only occur In ICD. 1. When I clear TRISC, bits <1:0> do not reset. 2. When I initialize TMR1H, TMR1L does not increment. This is pretty minor, but I want to understand why this is happening. 3. When the TMR1IF sets, the program does not go to the interrupt vector. It just stays in the Main loop indefinitely. These problems occur every time I load the program, and ONLY while stepping through the code in ICD; everything is still fine if I step through in SIM. Before I drive myself crazy trying to fix my code, I'm wondering if anyone has seen anything like this before. It occurs to me that I could have a bad chip, but I can't ask around for a new one until Monday. So what do you think? I'd appreciate any pointers, because this behavior seems really strange to me. Thanks, Wendy ;************************************************************* ;* cntrdemo.asm ;* A demonstration program for the PIC 16f877 ;* ;* ;* Wendy Olend ;* 24 April 2001 ;* ;************************************************************* list p=16f877 ;include files include"p16f877.inc" COUNTER equ 0x2d ;register declaration org 0x00 goto Initialize org 0x04 Interrupt movf COUNTER,w ;copy counter value and movwf PORTC ;send it to PORTC incf COUNTER,f ;increment counter bcf PIR1,0 ;reset TMR1IF movlw 0xf0 ;TEST ONLY movwf TMR1L ;TMR1 will count from 0000-FFFF movlw 0xff ;in actual execution movwf TMR1H retfie Initialize bsf STATUS,RP0 ;switch to bank1 bsf INTCON,7 ;EN GIE bsf INTCON,6 ;EN peripherial interrupts bsf PIE1,0 ;EN TMR1 interrupt clrf TRISC ;PORTC all outputs bcf STATUS,RP0 ;switch to bank0 clrf PORTC ;make sure PORTC is clear movlw b'00001101' ;TMR1 setup prescaler 1:1,osc EN, movwf T1CON ;internal clock, timer EN movlw 0xf0 ;TEST ONLY movwf TMR1L ;TMR1 will count from 0000-FFFF movlw 0xff ;in actual execution movwf TMR1H bcf PIR1,0 ;clr TMR1 overflow flag movlw 0x01 ;initialize counter movwf COUNTER Main goto Main ;wait for TMR1 to overflow ;then goto interrupt vector END -- http://www.piclist.com hint: PICList Posts must start with ONE topic: [PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads