Hi I have to use a 16 bit up/down counter...... I wrote the code for that in at89c51. The counting is made in external interrupt 0. The pulses are given by a linear scale. the count values are stored in mem location 50 and 51. The up counting or down counting is decided by the state of the 3.0 and 3.1 pins
counter: jnb p3.0,ru jnb p3.1,rd reti rd: push acc mov a,51h ;up counting add a,#01h jc bb sjmp aa bb: inc 50h aa: inc 51h pop acc reti ru: push acc ;down counting mov a,51h clr c subb a,#01h jc dd sjmp cc dd: dec 50h cc: dec 51h pop acc reti