Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

problem in counting pulse train by using timer0

Status
Not open for further replies.

asic1984

Full Member level 5
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
 

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?

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
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top