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.

random number gernerator using pic 16 f877

Status
Not open for further replies.

hum20005

Newbie level 4
Joined
Oct 29, 2010
Messages
5
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,384
hi every 1,
plz help me to write a complete pic program, i have spent two month to write the pic program but couldn't get any luck. i have to submit my project in February but i didn't even start yet therefore plz help me to write a complete program. i have very basic experience in assembly language programming.


well i have been given a project to build a random number generator using pic 16F877 and display the result on lcd display. random number have to be between 0 and 27.

once the number is randomly select in the range then i have to use an external braille key pad to enter the right combination and produce the same matching number on lcd display.

my project is based on two external braille key pad. actually the project is called braille formation game. where a pic have to generate a random number with a push button and display it on lcd. then two player have to use the external braille pad and match that random number by entering the right combination of the braille dots. so whoever produce the right combination first will be a winner.


thank you so much.
hum
 

I think you have to post your part of the code before anyone will give you a help.Simply asking for the whole code, is asking us to do your work!
 

john is correct. have u at least able to interface the lcd with the pic correctly? have u able to display characters correctly on the lcd? maybe from there u can discuss the programming methods needed to generate random numbers in the range of 0 to 27.
 

My advice is write a small bit of code first and test it. Then add to the code to build it towards the final functionality. Don't try to write it all in one go to start with.

For random number, a fast, free running counter which is stopped by someone pressing a button would do.

Keith
 

hi thank you every1. here i have added some lcd program which i have learn from a book. lcd accept 4 bit data at a time.

this part is only for lcd to display character and turn lcd on. what i need to do, is to add more program to generate random number between 0 to 27 and display it on screen.

plz help

i'm doing my best to get it working.

thank u very much for you replies.




;ANHEAD877.ASM Header for the alpha numeric display csing 6 I/0

TMR0 EQU 1 ;means TMR0 is file 1.
STATUS EQU 3 ;means STATUS is file 3.
PORTA EQU 5 ;means PORTA is file 5.
PORTB EQU 6 ;means PORTB is file 6.
PORTC EQU 7 ;means PORTB is file 7.
PORTD EQU 8 ;means PORTB is file 8.
TRISA EQU 85H ;TRISA (the PORTA I/O selection) is file 85H
TRISB EQU 86H ;TRISB (the PORTB I/O selection) is file 86H
TRISC EQU 87H ;TRISC (the PORTC I/O selection) is file 87H
TRISD EQU 88H ;TRISD (the PORTD I/O selection) is file 88H
OPTION EQU 81H ;the OPTION register is file 81H
ZEROBIT EQU 2 ;means ZEROBIT is bit 2.
COUNT EQU 0CH ;COUNT is file 0C, a register to count events.

;****************************************************************************

LIST P=16F877 ;we are using the 16F877.
ORG 0 ;the start address in memory is 0
GOTO START ;goto start!

;****************************************************************************

; Configuration Bits

_CONFIG H'3FF0' ;selects LP oscillator, WDT off, PUT on,
;Code Protection disabled.


;****************************************************************************

; SUBROUTINE SECTION.

;3 SECOND DELAY
DELAY3 CLRF TMR0 ;Start TMR0
LOOPA MOVF TMR0.W ;Read TMR0 into W
SUBLW .96 ;TIME - W
BTFSS STATUS,ZEROBIT ;Check TIME-W = 0
GOTO LOOPA
RETLW 0 ;return after TMRO = 96


;P1 SECOND DELAY
DELAP1 CLRF TMR0 ;Start TMR0
LOOPC MOVF TMR0.W ;Read TMR0 into W
SUBLW .3 ;TIME - W
BTFSS STATUS,ZEROBIT ;Check TIME-W = 0
GOTO LOOPC
RETLW 0 ;return after TMRO = 3

CLOCK BSF PORTA,2
NOP
BCF PORTA,2
NOP
RETLW 0

;***************************************************************************

