8051 game project
As far as I understand, if I use a 11.0592Mhz crystal, my MCU (DS89C450) can count up to 11059200/12 = 921600 times per second (a machine cycle consists in 12 crystal pulses).
For example, 50000 timer increments will, theoretically, take 0.0542 S.
This comes from 50000/921600 = 0.0542
So, if I want to count 0.1 seconds I'll do:
x/921600 = 0.1 <=> x = 92160
So, this is the amount of times my timer has to increment.
So I configure my timer in 16 bit mode.
Then I do the following math:
92160/65535 = 1.41
So, I need 1.41 overflows to match up the 92160.
I do this by taking 1 complete overflow and then count the remaining time but in reverse order, like:
92160-65535 = 26625 - This is the remaining value after 1 overflow.
65535-26625=38910 - This is the initial value that my timer will have first. So I load my timer with 38910, then I start the timer and it will count from 38910 up to 65535. This will count the remaining from 65536 up to 92160. Then I let the timer to count from 0 up to 65535. At the end the timer has counted the 92160.
This should give me a real time simulation time of 100mS but my IDE only shows me 26mS
Am I doing anything wrong?
[ Edited Wed Feb 11 2015, 04:46 pm ]
try to redo your calculation now.
Well.. DS89C450 is a single clock cycle MCU unlike traditional 12clock cycle operation of 8051. So your first calculation itself is wrong: 11059200/12 = 921600 should be: 11059200/1 = 11059200
try to redo your calculation now.ajay_bhargav
Where can I find that info?
Can I trust the simulator IDE real time simulation info to check my calcs?
Can I trust the simulator IDE real time simulation info to check my calcs?PsySc0rpi0n
Not really
You can't always be sure what settings the simulator is using.
Your figures look about right, although not the method I'd choose.
According to the data sheet there are several settings that
affect the clock speed being fed to the timer,
so double check those.
Does your compiler set up any clock sources ?
As for your LCD problem, you need extra long delays during
initialization, where the "Busy" bit does not work.
These delays are of the order of 10s of ms
Do you have the source code for the ASM program that does work?
I'm using SDCC but I'm not an expert and I can't tell you (because I don't know) if my compiler sets up any clock sources...
I have the ASM code that works. It's here:
IDEONE
I didn't posted it all here because somehow the code wouldn't be indented correctly. It would stay centred I don't know why!
[ Edited Fri Feb 13 2015, 06:05 am ]
Also try to use for loops for delay so you dont have to worry about setting right value for timer. You can change the count anytime and see if things work in C.
FEATURES
 High-Speed 8051 Architecture
One Clock-Per-Machine Cycle
DC to 33MHz Operation
Single Cycle Instruction in 30ns
Optional Variable Length MOVX to Access
Fast/Slow Peripherals
Dual Data Pointers with Automatic
Increment/Decrement and Toggle Select
Supports Four Paged Memory-Access Modes
[ Edited Fri Feb 13 2015, 09:42 pm ]
Now I have another challenge going on... I can work with port P1 and LCD but I can't work with port P0 and LED's or LCD. I just can't make this port go "high" (+5Vcc) and I can't figure out why.
I'm using 8 resistors of 4K7 ohms connected to the 8 LEDs and each one connected to each MCU P0 pin, like:
P0_0--->+LED--->-LED--->4K7R--->GND
Any thoughts?
Now I have another challenge going on... I can work with port P1 and LCD but I can't work with port P0 and LED's or LCD.
I just can't make this port go "high" (+5Vcc)PsySc0rpi0n
That's an easy one
Port 0 is open drain, that is, it can sink current but not
supply it.
To get a high output you will need pull up resistors.
Check the data sheet to see what the other ports can do
it varies between types.
The usual way to drive LEDs on P0 is ...
+5 --- 1k --- +LED- ---P0_0
Pin low gives LED on.
4K7 will be very dim.
Now I'm trying to draw a simple round ball using 4 custom chars to draw later a smile from this ball but using the code attached, I'm not getting what I expected...
Can you help and try to see what's wrong in the code?
Edited;
Ok, I got it... Missing parenthesis when calling init_LCD () function in main ()... But the compiler didn't even complained!
[ Edited Tue Feb 17 2015, 12:39 am ]