Raynerd.co.uk

PIC Binary Dice – 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;
}
}
}
}

RSS
YouTube
Twitter
Visit Us
Follow by Email922
Google+
Google+

Leave a Reply