A MOVLW 2 ;enables the display
MOVWF PORTA
MOVLW 4H
MOVWF PORTB
CALL CLOCK
MOVWF 1H
MOVWF PORTB
CALL CLOCK
RETLW 0

BB MOVLW 2 ;enables the display
MOVWF PORTA
MOVLW 4H
MOVWF PORTB
CALL CLOCK
MOVWF 2H
MOVWF PORTB
CALL CLOCK
RETLW 0

C MOVLW 2 ;enables the display
MOVWF PORTA
MOVLW 4H
MOVWF PORTB
CALL CLOCK
MOVWF 3H
MOVWF PORTB
CALL CLOCK
RETLW 0

D MOVLW 2 ;enables the display
MOVWF PORTA
MOVLW 4H
MOVWF PORTB
CALL CLOCK
MOVWF 4H
MOVWF PORTB
CALL CLOCK
RETLW 0

E MOVLW 2 ;enables the display
MOVWF PORTA
MOVLW 4H
MOVWF PORTB
CALL CLOCK
MOVWF 5H
MOVWF PORTB
CALL CLOCK
RETLW 0

F MOVLW 2 ;enables the display
MOVWF PORTA
MOVLW 4H
MOVWF PORTB
CALL CLOCK
MOVWF 6H
MOVWF PORTB
CALL CLOCK
RETLW 0

G MOVLW 2 ;enables the display
MOVWF PORTA
MOVLW 4H
MOVWF PORTB
CALL CLOCK
MOVWF 7H
MOVWF PORTB
CALL CLOCK
RETLW 0

H MOVLW 2 ;enables the display
MOVWF PORTA
MOVLW 4H
MOVWF PORTB
CALL CLOCK
MOVWF 8H
MOVWF PORTB
CALL CLOCK
RETLW 0

I MOVLW 2 ;enables the display
MOVWF PORTA
MOVLW 4H
MOVWF PORTB
CALL CLOCK
MOVWF 9H
MOVWF PORTB
CALL CLOCK
RETLW 0

J MOVLW 2 ;enables the display
MOVWF PORTA
MOVLW 4H
MOVWF PORTB
CALL CLOCK
MOVWF 0AH
MOVWF PORTB
CALL CLOCK
RETLW 0

K MOVLW 2 ;enables the display
MOVWF PORTA
MOVLW 4H
MOVWF PORTB
CALL CLOCK
MOVWF 0BH
MOVWF PORTB
CALL CLOCK
RETLW 0

L MOVLW 2 ;enables the display
MOVWF PORTA
MOVLW 4H
MOVWF PORTB
CALL CLOCK
MOVWF 0CH
MOVWF PORTB
CALL CLOCK
RETLW 0

M MOVLW 2 ;enables the display
MOVWF PORTA
MOVLW 4H
MOVWF PORTB
CALL CLOCK
MOVWF 0DH
MOVWF PORTB
CALL CLOCK
RETLW 0

N MOVLW 2 ;enables the display
MOVWF PORTA
MOVLW 4H
MOVWF PORTB
CALL CLOCK
MOVWF 0EH
MOVWF PORTB
CALL CLOCK
RETLW 0

O MOVLW 2 ;enables the display
MOVWF PORTA
MOVLW 4H
MOVWF PORTB
CALL CLOCK
MOVWF 0FH
MOVWF PORTB
CALL CLOCK
RETLW 0

P MOVLW 2 ;enables the display
MOVWF PORTA
MOVLW 4H
MOVWF PORTB
CALL CLOCK
MOVWF 0H
MOVWF PORTB
CALL CLOCK
RETLW 0

Q MOVLW 2 ;enables the display
MOVWF PORTA
MOVLW 5H
MOVWF PORTB
CALL CLOCK
MOVWF 1H
MOVWF PORTB
CALL CLOCK
RETLW 0

R MOVLW 2 ;enables the display
MOVWF PORTA
MOVLW 5H
MOVWF PORTB
CALL CLOCK
MOVWF 2H
MOVWF PORTB
CALL CLOCK
RETLW 0

