// Global Variables const unsigned char MSG0[20] = "N: "; const unsigned char MSG1[20] = "Bank: "; // Subroutine Declarations #include // Subroutines #include "lcd_portd.c" void Beep(void) { unsigned int i, j; for(i=0; i<20; i++) { RA1 = !RA1; for(j=0; j<1558; j++); } RA1 = 0; } void Display(unsigned int BANK, unsigned int BALL) { LCD_Move(0,8); LCD_Out(BALL, 1, 0); LCD_Move(1,8); LCD_Out(BANK, 3, 0); if(BALL == 0) PORTC = 1; if(BALL == 1) PORTC = 2; if(BALL == 2) PORTC = 4; if(BALL == 3) PORTC = 8; if(BALL == 4) PORTC = 0x10; if(BALL == 5) PORTC = 0x20; if(BALL == 6) PORTC = 0x40; if(BALL == 7) PORTC = 0x80; } unsigned int Spin_Wheel(void) { unsigned int N; while(!RB0); while(RB0) N = (N + 1) % 8; return(N); } // Main Routine void main(void) { unsigned int BANK, BALL, N, i, j; TRISA = 0; TRISB = 0xFF; TRISC = 0; TRISD = 0; TRISE = 0; ADCON1 = 0x0F; LCD_Init(); LCD_Move(0,0); for(i=0; i<16; i++) LCD_Write(MSG0[i]); LCD_Move(1,0); for(i=0; i<16; i++) LCD_Write(MSG1[i]); BANK = 2600; BALL = 7; Display(BANK, BALL); while(1) { N = Spin_Wheel(); for(i=32+N; i>0; i--) { BALL = (BALL + 1)%8; Display(BANK, BALL); Beep(); Wait_ms(50 + 1000/i); } if(BALL == 7) BANK += 8; else BANK -= 1; Display(BANK, BALL); } }