dual 7-segment dice c code

Status
Not open for further replies.

mojocyber

Newbie level 2
Joined
Jan 3, 2014
Messages
2
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Visit site
Activity points
23
I am having problems with my code, it compiles but does not display the digits how I want. can someone help, very new to programming.


Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
/* Created:   Mon Nov 25 2013
* Processor: PIC16F877
* Compiler:  HI-TECH C for PIC10/12/16
*/
/* double 7 Segment interfacing programme*/
 
#include <pic.h>
#include <stdlib.h>
#include <time.h>
 
 
const static unsigned char segment_code[] = {       0x3F, //0
                                                    0x06, //1
                                                    0x5B, //2
                                                    0x4F, //3
                                                    0x66, //4
                                                    0x6D, //5
                                                    0x7C, //6
                                                    0x07, //7
                                                    0x7F, //8
                                                    0x67}; //9
 
char counter1 = 0;
char counter2 = 0;
bit button_up = 0;
 
void main(void)
{
    TRISC=0x00; // all outputs
    TRISD=0x00; // all outputs
    TRISB=0xFF; // all inputs
 
    srand(rand()); // seeds random with time
 
    for(;;) // start of superloop
    {
        if(RB0==1)
            button_up=1;
        else
        {
            if (button_up==1)
            {
                button_up=0;
                counter1=rand()%6+1;
                counter2=rand()%6+1;
            }
        }
        PORTC=segment_code[counter1];
        PORTD=segment_code[counter2];
    }
};

:???:
 
Last edited by a moderator:

You are required to design an electronic dice simulator. The design will incorporate two seven segment displays, a pushbutton and the PIC16F877. A suitable circuit design developed in Proteus will be required to simulate the circuit and the software developed.
When the push button is pressed both displays will show rapidly changing numbers between 1 and 6. When the button is released the two random numbers generated will be displayed.
Requirements
You will need to develop the circuit in the ISIS part of Proteus 8 and the C code for the PIC16F877, using the HiTech 'C' compiler. The report should document the design procedure with sufficient detail so that it could be redeveloped by others.

I have 1 7-segment connected to RCO to RC6
and 1 7-segment connected to RDO to RD6
push button connected to RBO

it is not outputting full digits
 

Don't know for sure if this comes into play with your PIC code, but...

7-segment displays can be of two styles: (a) common ground or (b) common supply +.

You must apply correct polarity to the common pin, and opposite polarity to the 7 pins, in order to light up the led segments.

Once you get polarity right, you must confirm that sending an '8' lights up every segment.
And sending a '1' lights up the rightmost two segments. Etc.
 

Head over to gooligum, there is an entire section on driving and multiplexing 7 segments.

There are two tutorials on driving 7 segments at gooligum along source code both assembly and c.
 
Last edited:

Status
Not open for further replies.

Similar threads

Cookies are required to use this site. You must accept them to continue using the site. Learn more…