#include #define LATCH BIT2 #define CLOCK BIT3 #define DATA BIT4 #define SWITCH1 BIT0 #define SWITCH2 BIT1 #define RS BIT5 #define EN BIT4 #define D7 BIT3 #define D6 BIT2 #define D5 BIT1 #define D4 BIT0 int x,m,y,s,d,z,v,p,a,c,e,f,g,h; int i=0; int f=0; void pulseclock(void)//function to pulse the serial clock { P1OUT |= CLOCK; P1OUT ^= CLOCK; } void pinwrite(unsigned int pin, unsigned long j)//function to send 0 or 1 on gpio for a high or low value of sent data { if (j) P1OUT |= pin; else P1OUT &=~ pin; } void shiftout1(unsigned long j)//function to send higher order 16 bits as msp has 16 bit architecture { P1OUT &=~ LATCH; int l; for (l = 0; l < 16; l++) {// as data value is 16 bits and clock has to be toggled 16 bits only pinwrite(DATA, (j & (1<>4)|0xF0);//SEND HIGHER BITS data_write(); P2OUT = (P2OUT | 0x0F)&(cmd|0xF0);//SEND LOWER BITS data_write(); } void send_data(unsigned char data){ check_busy(); P2OUT |= RS; P2OUT = (P2OUT | 0x0F)&((data>>4)|0xF0);//SEND HIGHER BITS data_write(); P2OUT = (P2OUT | 0x0F)&(data|0xF0);//SEND LOWER BITS data_write(); } void send_string(char *s){ while(*s){ send_data(*s); s++; } } void lcd_init(void) { P2DIR |= RS+EN+D7+D6+D5+D4; P2OUT &= 0x00; send_command(0x33); send_command(0x32); send_command(0x28); // 4 bit mode send_command(0x0E); // display on cursor on send_command(0x01); // clear the screen send_command(0x06); // increment cursor send_command(0x80); // row 1 column 1 } void refresh_red(void) { for(m=0;m<8;m++){ int b = (m%8); if(b==0){ ledred(i); } else{ shiftout2(0x0000);//sending lower order byte first shiftout1(0x0000);//sending higher order byte P1OUT |= LATCH; P1OUT &=~ LATCH; } } } void refresh_green(void) { for(m=0;m<8;m++){ int b = (m%8); if(b==0){ ledgreen(f); } else{ shiftout2(0x0000);//sending lower order byte first shiftout1(0x0000);//sending higher order byte P1OUT |= LATCH; P1OUT &=~ LATCH; } } } void gen_random_red(void) { while(P1IN & SWITCH1 == 0); __delay_cycles(2000); x = TA1R; y=((x%6)+1); lcd_init(); if(y==1){ send_string("1"); } else if(y==2){ send_string("2"); } else if(y==3){ send_string("3"); } else if(y==4){ send_string("4"); } else if(y==5){ send_string("5"); } else if(y==6){ send_string("6"); } else{ send_string("2"); y=2; } s=i+y; z=((x-i)%3); if (z==0){ send_command(0xC0); send_string("oops! snakes"); d= ((x%20)+1); if(d>i){ v=0; } else{ v=i-d; } } else if(z==1){ send_command(0xC0); send_string("yayy! ladders"); d= ((x%14)+1); v=d+i; } else { send_command(0xC0); send_string("safe play"); d=0; v=i; } } void gen_random_green(void) { while(P1IN & SWITCH2 == 0); __delay_cycles(2000); a = TAR; c=((a%6)+1); lcd_init(); if(c==1){ send_string("1"); } else if(c==2){ send_string("2"); } else if(c==3){ send_string("3"); } else if(c==4){ send_string("4"); } else if(c==5){ send_string("5"); } else if(c==6){ send_string("6"); } else{ send_string("1"); c=1; } e=f+c; g=((a-f)%3); if (g==0){ send_command(0xC0); send_string("oops! snakes"); h= ((a%20)+1); if(h>f){ p=0; } else{ p=f-h; } } else if(g==1){ send_command(0xC0); send_string("yayy! ladders"); h= ((x%14)+1); p=h+f; } else { send_command(0xC0); send_string("safe play"); h=0; p=i; } } int main(void) { WDTCTL = WDTPW | WDTHOLD; // Stop watchdog timer P1DIR &=~(SWITCH1+SWITCH2); P1DIR |= (BIT2+BIT3+BIT4); P2DIR |= RS+EN+D7+D6+D5+D4; P2OUT &= 0x00; P1REN |= SWITCH1+SWITCH2; P1OUT |= SWITCH1+SWITCH2; TA1CTL |= TACLR + TASSEL_2 + MC_2 ; TA0CTL |= TACLR + TASSEL_1+ MC_2 + ID_1; for(;;){ if((P1IN & SWITCH1) == 0){ gen_random_red(); } for(i=i;iv;i--){ refresh_red(); __delay_cycles(200); } } if(z==1){ for (i=i; ip;f--){ refresh_red(); __delay_cycles(200); } } if(g==1){ for (f=f; f=63){ i=63; refresh_red(); send_command(0x01); send_string("RED WINS"); P1DIR |=(SWITCH1+SWITCH2); } if(f>=63){ f=63; refresh_green(); send_command(0x01); send_string("GREEN WINS"); P1DIR |=(SWITCH1+SWITCH2); } } return 0; }