Feb 20, 2005 #1 asic1984 Full Member level 5 Joined Nov 15, 2003 Messages 257 Helped 4 Reputation 8 Reaction score 1 Trophy points 1,298 Activity points 2,340 timer0 in pic16f877? hi i tried to run a code in pic16f977 and simulate it ...but seems that the timer0 is not initialize well ......can u help me in finding the mistake? Code: PROCESSOR 16F877 #INCLUDE "P16F877.INC" ORG 0X00 GOTO START ORG 0X04 GOTO INT_HANDLER ORG 0X06 START BSF STATUS,5 MOVLW 0X00 MOVWF TRISB BCF STATUS,5 ;BANK 0 MOVLW 0XFF MOVWF PORTB ;PORTB INITIALLY 1`S MOVLW 0XA0 MOVWF INTCON ;ENABLE TIMER0 AND CLEAR THE FLAG OF THE TIMER movlw 0x00 movwf OPTION_REG LOOP GOTO LOOP INT_HANDLER MOVLW 0X00 MOVWF INTCON MOVFW PORTA XORLW 0XFF MOVWF PORTA MOVLW 0XA0 ;RENABLE INTERRUPTS RETFIE ;RETURN FROM INTERRUPT END thanks
timer0 in pic16f877? hi i tried to run a code in pic16f977 and simulate it ...but seems that the timer0 is not initialize well ......can u help me in finding the mistake? Code: PROCESSOR 16F877 #INCLUDE "P16F877.INC" ORG 0X00 GOTO START ORG 0X04 GOTO INT_HANDLER ORG 0X06 START BSF STATUS,5 MOVLW 0X00 MOVWF TRISB BCF STATUS,5 ;BANK 0 MOVLW 0XFF MOVWF PORTB ;PORTB INITIALLY 1`S MOVLW 0XA0 MOVWF INTCON ;ENABLE TIMER0 AND CLEAR THE FLAG OF THE TIMER movlw 0x00 movwf OPTION_REG LOOP GOTO LOOP INT_HANDLER MOVLW 0X00 MOVWF INTCON MOVFW PORTA XORLW 0XFF MOVWF PORTA MOVLW 0XA0 ;RENABLE INTERRUPTS RETFIE ;RETURN FROM INTERRUPT END thanks
Feb 20, 2005 #2 olemp Full Member level 1 Joined Jul 18, 2004 Messages 96 Helped 5 Reputation 10 Reaction score 3 Trophy points 1,288 Location turkiye Activity points 1,043 Re: timer0 in pic16f877? in your code: portb pull ups are enabled.. in "INT_HANDLER" you have used PORTA but you haven't initialized PORTA and there is no instruction like MOVFW PORTA (perhaps it may be equal to movf porta????)
Re: timer0 in pic16f877? in your code: portb pull ups are enabled.. in "INT_HANDLER" you have used PORTA but you haven't initialized PORTA and there is no instruction like MOVFW PORTA (perhaps it may be equal to movf porta????)
Feb 20, 2005 #3 asic1984 Full Member level 5 Joined Nov 15, 2003 Messages 257 Helped 4 Reputation 8 Reaction score 1 Trophy points 1,298 Activity points 2,340 Re: timer0 in pic16f877? hi will about movfw the mplab didnot say anything error about it but i changed it any way the mistake was in addressing as the option_reg is in bank1 not 0 about porta sorry for it i write this code in the first for porta and when the timer didnot work i changed to portb here is the code after the modifications: Code: PROCESSOR 16F877 #INCLUDE "P16F877.INC" ORG 0X00 GOTO START ORG 0X04 GOTO INT_HANDLER ORG 0X06 START BSF STATUS,5 MOVLW 0X00 MOVWF TRISB movlw 0x80 movwf OPTION_REG BCF STATUS,5 ;BANK 0 MOVLW 0XFF MOVWF PORTB ;PORTB INITIALLY 1`S movLW 0x00 MOVWF TMR0 MOVLW 0XA0 MOVWF INTCON ;ENABLE TIMER0 AND CLEAR THE FLAG OF THE TIMER LOOP GOTO LOOP INT_HANDLER bcf INTCON,2 MOVF PORTB,W XORLW 0XFF MOVWF PORTB RETFIE ;RETURN FROM INTERRUPT END thanks too mcuh for your help
Re: timer0 in pic16f877? hi will about movfw the mplab didnot say anything error about it but i changed it any way the mistake was in addressing as the option_reg is in bank1 not 0 about porta sorry for it i write this code in the first for porta and when the timer didnot work i changed to portb here is the code after the modifications: Code: PROCESSOR 16F877 #INCLUDE "P16F877.INC" ORG 0X00 GOTO START ORG 0X04 GOTO INT_HANDLER ORG 0X06 START BSF STATUS,5 MOVLW 0X00 MOVWF TRISB movlw 0x80 movwf OPTION_REG BCF STATUS,5 ;BANK 0 MOVLW 0XFF MOVWF PORTB ;PORTB INITIALLY 1`S movLW 0x00 MOVWF TMR0 MOVLW 0XA0 MOVWF INTCON ;ENABLE TIMER0 AND CLEAR THE FLAG OF THE TIMER LOOP GOTO LOOP INT_HANDLER bcf INTCON,2 MOVF PORTB,W XORLW 0XFF MOVWF PORTB RETFIE ;RETURN FROM INTERRUPT END thanks too mcuh for your help