i'm now trying to use Timer0 of 16f877a to overflow every 6.25ms. So this is how i calculate the TMR0 value. i'm using 4Mhz XTAL. and my prescaler is set to 1:256.
4Mhz/4= 1Mhz
1Mhz/256 = 3906.25hz
1/3906.25hz = 256us
6.25ms/256us=24.41
256 - 24.41 = 231.58
so i decided to use 232 as my TMR0 value. So am i correct?
in my program, i complement my LEDs everytime interrupt occur which mean every 6.25ms. But when i measure the period from my logic analyzer i found that the period time is not correct. SO i'm wonder maybe is my calculation problem or other .
Seems like my calculation is correct. The following is my picBasic code. Where am i go wrong? because the period of one logic high or logic low is wrong.
'DECLARE SYMBOLS
Symbol T0IF = INTCON.2 ' TMR0 Overflow Interrupt Flag
Symbol T0IE = INTCON.5 ' TMR0 Overflow Interrupt Enable
Symbol GIE = INTCON.7 ' Global Interrupt Enable
Symbol PS0 = OPTION_REG.0 ' Prescaler Rate Select
Symbol PS1 = OPTION_REG.1 ' Prescaler Rate Select
Symbol PS2 = OPTION_REG.2 ' Prescaler Rate Select
Symbol PSA = OPTION_REG.3 ' Prescaler Assignment
Symbol TOCS = OPTION_REG.5
symbol LED = PORTB
HI,
yeah~ the code u given works.i can get half period for 6.15ms. So what wrong with my part?
After i troubleshooting my code. i found that when i enable global interrupt, it wont work. but once i disable it. i cant get 6.20ms back for half period.
I'm afraid I'm not familiar with the compiler that you are using so can't really help. I suspect it is something to do with the interrupt code. Is there a forum for your compiler?
If you state which compiler it is then maybe someone else who is familiar with it might help.
As you state, the code is identical and so it must be the compiler that does something strange. I would check the manual especially the interrupt section.
With regard to the config line, the default is all ones and so,
LVP would be enabled - rb3 must be tied high.
WDT is enabled - it will reset every few mS.
Oscillator is RC - won't work with a crystal.
Actually, this could be the problem with your basic program. The watchdog timer could be reseting the processor.
hi pommie,
ic..really learn alot.thanks. i would like to ask something regard programming style. if i want to read data from a table using assembly. how am i gonna do?
.data 0x01, 0x02, 0x03
some sort like dis. i want to display the data 1 by 1 to the led. how is the coding idea?
but when i compile MPLAB doesnt show any error.haha..
thank you.
since 16f877a have an external interrupt for RB0. And it has and state change for RB7:RB4. so izzit mean that whenever there is either a low to high or vice versa state, it will set the flag bit? So after the flag is set, can i know which pin is being changed? because i'm planing to have two external interrupt button. but seems like we only have one RB0 ext interrupt pin.