S MOVLW 2 ;enables the display
MOVWF PORTA
MOVLW 5H
MOVWF PORTB
CALL CLOCK
MOVWF 3H
MOVWF PORTB
CALL CLOCK
RETLW 0

T MOVLW 2 ;enables the display
MOVWF PORTA
MOVLW 5H
MOVWF PORTB
CALL CLOCK
MOVWF 4H
MOVWF PORTB
CALL CLOCK
RETLW 0

U MOVLW 2 ;enables the display
MOVWF PORTA
MOVLW 5H
MOVWF PORTB
CALL CLOCK
MOVWF 5H
MOVWF PORTB
CALL CLOCK
RETLW 0

V MOVLW 2 ;enables the display
MOVWF PORTA
MOVLW 5H
MOVWF PORTB
CALL CLOCK
MOVWF 6H
MOVWF PORTB
CALL CLOCK
RETLW 0

WW MOVLW 2 ;enables the display
MOVWF PORTA
MOVLW 5H
MOVWF PORTB
CALL CLOCK
MOVWF 7H
MOVWF PORTB
CALL CLOCK
RETLW 0

X MOVLW 2 ;enables the display
MOVWF PORTA
MOVLW 5H
MOVWF PORTB
CALL CLOCK
MOVWF 8H
MOVWF PORTB
CALL CLOCK
RETLW 0

Y MOVLW 2 ;enables the display
MOVWF PORTA
MOVLW 5H
MOVWF PORTB
CALL CLOCK
MOVWF 9H
MOVWF PORTB
CALL CLOCK
RETLW 0

Z MOVLW 2 ;enables the display
MOVWF PORTA
MOVLW 5H
MOVWF PORTB
CALL CLOCK
MOVWF 0AH
MOVWF PORTB
CALL CLOCK
RETLW 0

NUM0 MOVLW 2 ;enables the display
MOVWF PORTA
MOVLW 3H
MOVWF PORTB
CALL CLOCK
MOVWF 0H
MOVWF PORTB
CALL CLOCK
RETLW 0

NUM1 MOVLW 2 ;enables the display
MOVWF PORTA
MOVLW 3H
MOVWF PORTB
CALL CLOCK
MOVWF 1H
MOVWF PORTB
CALL CLOCK
RETLW 0

NUM2 MOVLW 2 ;enables the display
MOVWF PORTA
MOVLW 3H
MOVWF PORTB
CALL CLOCK
MOVWF 2H
MOVWF PORTB
CALL CLOCK
RETLW 0

NUM3 MOVLW 2 ;enables the display
MOVWF PORTA
MOVLW 3H
MOVWF PORTB
CALL CLOCK
MOVWF 3H
MOVWF PORTB
CALL CLOCK
RETLW 0

NUM4 MOVLW 2 ;enables the display
MOVWF PORTA
MOVLW 3H
MOVWF PORTB
CALL CLOCK
MOVWF 4H
MOVWF PORTB
CALL CLOCK
RETLW 0

NUM5 MOVLW 2 ;enables the display
MOVWF PORTA
MOVLW 3H
MOVWF PORTB
CALL CLOCK
MOVWF 5H
MOVWF PORTB
CALL CLOCK
RETLW 0

NUM6 MOVLW 2 ;enables the display
MOVWF PORTA
MOVLW 3H
MOVWF PORTB
CALL CLOCK
MOVWF 6H
MOVWF PORTB
CALL CLOCK
RETLW 0

NUM7 MOVLW 2 ;enables the display
MOVWF PORTA
MOVLW 3H
MOVWF PORTB
CALL CLOCK
MOVWF 7H
MOVWF PORTB
CALL CLOCK
RETLW 0

NUM8 MOVLW 2 ;enables the display
MOVWF PORTA
MOVLW 3H
MOVWF PORTB
CALL CLOCK
MOVWF 8H
MOVWF PORTB
CALL CLOCK
RETLW 0

