Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

rand and bits need to change wording

Status
Not open for further replies.

maria258

Member level 2
Joined
Feb 10, 2011
Messages
42
Helped
2
Reputation
4
Reaction score
2
Trophy points
1,288
Activity points
1,577
Dear members,
how can i convert this language to mplab so that he knows that i want this bit. i have this code and if someone wants to really help please private message me cos i cannot share this code online.

furthermore,i have this part and need to convert it to mplab. this is to shift the bits right:
int x[4] = {rand()>>9,rand()>>9,rand()>>9,rand()>>9};

thanks
maria
 
Last edited:

the array initialisation statement compiled OK with MPLAB and MCC18
Code:
#include <p18f4550.h>
#include <stdlib.h>

void main (void)
{
int x[4] = {rand()>>9,rand()>>9,rand()>>9,rand()>>9};  
}
you are initialising the array with four pseudo random values
however, you should initialise the random seed by calling srand() before rand()
 

i am using pic16f877a with the stdlib.h, even though srand is used before the error "pointer required" is coming up 4 times for every rand.
 

using HI-TECH C Compiler for PIC10/12/16 MCUs I don't get "pointer required" I get
Code:
Error   [188] C:\Test1 - Copy\test1.c; 17.22 constant expression required
indicating one can only initialise the array element with constants
you will have to initialise at run time, e.g.
Code:
#include <htc.h>
#include <stdlib.h>

void main (void)
{
  int i, x[4]={1,2,3,4};
  srand(100);
  for(i=0;i<4;i++)
    x[i]=rand()>>9;  
}
the initialise of the array is OK because I have used constants. I then use a loop to initialse with pseudo random values.
 

this is my bit of code:
#include <htc.h>
#include <stdlib.h>

__CONFIG (0x3F72);

#define LEDS PORTB
//#define GLCD_DATA PORTD
#define DI RE0
#define R_W RE1
#define E RE2
//#define RS RE3 //need to change the port

#define CS1 RC6
#define CS2 RC7

void main(void)
{
unsigned char t;
int px0,py0, px1, py1, px2, py2, px3, py3;
int dx0,dy0,dx1,dy1,dx2,dy2,dx3,dy3;
srand(3522);

int x[4] = {rand()>>9,rand()>>9,rand()>>9,rand()>>9};
and it continues on....

still the same error
 

this works for me
Code:
#include <htc.h>
#include <stdlib.h>

__CONFIG (0x3F72);

#define LEDS PORTB
//#define GLCD_DATA PORTD
#define DI RE0
#define R_W RE1
#define E RE2
//#define RS RE3 //need to change the port

#define CS1 RC6
#define CS2 RC7

void main(void)
{
unsigned char t;
int px0,py0, px1, py1, px2, py2, px3, py3;
int dx0,dy0,dx1,dy1,dx2,dy2,dx3,dy3;
srand(3522);

int i, x[4]={1,2,3,4};
  for(i=0;i<4;i++)
    x[i]=rand()>>9;  
}
 

ok, this worked for me for the moment. now ill implement its hex file to the graphic lcd.

Thanks
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top