In brief,All i want is to keep generating 10 numbers(integers) from 0
to 3...and build an array of those random numbers...the rest of my
game is very much done...although i'm using UART for interaction with
user....soon i'll try and interact using LCD display on board....which
i don't know how to do it btw :P Crying out loud for help!Jackie
Sir,Hardik Sir,Avinash Sir and friends...please help...also let me
know if i could come to powai office (or anywhere near to kharghar,new
bombay :P)
I had enrolled for embedded systems batch starting 11thJan 2010...
regards,
Sumeer Sinha
" In brief,All i want is to keep generating 10 numbers(integers) from
0 to 3... ".
What exactly d'u mean by this ? You want to generate 10 integers
between what range ?
Hope the timer thing works, and please get back to us if it works or
not.
Regards,
code:
#include <stdlib.h>
#include <string.h>
#include<avr/io.h>
#include<util/delay.h>
init_tim0(void)
{
TCNT0=0x00;
TCCR0=0x02;
}
int get_seed(void)
{
return (int)TCNT0;
}
void initrand(void)
{ int p;
p=get_seed();
srand(p);
}
int getrand(int range)
{
return (rand() % range);
}
void port_init(void)
{
DDRD=0x00;
PORTD=0xFF;
DDRC=0xFF;
PORTC=0xFF;
DDRE=0x00;
PORTE=0xFF;
}
int main(void)
{
port_init();
init_tim0();
initrand();
int p,q;
while(1)
{
p=getrand(4);
q=p;
switch (q)
{
case 0:
PORTC=0xFE;
_delay_ms(500);
PORTC=0xFF; _delay_ms(500);
break;
case 1:
PORTC=0xFD;
_delay_ms(500);
PORTC=0xFF; _delay_ms(500);break;
case 2:
PORTC=0xFB;
_delay_ms(500);
PORTC=0xFF; _delay_ms(500);break;
case 3:
PORTC=0xF7;
_delay_ms(500);
PORTC=0xFF; _delay_ms(500);break;
}
}
return 0;
}
There are some changes i did in the makefile as well to include
headers...just specified the path..
I hope i complete the project soon :)
Thanks for help!
cheers!