Raynerd.co.uk

25 Feb, 2010

PIC Binary Dice - 12F675

Posted by: admin In: PIC Binary Dice Code 12F675

Simple MikroC code for a binary dice on a 12F675. I was looking for a nice idea for a small project group of students rather than just flashing leds. No embellishment, just a straight forward code! While no button is pressed it is counting 1-6 fast, when the button is pressed it displays the number in binary.

#define led0 GPIO.b0
#define led1 GPIO.b1
#define led2 GPIO.b2
#define button GPIO.b5

//----- global variables ----
char dice=1;

// hardware initiation function
void init()
{
ANSEL = 0; // Configure AN pins as digital
CMCON = 7; // Turn off the comparators
TRISIO = 0b111000;
GPIO = 0x00;
}

void main()
{
init ();

while (1)
{
while (!button)
{
led0 = led1 = led2 = 0;
dice++;
if (dice>6)
dice = 1;
}

while (button)
{
switch (dice)
{
case 1: led0 = 1; break;
case 2: led1 = 1; break;
case 3: led0 = led1 = 1; break;
case 4: led2 = 1; break;
case 5: led2 = led0 = 1; break;
case 6: led2 = led1 = 1; break;
}
}
}
}

No Responses to "PIC Binary Dice - 12F675"

Comment Form


  • admin: I appreciate your interest in this project. I have far too many other little projects on the go and have just had a major change around, reorganisatio
  • Mark Peterson: What is your current status? Any advances since July? I am curious to see how you end up on this project. This has got to be a labor of love. I endeav
  • admin: Yes, I machined the graphite. It was very messy! I`ve tried it without the counter weight and still nothing. It is currently in bits again and I`m mak

Welcome to Raynerd.co.uk

I`ve always wanted to learn more about engineering and electronics and my list of projects both complete and ongoing has been growing over the past few years. I like to document my progress more for my own understanding as much as anything, it helps keep me on track. I hope you can find something of interest to you, my clock building project is my priority but as you can see, I have many other builds I`m working on. Please leave a comment, it is nice to see people are reading!