| ??? 03/07/02 09:29 Read: times |
#20542 - RE: Counters with the 8051 |
hi daire,
sorry i confused u with my assemble program! plz find below the program which worked properly for me with the comments! made some more modifications in ISS to suit exactly ur requirement! I am clearing the internal RAM first so i am using R0 as a pointer the i am writing #00H to all RAM locations! I am initialising only timer0 only! there r 3 steps involved, 1)kicking ON ur transmitter that is generating the square wave. 2)every time ur square wave toggles u r going to increment a 16bit counter which at last is going to give u how may square pulse has gone out! 3) when u receive ur signal then u have to stop the timer,so that u r stopping the generation of square wave!At this time if u read ur 16bit counter it will give u the square pulse went out! ;program with comments START1: .ORG 0000H LJMP 0050H ;start code execution from here INT1: .ORG 0013H RETI ;INTERRUPT SERVICE SUBROUTINE... TIM_INT0: .ORG 000BH LJMP 1000H ;TIMER Interrupt zero TIM_INT1: .ORG 001BH RETI ;TIMER Interrupt one (this is given since if a timer1 interrupt occurs without any actual tiggering then it should not cause the uC to run wild same for timer2 also; this is not timer initialisation) TIM_INT2: .ORG 002BH RETI ;TIMER Interrupt TWO CODE_BEGIN: .ORG 0050H INITIAL: MOV IE,#00H ;Disable interruptS ;the following code CLEARs INTERNAL RAM ;################################################ MOV R0,#FFH ;CLEAR INTERNAL RAM MOV A,#00H ; CLEAR_RAM: MOV @R0,A ; DJNZ R0,CLEAR_RAM ; ;################################################# ;TIMER0 INITIALISATION ;@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ CLR TR0 ;stop timer0 CLR TF0 ;clear timer0 ;(the frequency u want to generate (ie., 40Khz) depends on the value in value1 and value2 u select here. u have to calculate what value should be load if u want to generate 40Khz and divide it by 2 and load it here ) MOV TH0,#VALUE1 MOV TL0,#VALUE2 MOV TMOD,#11H ;TIMER0 MODE 1 SETB P1.0 ; LET ME ASSUME U R USING P1.0 FOR ;GENERATING SQUARE WAVE MOV IE,#82H SETB TR0 ;StART TIMER0 ;@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ ;count1 and count2 r the internal reg. which r going to contain how may square pulse u have transmitted.u have to declare this reg's MOV COUNT1,#00H ; MOV COUNT2,#00H ;(YOUR ANALOG INPUT will be CHECKed HERE continously in the main program ,I AM JUST ASSUMING IT TO BE BIT ADDRESSABLE) MAIN: CLR C MOV C,PORT_PIN ;USED APPROPRIATE LOGIC TO CHECK UR ANALOG PIN JC RXED ;( when i receive the signal in the analog input we will jump to RXED routine) JMP MAIN RXED: ;HOW MANY TIMES UR COUNTER HAS RUN or how may suare pulse u have transmitted WILL BE STORED IN COUNT1 AND COUNT2 REGs) CLR TR0 CLR TF0 JMP UR_ROUTINE UR_ROUTINE: ;Here if u read the count1 and count2 values it will give u the no. of square pulse send out. so that is the data u want to manipulate to determind the exact distance. ;TIMER0 ;This is the ISS for timer0 when .ORG 1000H CLR TR0 ;stopping timer0 CLR TF0 ;clearing timer0 CPL P1.0 ; TOGGLEING TO GET SQUARE WAVE clr c mov c,p1.0 jc out1 ;(checking for one pulse if yes then increment the 16 bit counter) mov a,count1 add a,#01h mov count1,a JNC OUT1 CLR C INC COUNT2 ;16 BIT COUNTING IS USED U SHALL MODIFY AS U REQUIRE OUT1: MOV TH0,VALUE1 MOV TL0,VALUE2 SETB TR0 RETI daire plz cut and paste the program in notepad then go through it! i Want some more clarification daire, 1)Have u sucessfully generated the 40Khz square pulse using timer??? 2)I have implemented the project through a USD kit so i don't have to bother about the rxed signal! i will get a pulse when i rx the reflected signal so i will stop my counter then! now in ur case what is mean by this analog input?? Is it an ADC input ??? since i worked only with 80c52 i dont have idea about ADuC812 any way i am trying to get its datasheets! 3) this distance measurement is a part of ur project or this itself u have taken as a project?? keep me informed about ur progress and troubles if u face any! u shall mail me to danaraja_b@btlpkd.com All the best! rgds, dana |
| Topic | Author | Date |
| Counters with the 8051 | 01/01/70 00:00 | |
| RE: Counters with the 8051 | 01/01/70 00:00 | |
| RE: Counters with the 8051 | 01/01/70 00:00 | |
| SMALL CORRECTION | 01/01/70 00:00 | |
| SMALL CORRECTION ON ISS | 01/01/70 00:00 | |
| RE: SMALL CORRECTION ON ISS | 01/01/70 00:00 | |
| RE: Counters with the 8051 | 01/01/70 00:00 | |
RE: Counters with the 8051 | 01/01/70 00:00 |



