Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Software polling of 8051

Status
Not open for further replies.

=CrAzYG33K=

New Member
I need my 8051 to take the values from some register every 5 seconds .. this has to be donew using polling right? What need I use?
Any insights?
 
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.
 
=CrAzYG33K= said:
I didn't get you fully mstechca, maybe attaching an *.a51 ASM file might be helpful to me

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.
 
mstechca said:
The difference between me and the rest of the microcontroller users on this site is that I directly program them through the parallel port.

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!.
 
Hi buddy,

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).
 
Nigel Goodwin said:
Have you ever prgorammed one yet?
Yes, I programmed the AT89C2051, and tested it with a simple HELLO program, and it worked nicely.

I thought (from your other posts) you haven't even managed to make a working target system?
You are talking about me receiving TV stations.

mostly because you wouldn't follow a working design!.

A working design? :lol:

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:
 
anyone ever hear of the theory of a monkey sitting down at a typewriter???

I guess the chances of that working are greater when all they have to press is 0's and 1's
 
mstechca said:
Nigel Goodwin said:
Have you ever prgorammed one yet?
Yes, I programmed the AT89C2051, and tested it with a simple HELLO program, and it worked nicely.

I'm glad you got it going! :D

I thought (from your other posts) you haven't even managed to make a working target system?
You are talking about me receiving TV stations.

No, about your 8051 target board, where you used the wrong chip to latch the address bus.
 
no compiler, no assembler, no knowledge - just puuuure creativity... Oh, and a parallel port.
 
=CrAzYG33K= said:
I need my 8051 to take the values from some register every 5 seconds .. this has to be donew using polling right? What need I use?
Any insights?
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.
 
hyedenny said:
no compiler
I make my own, so that I know it works 100%

no assembler
Its embedded in my compiler.

no knowledge
You can't say "no knowledge" when I can print the word HELLO on an LCD!

puuuure creativity
Let me tell you that creativity is one thing that can make you go far in this world.

Oh, and a parallel port.
What is wrong with using a parallel port?

What way are you programming the 8051?
Assembler, C compiler, ... I hope not machine code through the parallel port
I'm writing my own compiler/assembler package for the 8051, but for now, I'm using machine code!

I'm sorry, but I am not interested in buggy software or software requiring a buggy operating system. and "if you want it done right, do it yourself!"
 
mstechca said:
I'm writing my own compiler/assembler package for the 8051, but for now, I'm using machine code!

Funny how you implied above that you were already using your own compiler and assembler?, yet now you say you're still writing it?.

If you're writing a compiler, what language are you trying to use?.

I'm sorry, but I am not interested in buggy software or software requiring a buggy operating system. and "if you want it done right, do it yourself!"

Somehow that last sentence and mstechca just don't seem to make any sense :lol: :lol:

BTW, I have hand assembled 6502 machine code, back in my early days!, and entered it via a simple hex keypad and machine code monitor.
 
mstechca said:
I make my own, so that I know it works 100%
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... ...
 

Attachments

  • example_162.zip
    3 KB · Views: 307
Status
Not open for further replies.

Latest threads

Back
Top