NUM9 MOVLW 2 ;enables the display
MOVWF PORTA
MOVLW 3H
MOVWF PORTB
CALL CLOCK
MOVWF 9H
MOVWF PORTB
CALL CLOCK
RETLW

GAP MOVLW 2
MOVWF PORTA
MOVLW 2H
MOVWF PORTB
CALL CLOCK
MOVWF 0H
MOVWF PORTB
CALL CLOCK
RETLW 0

DOT MOVLW 2
MOVWF PORTA
MOVLW 2H
MOVWF PORTB
CALL CLOCK
MOVWF 0EH
MOVWF PORTB
CALL CLOCK
RETLW 0

CLRDISP MOVWF PORTA
MOVLW 0H
MOVWF PORTB
CALL CLOCK
MOVWF 1
MOVWF PORTB
CALL CLOCK
CALL DELAYP1
RETLW 0

;******************************************************************************

;CONFIGURATION SECTION.

START BSF STATUS,5 ;Turns to Bank1.
MOVLW B'00000000' ;PORTA is O/P
MOVWF TRISA

MOVLW B'00000000' ;PORTA is O/P
MOVWF TRISB

;Display CONFIGURATION


MOVLW 02H
MOVWF PORTB
CALL CLOCK
CALL DELAYP1


MOVLW 02H
MOVWF PORTB
CALL CLOCK
CALL DELAYP1


MOVLW 08H
MOVWF PORTB
CALL CLOCK
CALL DELAYP1


MOVLW 0H
MOVWF PORTB
CALL CLOCK

MOVLW 0cH
MOVWF PORTB
CALL CLOCK

CALL DELAYP1

MOVLW 0H
MOVWF PORTB
CALL CLOCK

MOVLW 6H
MOVWF PORTB
CALL CLOCK

***********************************************************************


;program stats now.


Begin CALL CLRDISP
CLRF PORTA


MOVLW 8H
MOVWF PORTB
CALL CLOCK

MOVLW 0H
MOVWF PORTB
CALL CLOCK


CALL M
CALL DELAYP1
CALL I
CALL DELAYP1
CALL C
CALL DELAYP1
CALL R
CALL DELAYP1
CALL O
CALL DELAYP1
CALL C
CALL DELAYP1
CALL O
CALL DELAYP1
CALL N
CALL DELAYP1
CALL T
CALL DELAYP1
CALL R
CALL DELAYP1
CALL O
CALL DELAYP1
CALL L
CALL DELAYP1
CALL L
CALL DELAYP1
CALL E
CALL DELAYP1
CALL R
CALL DELAYP1
CALL S
CALL DELAYP1



CLRF PORTA
MOVLW 0CH ; CURSOR ON SECOND LINE, C3
MOVWF PORTB
CALL CLOCK

MOVLW 3H
MOVWF PORTB
CALL CLOCK



CALL A
CALL DELAYP1
CALL T
CALL DELAYP1

CALL GAP

CALL L
CALL DELAYP1
CALL O
CALL DELAYP1
CALL N
CALL DELAYP1
CALL D
CALL DELAYP1
CALL O
CALL DELAYP1
CALL N


CALL DELAYP3

GOTO BEGIN

END











hum
 

your better to use a fast flow int driven clock
and a pic rt timer
divide one by the other

or use a random divide multiply + - stage

that has limits

this code is very long and disjointed to see easily where your problem is...

better 2s over clock and use all maths avalible

what ive done in the past is to time a number and divide it by the time + a random count based on time / time taken to make a decision
on what it was

youll only get sudo random from a pic
its only 16bit
 

i think this thread belongs to embedded segment.if you post this there, probability of getting the right solution will be higher (because embedded masters mostly visit that section )
 

thank you for interest.

well that is my problem that i don't know how sort out this program, therefore i asked for help if any1 can help me to write a program.

so is there any1 that can help me to write a new program from the beginning?


thanks
hum
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top