/* prints a welcome message */ void welcomemessage() { char phrase[15]; char phrase2[15]; snprintf(phrase, 15,"EE109"); snprintf(phrase2, 15,"Stopwatch Lab"); moveto(1,6); stringout(phrase); moveto(2,2); stringout(phrase2); _delay_ms(2000); }
/* sets timer to zero */ void init_count() { char buffer[5]; time[0] = time[1] = time[2] = '0'; snprintf(buffer, 5, "%c%c.%c", time[0] , time[1] , time[2]); moveto(1,1); stringout(buffer); }
void moduleinit() { DDRD = 0xf0; DDRB = 0x03; // initialize lcd init_lcd(); writecommand(0x01); // leds (blue wire) DDRD |= (1 << PD2) | (1 << PD3); // rotary encoder (yellow wire) DDRC &= ~(1 << PC1) | ~(1 << PC2); PORTC |= (1 << PC1) | (1 << PC2); // buttons (green wire) DDRB &= ~(1 << PB3) | ~(1 << PB4); PORTB |= (1 << PB3) | (1 << PB4); //enable interrupts sei(); PCICR |= (1 << PCIE0) | (1 << PCIE1); PCMSK0 |= (1 << PB3) | (1 << PB4); PCMSK1 |= (1 << PC1) | (1 << PC2); //serial interface UBRR0 = 103; // Set baud rate UCSR0B |= (1 << TXEN0 | 1 << RXEN0); // Enable RX and TX UCSR0C = (3 << UCSZ00); // Async., no parity, // 1 stop bit, 8 data bits DDRC |= (1 << PC3); PORTC &= ~(1 << PC3); //initialize thermometer ds1631_init(); ds1631_conv(); // template stringout("Temp:"); moveto(8); stringout("Rmt :"); moveto(0x40); stringout("Low :"); moveto(0x48); stringout("High:"); }
void updateScreen(){ moveto(0x40);//move to second line of LCD char vars[16]; if(buttonState){//high snprintf(vars, 16, "Low:%d HIGH:%d", low, high); } else{//low snprintf(vars, 16, "LOW:%d High:%d", low, high); } stringout(vars); }
int main(void){ init_lcd(); sei(); PORTD |= (1<<PD2)|(1<<PD3);//pull up button PCICR |= (1 << PCIE2);//enable interrupts on PORTD PCMSK2 |= (1 << PCINT18) | (1 << PCINT19);//mask for portd bits 2 and 3 stringout("Temp:"); moveto(0x40); snprintf(out,8,"%d",res); stringout(out); if(prnt==1){ moveto(0x40); stringout(" "); moveto(0x40); snprintf(out,8,"%d",res); stringout(out); prnt=0; } while(1); /*while(1){ if((PIND&(1<<PD2))==0){ stringout("High"); } else if((PIND&(1<<PD3))==0){ stringout("Low"); } }*/ return 0; }
void romanout(char thischar) { stringout("{\\roman "); charout(thischar); charout('}'); }
main(int argc, char *argv[]) { int ch,err,notdone,vowflag,initflag; errorcount=0; switcher='~'; true=1; false=0; tamilflag=false; tdelim=1; /* i.e. control-a ::: if yah don't like it, change it */ tspace[0]=tdelim; tspace[1]=' '; haccbox(); vowflag=0; if (argc > 1) input = fopen(argv[1],"rb"); if (input == (FILE *) NULL) { /* prompt for and open input file */ for ( ; input == (FILE *) NULL ; input=get_file("rb","Enter name of input file: ")) ; } /* we are making these binary, as we have no guarantee what kind */ /* of character may be in the transcription: we don't care about */ /* ends of lines, as we are reading character by character */ if (argc > 2) output = fopen(argv[2],"wb"); if (output == (FILE *) NULL) { for ( ; output == (FILE *) NULL ; output=get_file("wb","Enter name of output file: ")) ; /* prompt for and open output file */ } while ((ch = getc(input)) != EOF) { if (ch == switcher) changestate(); else { if (ch == '|') { vowflag=1; notdone=1; initflag=2; while (notdone) { ch=getc(input); if (isalnum(ch)) { initflag--; if (vowflag==0) { if (! isvowel(ch)) stringout("\\-"); } if (isvowel(ch)) vowflag=1; else vowflag=0; } else { vowflag=1; initflag=2; } if (ch==EOF) notdone=0; else { switch(ch) { case '2': stringout("\\ndot{}"); break; case '3': stringout("\\nndot{}"); break; case '4': stringout("\\skts{}"); break; case '5': stringout("\\paln{}"); break; case '6': stringout("\\rdot{}"); break; case '7': stringout("\\rdotdot{}"); break; case 'T': stringout("\\tdot{}"); break; case 'D': stringout("\\dotd{}"); break; case '8': if ( initflag > 0 ) stringout("\\tdot{}"); else { err=getc(input); if (err == '8') stringout("\\tdot{}\\tdot{}"); else { stringout("\\dotd{}"); pushback(err); } } break; case '9': stringout("\\dotl{}"); break; case '|': notdone=0; break; default: putc(ch,output); } /* endcase */ } /* end else */ } /* endwhile */ } /* endif */ else putc(ch,output); } /* endelse */ } /* endwhile */ fclose(input); fclose(output); puts("Tamilize is done."); }
void endtamil() { stringout("}\\etam{}"); /* stringout("}\\endtamil\%\n"); */ tamilflag=false; }
void starttamil() { stringout("{\\btam "); /* stringout("{\\starttamil\%\n"); */ processtamil(); }
void processtamil() { char ch; int newsyl; newsyl=true; for (tamilflag=true; tamilflag==true; ) { ch = getc(input); if (ch == EOF) abort(); if (ch == switcher) changestate(); else if (isspace(ch)) { stringout(tspace); charout(ch); for ( ch=getc(input); isspace(ch); ch=getc(input)) charout(ch); pushback(ch); newsyl=true; } else if (ispunct(ch) ) { if (ch == 125) printf("\nCharacter } encountered while scanning tamil -- probable error.\n"); romanout(ch); newsyl=true; } else { switch (ch) { case 'a': case 'e': case 'i': case 'o': case 'u': if (newsyl==true) { charout(tdelim); newsyl=false; } charout(ch); break; case 'c': case 't': case 'p': case 'm': case 'y': case 'r': case 'l': case 'v': case 's': case 'j': case 'x': case 'h': charout(tdelim); charout(ch); newsyl=false; break; case 'k': charout(tdelim); ch=getc(input); if (ch=='4') charout('X'); else { charout('k'); pushback(ch); } newsyl=false; break; case '2': charout(tdelim); charout('N'); newsyl=false; break; case '3': charout(tdelim); stringout("NN"); newsyl=false; break; case '4': charout(tdelim); charout('S'); newsyl=false; break; case '5': charout(tdelim); stringout("NY"); newsyl=false; break; case '6': charout(tdelim); charout('R'); newsyl=false; break; case '7': charout(tdelim); charout('Z'); newsyl=false; break; case '8': charout(tdelim); charout('T'); newsyl=false; break; case '9': charout(tdelim); charout('L'); newsyl=false; break; case 'n': charout(tdelim); ch=getc(input); if (ch=='g') stringout("ng"); else { charout('n'); pushback(ch); } newsyl=false; break; default : transcribe_err(ch); newsyl=true; } /* endcase */ } /* endif */ } /* endfor*/ }
void updateTop(){//called if valid data received from remote moveto(0x00); char top[16]; snprintf(top, 16, "Temp:%d Rmt:%d", tempF, remoteVal); stringout(top); }
int main() { int oldl = 1000, oldh = 1000, oldt = 1000;//, oldr = 1000; unsigned char out[4]; unsigned char rec[5]; unsigned char temp[2]; moduleinit(); while (1) { //receive and convert temperature ds1631_temp(temp); float c = temp[0]; if (temp[1]) { c += 0.5; } float f = (9*c)/5; int x = f +32; //unsigned char rmt = rx_char(); if (low != oldl) { moveto(0x45); stringout(" "); //clear previous number moveto(0x45); sprintf(out, "%2d", low); stringout(out); oldl = low; } if (high != oldh) { moveto(0x4d); stringout(" "); //clear previous number moveto(0x4d); sprintf(out, "%2d", high); stringout(out); oldh = high; } if (x != oldt) { moveto(5); stringout(" "); moveto(5); itoa(x, out, 10); stringout(out); oldt = x; //send temperature if (x > 0) { tx_char('+'); } else if (x < 0) { tx_char('-'); } //if 3 digits if (out[2] == 0) { tx_char('0'); _delay_ms(5); tx_char(out[0]); _delay_ms(5); tx_char(out[1]); } //if 2 digits else { tx_char(out[0]); _delay_ms(5); tx_char(out[1]); _delay_ms(5); tx_char(out[2]); } } //receive temperature if (UCSR0A & (1 << RXC0)) { // character has been received if (rx_char() == '+') { rec[0] = rx_char(); //100's digit if (rec[0] == '0') { //if 100's digit is 0 rec[0] = rx_char(); rec[1] = rx_char(); rec[2] = 0; } else { //else reset rec[0] to 10's digit rec[1] = rx_char(); rec[2] = rx_char(); rec[3] = 0; } } else if (rx_char() == '-') { rec[0] = '-'; rec[1] = rx_char(); if (rec[1] == '0') { //if 100's digit is 0 rec[1] = rx_char(); rec[2] = rx_char(); rec[3] = 0; } else { //else reset rec[0] to 10's digit rec[2] = rx_char(); rec[3] = rx_char(); rec[4] = 0; } } moveto(13); stringout(" "); moveto(13); stringout(rec); } if (x < low) { PORTD |= (1 << PD3); } else { PORTD &= ~(1 << PD3); } if (x > high) { PORTD |= (1 << PD2); } else { PORTD &= ~(1 << PD2); } moveto(0x50); //move cursor off of screen } return 0; }