8051 game project
Isn't the IP register addressable with an 8 bit number?PsySc0rpi0n
If you meant the IR register, yes it's 8 bit.
Isn't the IP register addressable with an 8 bit number?PsySc0rpi0n
If you meant the IR register, yes it's 8 bit.ExperimenterUK
I was talking about the interrupts priority register. Is it only bit addressable or 8 bit only?
You can set one bit or write 8 bits at once.
[ Edited Mon Dec 08 2014, 07:04 am ]
Another question:
Can the value at timer x be readed and stored into a variable? Meaning after starting T1 (TR1 = 0x01), for instance, read the value that is at T1 at a given moment?
[ Edited Mon Dec 08 2014, 05:55 pm ]
Yes You can read timer registers at any time.
unsigned char time; time = T1;
or
unsigned char time; time = THx;
or
unsigned char time time =TLx;
[ Edited Thu Dec 11 2014, 12:52 am ]
I'm trying to generate a sequence of 4 random numbers using srand (time (NULL)); and rand () % 4; but for some reason the generated numbers are always 2 and 3.
I think I can't use fopen, fread, fclose and FILE * in SDCC, can I?
unsigned int time; /* TH and TL combined makes a 16-bit value */ time = TH1; /* for timer 1 */ time = (time << 8) | TL1; /* makes it a 16-bit value */
I'm trying to generate a sequence of 4 random numbers using srand (time (NULL)); and rand () % 4; but for some reason the generated numbers are always 2 and 3.
PsySc0rpi0n
srand is not very efficient as I know. why are you doing a mod with 4?
I think I can't use fopen, fread, fclose and FILE * in SDCC, can I?
PsySc0rpi0n
You can but you need a storage media (like SD card or something) and Filesystem driver (FAT32/FAT16 etc.). These functions are not built into sdcc. you need external library.. check this out: http://www.8051projects.net/mmc-sd-interface-fat16/
If you want to read the complete timer register then best is this way:unsigned int time; /* TH and TL combined makes a 16-bit value */ time = TH1; /* for timer 1 */ time = (time << 8) | TL1; /* makes it a 16-bit value */I'm trying to generate a sequence of 4 random numbers using srand (time (NULL)); and rand () % 4; but for some reason the generated numbers are always 2 and 3.
PsySc0rpi0n
srand is not very efficient as I know. why are you doing a mod with 4?I think I can't use fopen, fread, fclose and FILE * in SDCC, can I?
PsySc0rpi0n
You can but you need a storage media (like SD card or something) and Filesystem driver (FAT32/FAT16 etc.). These functions are not built into sdcc. you need external library.. check this out: http://www.8051projects.net/mmc-sd-interface-fat16/ajay_bhargav
Ok, I'll try that way to read timer.
About the other question, alternatively to reading timers or using srand (time(NULL)) to generate random numbers, I was also thinking about to read '/dev/urandom' or even using 'clock()' inside srand () to get a better seed but I think SDCC doesn't recognise clock () or fread, fopen, fclose and FILE*.
Edited;
I'm using
to generate 4 numbers between 0 and 3, and according to the generated number, I'll launch the mine in 1of the 4 corners of the LCD.% 4
Meaning that I want to randomize the LCD address where the mines will be launched!
[ Edited Fri Dec 12 2014, 04:23 pm ]