void lcdcmd(unsigned char value) { lcdready(); ldata = value; //put the value on the pins rs = 0; rw = 0; en = 1; //strobe the enable pin MSDelay(1); en = 0; }
void lcddata(unsigned char value) { lcdready(); ldata = value; rs = 1; rw = 0; en = 1; MSDelay(1); en = 0; return; }
void main(void) { unsigned int HI, LO, TOTAL; unsigned char l, OV, OFR[16] = "Out Of Range..."; OV = 0; T0 = 1; TMOD = 0x05; TL0 = 0; TL1 = 0; lcdinit(); while(1) { do { start: TR0 = 1; MSDelay(145); LO = TL0; HI = TH0; HI = HI << 8; TOTAL = HI | LO; Unit[0] = 'H'; Unit[1] = 'z'; Unit[2] = ' '; Unit[3] = ' '; if(OV == 1) { TOTAL = TOTAL / 1000; TOTAL = TOTAL + 65; if(TOTAL > 125) { for(l=0; l<16; l++) lcddata(OFR[l]); for(l=0; l<16; l++) lcdcmd(0x10); goto start; } OV = 0; Unit[0] = 'K'; Unit[1] = 'H'; Unit[2] = 'z'; Unit[3] = ' '; } inttoLCD(TOTAL); TL0 = 0; TH0 = 0; } while(TF0 == 0); OV = 1; TR0 = 0; TF0 = 0; } }
void lcdready() { busy = 1; //make the busy pin an input rs = 0; rw = 1; while(busy == 1) //wait here for busy flag { en = 0; //strobe the enable pin MSDelay(1); en = 1; } return; }
void lcdready() { busy = 1; rs = 0; rw = 1; do { en = 0; MSDelay(1); en = 1; } while(busy == 1); return; }
void main() { float Frequency, Percent, LowTime, HighTime, TotalDelayMilli, TotalDelayMicro; unsigned int ConvHH, ConvLH, ValueH, ConvHL, ConvLL, ValueL; unsigned char x, HighH, LowH, HighL, LowL; unsigned char Freq[17] = "Freq: Hz", DutyC[17] = "Duty Cycle: %"; unsigned char colloc; Status = 0; KEYPAD = 0xF0; // make higher bits of keypad port that is column bits input and low row bits outputs Clock = 0; lcdcmd(0x38); // 2 lines and 5X7 matrix lcdcmd(0x0C); // Display ON, Cursor Blinking = 0x0E But this command is Display ON, Cursor OFF lcdcmd(0x01); // Clear Display Screen lcdcmd(0x80); // Force Cursor to the beginning of the First Line lcdcmd(0x06); main:lcdcmd(0x01); for(x = 0; x<16; x++) lcddata(Freq[x]); lcdcmd(0xC0); for(x = 0; x<16; x++) lcddata(DutyC[x]); lcdcmd(0x80); for(x=0; x<6; x++) lcdcmd(0x16); lcdcmd(0x0E); Frequency = GetInput(); if(Frequency > 20000) goto main; lcdcmd(0x0C); lcdcmd(0xC0); for(x = 0; x<12; x++) lcdcmd(0x16); lcdcmd(0x0E); Percent = GetInput(); lcdcmd(0x0C); TotalDelayMilli = (1 / Frequency) * 1000; TotalDelayMicro = (TotalDelayMilli * 1000) - 45; //With correction of 45 HighTime = (TotalDelayMicro / 100) * Percent; LowTime = TotalDelayMicro - HighTime; ValueH = 65536 - HighTime; ConvLH = ValueH & 0x00FF; // Zeroing the Higher 8 bits to have Lower 8 bits LowH = ConvLH; // Storing in a 8 bit character ConvHH = ValueH & 0xFF00; // Masking the Lower 8 bits to have Higher 8 bits ConvHH = ConvHH >> 8; // Shifting right 8 bits to hit to the Lower Part to save it to a 8-bit character HighH = ConvHH; // Storing in a 8 bit character ValueL = 65536 - LowTime; ConvLL = ValueL & 0x00FF; // Zeroing the Higher 8 bits to have Lower 8 bits LowL = ConvLL; // Storing in a 8 bit character ConvHL = ValueL & 0xFF00; // Masking the Lower 8 bits to have Higher 8 bits ConvHL = ConvHL >> 8; // Shifting right 8 bits to hit to the Lower Part to save it to a 8-bit character HighL = ConvHL; Status = 1; while(1) //2 Machine Cycle { Clock = 1; //1 MC TimerH(HighH, LowH); Clock = 0; TimerL(HighL, LowL); colloc = KEYPAD; //2 MC colloc &= 0xF0; //2 MC if(colloc == 0xE0) //4 MC { MSDelay(5); colloc = KEYPAD; //read the columns colloc &= 0xF0; //mask unused bits if(colloc == 0xE0) { Status = 0; goto main; } } } } //main braces
unsigned char KeypadRead() { unsigned char colloc, rowloc; do { KEYPAD = 0xF0; // ground all rows at once colloc = KEYPAD; // read the port for columns colloc &= 0xF0; // mask row bits } while(colloc != 0xF0); // check until all keys are released do { do { MSDelay(8); //call delay colloc = KEYPAD; //see if any key is pressed colloc &= 0xF0; // mask unsused bits } while(colloc == 0xF0); // keep checking for keypress MSDelay(8); // call delay for debounce colloc = KEYPAD; // read columns colloc &= 0xF0; // mask unused bits } while(colloc == 0xF0); // wait for keypress while(1) { KEYPAD &= 0xF0; // masking row bits KEYPAD |= 0x0E; // now ground row 0 0E = 00001110b ORing won't affect column data colloc = KEYPAD; // read columns colloc &= 0xF0; // mask row bits if(colloc != 0xF0) // column detected { rowloc = 0; // save row location break; } KEYPAD &= 0xF0; KEYPAD |= 0x0D; // ground row 1 0D = 00001101b ORing won't affect column data colloc = KEYPAD; // read columns colloc &= 0xF0; // mask row bits if(colloc != 0xF0) // column detected { rowloc = 1; // save row location break; } KEYPAD &= 0XF0; KEYPAD |= 0x0B; // ground row 2 0B = 00001011b colloc = KEYPAD; // read columns colloc &= 0xF0; // mask row bits if(colloc != 0xF0) // column detected { rowloc = 2; // save row location break; } KEYPAD &= 0XF0; KEYPAD |= 0x07; // ground row 3 07 = 00000111b colloc = KEYPAD; // read columns colloc &= 0xF0; // mask row bits if(colloc != 0xF0) // column detected rowloc = 3; // save row location break; } //check columns and send result to LCD if(colloc == 0xE0) // 0E = 00001110 return keypad[rowloc][0]; else if(colloc == 0xD0) // 0D = 00001101 return keypad[rowloc][1]; else if(colloc == 0xB0) // 0B = 00001011 return keypad[rowloc][2]; else return keypad[rowloc][3]; }
void main(void) { unsigned int readDPS; unsigned int temp = 1; unsigned int sayi1; unsigned int i=0; unsigned int j=0; unsigned int kazanmaDrumu =0; unsigned int kazandi=0; disable(); DDRA=0x0F; // pb0-3 is out, others input DDRB=0xff; // DDRP=0xff; // 7-segment icin DDRH=0x00; DDRT = DDRT | 0b00100000; // PTT5 as output (Buzzer icin) PORTB=0; TSCR1 =TSCR1 | 0x80; // Enable timer subsystem TSCR2 = 0x05; // Set overflow time to 87 ms TFLG2 = 0x80; // Make sure TOF bit clear RTICTL=0x31; //pre scale 2048 CRGINT=0x80; //RTI CRGFLG=0x80; //RTI flag enable(); while (1) { /* cvp arayi sýfýrlanir */ for(i=0; i<4; ++i){ cvp[i] = 0; } oyunSayisi = (TCNT+temp)%NUMBER_OF_WORDS; // random sayý üretmek icin back = 0; kazandi=1; kazanmaDrumu =0; hataCount = 0; chooser = 0; // score u goster MSDelay(2000); // 2 sn boyunca while(1) { chooser = 1; // kelimenin dogru bilinen harflerini gosterir. //MSDelay(2000); // 2 sn bekle kullanýcý giris yapsýn while((sayi1 = GetKey()) == -1); MSDelay(155); sayi1 *= 10; while((readDPS = GetKey()) == -1); MSDelay(155); readDPS += sayi1; temp = readDPS; tahmin(readDPS); // tahmin doðrumu diye check et chooser=1; // kelimenin dogru bilinen harflerini gosterir. MSDelay(500); // 500 ms boyunca goster /* cvp arrayi tam doluysa cevap bilinmistir. */ for(i=0; i<4; ++i){ if(cvp[i] == 1){ ++kazanmaDrumu; } } /* kazanma durumunda yapilacak olanlar */ if(kazanmaDrumu == 4){ ++score; kazandi=0; chooser=1; // kelimenin dogru bilinen harflerini gosterir. MSDelay(2000); // 3 sn boyunca goster chooser = 4; // win MSDelay(1000); chooser = 0; // score MSDelay(1000); chooser = 4; // win MSDelay(1000); break; }else{ kazanmaDrumu=0; } /* 6 kez yanlis girilme durumunda programdan cik. */ if(hataCount >= 6){ break; } } if(kazanmaDrumu < 4 || hataCount >= 6){ chooser = 0; // score MSDelay(1000); chooser = 7; // cevap MSDelay(2500); chooser = 5; // lose MSDelay(1000); chooser = 0; // score MSDelay(1000); chooser = 5; // lose MSDelay(1000); chooser = 0; // score MSDelay(1000); chooser = 5; // lose MSDelay(1000); chooser = 0; // score MSDelay(1000); chooser = 5; // lose MSDelay(1000); chooser = 9; // GOODBYE // goodbye yazan dongu while(1){ MSDelay(500); PTT = PTT | 0x20; //make PT5=1 MSDelay(10); //change the delay size to see what happens PTT = PTT & 0xDF; //Make PT5=0 MSDelay(10); //change delay size.... ++goodCount; if(goodCount>=17){ break; } } chooser = 6; // finish MSDelay(100); break; } if(oyunCounter >= NUMBER_OF_GAME){ chooser = 0; // score MSDelay(1000); chooser = 4; // win MSDelay(1000); chooser = 0; // score MSDelay(1000); chooser = 4; // win MSDelay(1000); chooser = 0; // score MSDelay(1000); chooser = 4; // win MSDelay(1000); chooser = 0; // score MSDelay(1000); chooser = 4; // win MSDelay(1000); chooser = 6; // finish MSDelay(100); chooser = 8; // congraluations // congraluations yazan dongu while(1){ MSDelay(500); PTT = PTT | 0x20; //make PT5=1 MSDelay(10); //change the delay size to see what happens PTT = PTT & 0xDF; //Make PT5=0 MSDelay(10); //change delay size.... ++congCount; if(congCount>=33){ break; } } chooser = 6; // finish MSDelay(100); break; } ++oyunCounter; } __asm(swi); }