Discussion in "Project Help" started by    PsySc0rpi0n    Nov 27, 2014.
Fri Dec 05 2014, 02:00 pm
#11
Isn't the IP register addressable with an 8 bit number?
Fri Dec 05 2014, 10:29 pm
#12


Isn't the IP register addressable with an 8 bit number?

PsySc0rpi0n


If you meant the IR register, yes it's 8 bit.
Sun Dec 07 2014, 07:51 am
#13



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?
Mon Dec 08 2014, 07:01 am
#14
The INTERRUPT PRIORITY (IP) register is bit addressable.

You can set one bit or write 8 bits at once.


[ Edited Mon Dec 08 2014, 07:04 am ]
Mon Dec 08 2014, 05:54 pm
#15
Ok, thanks.

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 ]
Wed Dec 10 2014, 10:14 am
#16
Just for knowledge: any SFR register in 8051 whos address is divisible by 8 is bit addressable
Yes You can read timer registers at any time.
Wed Dec 10 2014, 12:44 pm
#17
Could you help me on how to do that? Is it just:

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 ]
Thu Dec 11 2014, 05:01 am
#18
One more question...

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?
Fri Dec 12 2014, 10:30 am
#19
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/
Fri Dec 12 2014, 12:37 pm
#20


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

% 4

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.

Meaning that I want to randomize the LCD address where the mines will be launched!


[ Edited Fri Dec 12 2014, 04:23 pm ]

Get Social

Information

Powered by e107 Forum System

Downloads

Comments

Richardgar
Sat Apr 20 2024, 11:05 am
AntoniaRoons
Fri Apr 19 2024, 09:59 pm
carpinteyrowrl
Fri Apr 19 2024, 02:51 pm
DonaldJAX
Fri Apr 19 2024, 01:08 pm
Lewisuhakeply
Thu Apr 18 2024, 06:00 pm
Darrellciz
Thu Apr 18 2024, 11:07 am
Charlessber
Thu Apr 18 2024, 09:29 am
BartonSem
Thu Apr 18 2024, 04:56 am