void LCDSendInt_Old(int a) { int h = 0; int l = 0; l = a%10; h = a/10; LCDSendChar(h+48); LCDSendChar(l+48); }
void LCDSendTxt(char* a) { int Temp; for(Temp=0; Temp<strlen(a); Temp++) { LCDSendChar(a[Temp]); } }
void LCDSendInt(long a) { int C[20]; unsigned char Temp=0, NumLen = 0; if (a < 0) { LCDSendChar('-'); a = -a; } do { Temp++; C[Temp] = a % 10; a = a/10; } while (a); NumLen = Temp; for (Temp = NumLen; Temp>0; Temp--) LCDSendChar(C[Temp] + 48); }
void LCDSendUnsafeCounteredTxt(char* a, char count) { //_delay_ms(1); int Temp; for(Temp=0; Temp < count; Temp++) { LCDSendChar(a[Temp]); TEXTDELAY } }
void LCDSendTxt(char* a) { //_delay_ms(1); int Temp; for(Temp=0; Temp < strlen(a); Temp++) { LCDSendChar(a[Temp]); TEXTDELAY } }
int main(void) { MCUCSR = (1<<JTD); // Disable JTAG MCUCSR = (1<<JTD); // Disable JTAG (yes, 2 are required) // Configure serial UBRRH = (uint8_t)(UBRR>>8); UBRRL = (uint8_t)(UBRR); UCSRB |= (1<<TXEN) | (1<<RXEN) | (1<<RXCIE); UCSRC |= (1<<URSEL) | (1<<UCSZ1) | (1<<UCSZ0); // Set up buttons DDRB &= ~(1<<ENTER | 1<<CANCEL | 1<<UP | 1<<DN); PORTB |= 0xF; // Configure ports 0-3 as inputs with pull-ups // Timer interrupt, 1mS TCCR1B |= (1<<CS12) | (1<<WGM12); OCR1A = 625; // 100Hz (10mS) with div by 256 TIMSK |= 1<<OCIE1A; sei(); DDRD |= (1<<PIND7 | 1<<PIND3 | 1<<PIND4); //DDRA |= (1<<PINA0 | 1<<PINA1); //PORTA &= ~(1<<PORTA0 | 1<<PORTA1); //_delay_ms(10); LCDInit(); while(1) { _delay_ms(200); if (rxflag) { LCDSetPos(0,15); LCDSendChar(c); } if (LEDFlag) { LEDFlag = 0; PORTD |= 1<<PORTD7; _delay_ms(100); PORTD &= ~(1<<PORTD7); } /* switch(btnpressed){ case(BTN_ENTER): serialSendText("Enter\n\r"); break; case(BTN_CANCEL): serialSendText("Cancel\n\r"); break; case(BTN_UP): serialSendText("Up\n\r"); break; case(BTN_DOWN): serialSendText("Down\n\r"); break; default: serialSendText("None\n\r"); } */ runstate = handleMenu(btnpressed); if (runstate == RS_RUN){ serialSendText("RUN\n\r"); } else{ serialSendText("STOP\n\r"); } if ((trigger == 1) && (runstate == RS_RUN)){ triggerhalf(); _delay_ms(100); triggerfull(); _delay_ms(100); triggernone(); trigger = 0; } btnpressed = BTN_NONE; if (lcdchanged == 1){ LCDSetPos(0,0); LCDSendText("Delay time: "); itoa(time, buffer, 10); LCDSendText(buffer); LCDSendText(" "); LCDSetPos(1,0); LCDSendText("Frames: "); itoa(counter, buffer, 10); LCDSendText(buffer); LCDSendText(" "); LCDSetPos(2,0); if (runstate == RS_RUN){ LCDSendText("Running"); } else{ LCDSendText("Stopped"); } lcdchanged = 0; } } }
int main() { Port_Init(); LCD_Init(); LCDSendCommand(DISP_OFF); while (1) { //Value of Bl prevents holding the buttons //Bl = 0: One of the Buttons is pressed, release to press again //LCD_State value is the state of LCD: 1 - LCD is ON; 0 - LCD is OFF //Up Button (Button 1) : Turn ON Display if (!(PINA & 0b00000001) & Bl & !(LCD_State)) //check state of button 1 and value of Bl and LCD_State { LCDSendCommand(DISP_ON); //Turn ON Display LCDSendCommand(CLR_DISP); //Clear Display LCDSendTxt(" Welcome "); //Print welcome screen Bl = 0; //Button is pressed LCD_State = 1; //Display is ON (LCD_State = 1) } //Left Button (Button 2) : Set Text1 if (!(PINA & 0b00000010) & Bl & LCD_State) //check state of button 2 and value of Bl and LCD_State { LCDSendCommand(CLR_DISP); //Clear Display LCDSendCommand(DD_RAM_ADDR); //set to Line 1 for (i=0; i<16; i++) Text[i] = 0; //Clear Text strcpy(Text, Text1); //set Text for (i=0; i<16; i++) if (Text[i] == 0) Text[i] = ' ';//fill the Text with space //LCDSendTxt(Text); //Print the text for (i=0; i<16; i++) LCDSendChar(Text[i]); Bl = 0; //Button is pressed Line = 1; //text must be print on up line } //Middle Button (Button 3) : Slide the text if (!(PINA & 0b00000100) & Bl & LCD_State) { while (!(PINA & 0b00000100) & (Line != 0)) //check state of button 3 and value of Line (Line = 0 - no text selected) { //sliding the text for(i=60000; i; i--); Ch = Text[0]; for (i=0; i<15; i++) Text[i] = Text[i+1]; Text[15] = Ch; //print the text in the correct line if (Line == 1) LCDSendCommand(DD_RAM_ADDR); else LCDSendCommand(DD_RAM_ADDR2); //LCDSendTxt(Text); for (i=0; i<16; i++) LCDSendChar(Text[i]); } } //Right Button (Button 4) Set Text2 if (!(PINA & 0b00001000) & Bl & LCD_State) //check state of button 4 and value of Bl and LCD_State { LCDSendCommand(CLR_DISP); //Clear Display LCDSendCommand(DD_RAM_ADDR2); //set to Line 2 for (i=0; i<16; i++) Text[i] = 0; //Clear Text strcpy(Text, Text2); //set Text for (i=0; i<16; i++) if (Text[i] == 0) Text[i] = ' ';//fill the Text with space //LCDSendTxt(Text); //Print the text for (i=0; i<16; i++) LCDSendChar(Text[i]); Bl = 0; //Button is pressed Line = 2; //text must be print on down line } //Down Button (Button 5) Turn OFF Display if (!(PINA & 0b00010000) & Bl & LCD_State) //check state of button 5 and value of Bl and LCD_State { LCDSendCommand(CLR_DISP); //Clear Display LCDSendTxt(" Turn OFF "); //Print Turn OFF message for (i=30; i; i--) for (j=30000; j; j--); //simple delay Bl = 0; //Button is pressed LCDSendCommand(DISP_OFF); //Display is OFF ==> LCD_State = 0, Line = 0 LCD_State = 0; Line = 0; } //check state of all buttons if ( ((PINA & 0b00000001) |(PINA & 0b00000010) |(PINA & 0b00000100) |(PINA & 0b00001000) |(PINA & 0b00010000)) == 31) Bl = 1; //if all buttons are released Bl gets value 1 } return 0; }