You need two loops. The outer one is endless. The last statement in your code will be JMP 0x00 (jump to the beginning).
The next line will read the register you want. You should be able to do this with a MOV instruction.
The line after will increment the accumulator.
the next line will compare the accumulator with a value. If the accumulator doesn't reach the value, the code starts at 0x03 (the line after the mov instruction). It is 0x03 instead of 0x01 because a generic mov instruction takes 3 bytes.
If the accumulator matches the value, then the next line will send the accumulator back to 0.
The last line is the final JMP instruction.
When you run the code, something is read from a register, and an endless loop constantly increments the accumulator until it reaches a certain value. When it does, the accumulator returns to 0, and the code starts over.
now, this "value" I keep mentioning is special, because this value can determine how many increments are required before proceeding.
The easy way to figure out the value is to make the oscillator driving the microcontroller to seconds, and the value will be 5 times that, since you want to wait 5 seconds between each read.
Or use this equation: value = 5 / (oscillator time in seconds)
and to convert frequency to time, just use 1/x where x is either time or frequency.
The difference between me and the rest of the microcontroller users on this site is that I directly program them through the parallel port. Other users use software designed to accept code from a common language like C, and use compilers to create the proper hex file which is then downloaded into the microcontroller.
Here's code to show you what I am talking about. Let's assume you want the value at the P3.0 pin.
Code:
mov P3.0, R7 <-- Send the value of Register 7 to port 3.0.
inc A <-- Add 1 to accumulator (which is A)
cjne A, 5, 1 <-- Compare A to 5, and go to byte 1 (inc A) if A isn't 5.
mov A, 0 <-- Set A to 0, so counting can start over.
jmp 0 <-- Go back to the beginning and start again
Make your oscillator between 1 and 10Hz (yes, Hertz) for 5 second read intervals.
and I got another question. Why do you want to poll a register?
You can easily use your oscillator and set it to 0.2Hz (5 seconds), and check it's output pin. You don't need a microcontroller, if this is all you want one for.
Have you ever prgorammed one yet?, I thought (from your other posts) you haven't even managed to make a working target system? - mostly because you wouldn't follow a working design!.
I prefer writing an interrupt based program in this situation.
Use a timer. In the ISR you can do the work.
Polling will waste the processor time.
I use polling when i have to capture the signal applied to controller accurately. I have done it in my frequency meter( I used to poll for rising edges and calculate the time).
Let's say I want to make a modem using a homemade superregen and an 80C51 microprocessor and flash rom! Can you show me a working design? I bet the answer is no.
so basically there is no working design to follow. Maybe I'm just too creative :lol:
Personally I will do it this way:
Set up timer 0 for a delay of let say 10ms.
Write a timer 0 interrupt routine that increments an integer (2 RAM addresses called "intDelay") and check if it reaches 500 (500 * 10 ms = 5sec). You can use XRL function to check both registers of intDelay.
If it reaches 500 then
1) reset both registers of Delay to 0
2) get your value
3) return from interrupt
If it's still <500 then
1) return from interrupt
Remember to PUSH all registers used ACC, DPH, DPL, ... at the start of your interrupt routine to save them and restore POP them before you leave the interrupt routine.
What way are you programming the 8051?
Assembler, C compiler, ... I hope not machine code through the parallel port :?
I suggest you write different modules, 1 for you main program (initialize timer 0 once, do all the other stuff continously) and 1 for the timer interrupt routine (check 5 sec, ... ...) so you can keep things apart from each other.
What's the point in developping what already exist?
I can assure you the assembler compiler from Intel and C compiler from Keil I use works fine. So again why developping your own?
Anyway that doesn't solve =CrAzYG33K='s problem :cry:
Let me tell ya something. As soon as I am done it, I will show my programmer schematic, and upload the assembler/compiler, and then you can all tell me what ya think. :wink:
So =CrAzYG33K= if you're still here, this code solve your problem.
It consist of tree files: MainProg.txt with all the code to initialize the timer, LCD (used to check functionalities), endless loop, ... add you other code in this file Timer_0.txt with all the 10ms based actions. Add your polling code in this routine or call a routine written in MainProg.txt (like I do with Counter2LCD) Teksten.txt Used only to check the functionalities of the code.
Instead of polling a register like you want, I increment a 16 bit counter every 5 sec (adjustable with the variable DelayPreset).
With assembler "ASM51.EXE" and relocater "RL51.EXE" (both DOS programs from the late 80's) you can build a working binary file for an EPROM emulator.
No machine code, only readable, well documented, understandable assembler code :wink:
Have fun... ...