Microcontroller › 8051 › Understanding of Timer and Counter › Hello i wanted to write to
Hello i wanted to write answer your questions but i was not sure about the some things but now i am also with some code
Timers and counters uses the same registers. They operate different. Using keil with c if you do not stop timers/counters they will reaload themselves with the first values loaded on a overflow (Also applies for cleaing flags). Best way to understand is to try some simple codes with LED inputs outputs. Explaning them here will only give you superficial information therefore i am leaving you a timer0/timer, timer0/counter to try out
timer0/timer ***********************
Once you load the registers and start it will repeatedly reload itself whenever the interrupt ends. You can end it with TR0=0; somewhere in your code, this is the basic principle of how timers works.
timer0/counter********************
As counter you are using T0 pin as input and it count high to low edges of transmissions it does not count both high to low and low to high so one of your answer to your questions is here. You can implement the input with pullup resistor and with button enabled ground. This code will keep incrementing P2 port whenever it detects a high to low transmission on P0 port.
**************************
These are from 89s52. 89s52 also has extended timer2 but i have never used it/needed it before. It is a little bit different from other timers in 89s52. It is best to master timer0 and timer1 before moving on to extimer2 or you will have confussions. 89s52 is failry basic microcontroller to start on C51 architecture it has very few sfr and easy to use with enough ram and flash.