CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

16F876 random number

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
shhn



Joined: 14 Jun 2010
Posts: 4

View user's profile Send private message

16F876 random number
PostPosted: Mon Jun 14, 2010 8:38 am     Reply with quote

i want to generate random number from 16f876 every 1 seconds and i want to read rs232 this numbers. how can i write this code? please help
mkuang



Joined: 14 Dec 2007
Posts: 257

View user's profile Send private message Send e-mail

PostPosted: Mon Jun 14, 2010 8:41 am     Reply with quote

When is your homework assignment due?
shhn



Joined: 14 Jun 2010
Posts: 4

View user's profile Send private message

PostPosted: Mon Jun 14, 2010 8:48 am     Reply with quote

no i m not student, only I m interested pic and I want to develop some projects with pic
also i now c and cpp but in this issue i have is missing
mkuang



Joined: 14 Dec 2007
Posts: 257

View user's profile Send private message Send e-mail

PostPosted: Mon Jun 14, 2010 9:10 am     Reply with quote

You can try this:

Code:

#include <16F876.h>
#include <math.h>
#use delay(clock=8000000)
#fuses INTRC,NOWDT,PUT,NOBROWNOUT,NOLVP
#use rs232(baud=9600,xmit=PIN_C6,rcv=PIN_C7,ERRORS)

void main() {
   int8 random_number;
   while{1}
   {
    random_number = (int8)(10*randn()); //generate a random number between zero and 10
     printf("\n\rThis is a random nymber: %u", random_number);
     delayh_ms(1000); //prints every 10 seconds
   }
}
THis uses the internal oscillator at 8Mhz. Make sure you have a MAX232 or equivalent RS232 chip connected via hardware UART pins of the PIC (C6 and C7).

Look at this thread to see how to hook up the hardware.

http://www.ccsinfo.com/forum/viewtopic.php?t=42784
shhn



Joined: 14 Jun 2010
Posts: 4

View user's profile Send private message

PostPosted: Mon Jun 14, 2010 11:45 am     Reply with quote

Thanks for your reply.
I compiled your code and put in pic, now, I want to test pic. How to generate random number? How can I do this?
mkuang



Joined: 14 Dec 2007
Posts: 257

View user's profile Send private message Send e-mail

PostPosted: Mon Jun 14, 2010 11:48 am     Reply with quote

What kind of hardware do you have? IF you want to display something on a PC (like on hyperterminal) you need to make a serial cable. You will need something similar to the schematic I linked to in my previous post.
Humberto



Joined: 08 Sep 2003
Posts: 1215
Location: Buenos Aires, La Reina del Plata

View user's profile Send private message

PostPosted: Mon Jun 14, 2010 11:55 am     Reply with quote

There is a built in function that can generate random numbers, it use stdlib.h where you can define
the maximum number (RAND_MAX) to generate.


Humberto
shhn



Joined: 14 Jun 2010
Posts: 4

View user's profile Send private message

PostPosted: Mon Jun 14, 2010 12:03 pm     Reply with quote

mkuang wrote:
What kind of hardware do you have? IF you want to display something on a PC (like on hyperterminal) you need to make a serial cable. You will need something similar to the schematic I linked to in my previous post.

i have this USB PIC Programmer (D149BC). i connect it with usb cable.

mkuang



Joined: 14 Dec 2007
Posts: 257

View user's profile Send private message Send e-mail

PostPosted: Mon Jun 14, 2010 12:41 pm     Reply with quote

The silver connector on the lower left corner is an ethernet connector right? And you connect that to the programmer?

What programmer do you have?
SherpaDoug



Joined: 07 Sep 2003
Posts: 1640
Location: Cape Cod Mass USA

View user's profile Send private message

PostPosted: Mon Jun 14, 2010 1:43 pm     Reply with quote

mkuang wrote:
The silver connector on the lower left corner is an ethernet connector right? And you connect that to the programmer?

What programmer do you have?


It looks like USB to me. I think this IS his programmer. What I would want is a schematic of the PIC target, the board that the PIC runs on.
_________________
The search for better is endless. Instead simply find very good and get the job done.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group