void d_update (void) { int unused; if (d_status_ch) { unused = 16 - strlen (d_status); lcd_home (); lcd_puts (d_status); while (unused--) lcd_putc (' '); d_status_ch = 0; lcd_home (); } if (d_content_ch) { unused = 16 - strlen (d_content); lcd_gotoxy (0, 2); lcd_puts (d_content); while (unused--) lcd_putc (' '); d_content_ch = 0; lcd_home (); } }
void editorStart(FILE *LCD) { editor_LCD=LCD; editor_count_UP=0; editor_count_DOWN=0; editor_count_ENTER=0; editor_count_ACCEPT=0; editor_enabled=1; editor_mode=1; lcd_define_letter_P(1, EDITOR_UP_GLYPH_ADR); lcd_define_letter_P(2, EDITOR_DOWN_GLYPH_ADR); lcd_define_letter_P(3, EDITOR_ENTER_GLYPH_ADR); lcd_define_letter_P(4, EDITOR_ACCEPT_GLYPH_ADR); lcd_home(); lcd_clear(); editor_changed=1; editorShow(editor_mode); EDITOR_ENABLE_TIMER(); sei(); while (editor_enabled==1) { } EDITOR_DISABLE_TIMER(); editor_enabled=0; if (lcd_load_default_glyphs_P!=NULL) { lcd_load_default_glyphs_P(); lcd_home(); lcd_clear(); } }
/* * This method is called continouusly, i.e. in a while(1) loop. This is * where the exciting stuff happens. Well, "exciting" depends on your * point of view and level of experience, I guess. */ void loop() { // Place the cursor in the second line of the display and output the current // sensor values. Note that I didn't bother to translate those values to // an actual light level and temperature - I only scaled the light sensor's // output so it looked nicer on the display. // I use hex codes instead of decimal because it's more 31337. lcd_setcursor(0,2); int ldrValue = map(getAnalogValue(SEN_LDR_PIN), 0x050, 0x3ff, 0x000, 0xfff); int trmValue = getAnalogValue(SEN_TRM_PIN); sprintf(buffer, "LDR %03x TRM %03x", ldrValue, trmValue); lcd_string(buffer); // Show the sensor readings for some time ... _delay_ms(TIME_AWAKE); // ... then say that we're sleepy ... lcd_home(); lcd_string("Sleep ..."); _delay_ms(TIME_BEFORE_SLEEP); // ... switch off the LCD and put the processor in deep sleep mode. lcd_light_state(0); set_sleep_mode(SLEEP_MODE_PWR_DOWN); sleep_mode(); // When the button is pressed, the program will resume right here after // the interrupt handler has been executed. A good moment for reactivating // the LCD. lcd_home(); lcd_string("Wake up! "); lcd_light_state(1); }
void lcd_clrscr(void) { lcd_home(); lcd_send_i2c_start(); lcd_send_i2c_byte(0x40); // 0x00 for command, 0x40 for data for (uint16_t i = 0; i < DISPLAYSIZE; i++) { displayBuffer[i] = 0x00; lcd_send_i2c_byte(displayBuffer[i]); // clear display while printing space } lcd_send_i2c_stop(); lcd_home(); }
int8_t Fan_State_Dur(uint8_t fan, int8_t input){ // Wert bearbeiten? if (input == MENU_INPUT_PUSH) { Fan_edit ^= 1; eeprom_write_byte((void*) &Fan_fansE[fan].dur, Fan_fans[fan].dur); } if (Fan_edit && (input == MENU_INPUT_DOWN)) { Fan_fans[fan].dur = (Fan_fans[fan].dur < FAN_DUR_MAX) ? (Fan_fans[fan].dur+1) : (FAN_DUR_MAX); } if (Fan_edit && (input == MENU_INPUT_UP)) { Fan_fans[fan].dur = (Fan_fans[fan].dur > FAN_DUR_MIN) ? (Fan_fans[fan].dur-1) : (FAN_DUR_MIN); } // Ausgabe lcd_clear(); lcd_home(); if (Fan_edit) lcd_data('*'); else lcd_data('>'); lcd_string_P(MENU_STR_DURATION); lcd_number(Fan_fans[fan].dur, 2, ' '); lcd_string_P(MENU_STR_MIN); lcd_setcursor(0, 2); lcd_data(' '); lcd_string_P(MENU_STR_BACK); return Fan_edit; }
int8_t Fan_State_Humi(uint8_t fan, int8_t input) { // Wert bearbeiten? if (input == MENU_INPUT_PUSH) { Fan_edit ^= 1; eeprom_write_byte((void*) &Fan_fansE[fan].humi, Fan_fans[fan].humi); } if (Fan_edit && (input == MENU_INPUT_DOWN)) { Fan_fans[fan].humi = (Fan_fans[fan].humi < FAN_HUMI_MAX) ? (Fan_fans[fan].humi+1) : (FAN_HUMI_MAX); } if (Fan_edit && (input == MENU_INPUT_UP)) { Fan_fans[fan].humi = (Fan_fans[fan].humi > FAN_HUMI_MIN) ? (Fan_fans[fan].humi-1) : (FAN_HUMI_MIN); } // Ausgabe lcd_clear(); lcd_home(); if (Fan_edit) lcd_data('*'); else lcd_data('>'); lcd_string_P(MENU_STR_HUMIDITY); lcd_number(Fan_fans[fan].humi, 2, ' '); lcd_data('%'); lcd_setcursor(0, 2); lcd_data(' '); lcd_string_P(MENU_STR_ONTIME); lcd_number(Fan_fans[fan].timeH, 2, ' '); lcd_data(':'); lcd_number(Fan_fans[fan].timeM, 2, '0'); return Fan_edit; }
void main() { int tag; //stores the RFID ID tag number float dist; int ovf = 0; int count = 0; store(); if (init()) pm2_pstr("System Checksum Successful!\r\n"); startup_message(); //rfid read printf_fast("Present RFID Tag"); pm2_pstr("Please Present Allowable RFID Tag\r\n"); tag = check_RFID(); pm2_pint16u(tag); pm2_pstr(" = "); print_tag(tag); //prints the name of the tag, which is matched to the number being sent pm2_pstr(" RFID tag was detected\r\nNow Starting Central Operational Loop\r\n"); lcd_home(); lcd_clear(); gps_to_xbee(1); //Enable GPS->Xbee //Central Operational loop CCL while(1) { dist = getdist_Maxbot(); inchtolcd(dist); //printf("hello\r\n"); pm2_pint16u(dist); pm2_pstr("\"\r\n"); if(((int)dist) < 26) { EMICinit(7, 4, 0); EMICspeak('S'); EMICspeak('t'); EMICspeak('o'); EMICspeak('p'); EMICnull(); } } }
int main() { // start up the LCD lcd_init(); fdev_setup_stream(&lcd_stream, lcd_putchar, 0, _FDEV_SETUP_WRITE); lcd_home(); // start up the Analog to Digital Converter adc_init(); // configure the stepper controller stepper_init(); syringe_off(); // start up the serial port uart_init(); fdev_setup_stream(&uart_stream, uart_putchar, uart_getchar, _FDEV_SETUP_RW); stdin = stdout = &uart_stream; // Initialize state machine current_state = STATE_IDLE; current_command = COMMAND_NONE; current_command_state = CMD_STATE_COMMAND; value_str_i = 0; target_pressure = 512; while(1) { poll(); } return 0; }
void stop(void) //beginning of stop function { lcd_clear(); //clear LCD display lcd_home(); //set cursor of LCD to the first character position lcd_printf("Stopped"); //print "Stopped" on LCD display PORTA=0; //stop motors }
void lcd_init(const lcd_def *def) { // Set GPIO clock if (def->port == GPIOA) { RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE); } else if (def->port == GPIOB) { RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOB, ENABLE); } else if (def->port == GPIOC) { RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOC, ENABLE); } else if (def->port == GPIOD) { RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOD, ENABLE); } else if (def->port == GPIOE) { RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOE, ENABLE); } else if (def->port == GPIOF) { RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOF, ENABLE); } // Initialize GPIO pins GPIO_InitTypeDef gpio_init; gpio_init.GPIO_Pin = def->pin_register_select | def->pin_enable | def->pin_d4 | def->pin_d5 | def->pin_d6 | def->pin_d7; gpio_init.GPIO_Mode = GPIO_Mode_OUT; gpio_init.GPIO_OType = GPIO_OType_PP; gpio_init.GPIO_Speed = GPIO_Speed_10MHz; gpio_init.GPIO_PuPd = GPIO_PuPd_NOPULL; GPIO_Init(def->port, &gpio_init); // wait for initialization sleep_ms(30); // select 4-bit interface _lcd_set_nibble(def, 2); sleep_ms(20); // init _lcd_send_command(def, 0x28); // 4 bit mode, 2 lines, 5x7 glyph _lcd_send_command(def, 0x0c); // display with no cursor, no blink _lcd_send_command(def, 0x06); // automatic increment, no display shift lcd_home(def); lcd_clear(def); }
void disp_show_buf(char *buf) { uint8_t i; lcd_clear(); lcd_home(); for(i=0;i<16;i++)lcd_data(buf[i]); lcd_setcursor(0,2); for(;i<32;i++)lcd_data(buf[i]); }
void right(void) //beginning of right function { lcd_clear(); //clear LCD display lcd_home(); //set cursor of LCD to the first character position lcd_printf("Right"); //print "Right" on LCD display PORTA=0; //stop motors for 20 milliseconds delay_ms(20); PORTA=0b00000001; //stop right motor and turn left motor forward }
void backward(void) //beginning of backward function { lcd_clear(); //clear LCD display lcd_home(); //set cursor of LCD to the first character position lcd_printf("Reverse"); //print "Reverse" on LCD display PORTA=0; //stop motors for 20 milliseconds delay_ms(20); PORTA=0b00001010; //turn both motors backward }
int8_t Menu_Version(int8_t input) { lcd_clear(); lcd_home(); lcd_string_P(MENU_STR_VER); lcd_data(':'); lcd_setcursor(0, 2); lcd_string_P(GITVERSION); return 0; }
//move cursor to row r(0/1), column c(0-15) void lcd_set_cursor(int r, int c) { char addr = 0; lcd_home(); if(r != 0) addr |= LINE2; if(c<=0x0F) addr += c; char cmd[] = {0x80, DDRAM_SET | addr}; i2c_transmitinit(LCD_ADDR,2,cmd); wait_for_transfer(); }
void Hello() { lcd_swrite_P(PSTR("MPPT BOOST CONTR")); lcd_gotoxy(0,1); uint8_t count = 0; for (count = 0; count < 16; count++) { lcd_swrite("+"); _delay_ms(50); } _delay_ms(500); lcd_clear(); lcd_home(); lcd_swrite_P(PSTR("DESIGNED BY:")); lcd_gotoxy(0,1); lcd_swrite_P(PSTR("T. SZAFRANSKI")); _delay_ms(500); lcd_clear(); lcd_home(); }
void lcd_define_letter(uint8_t id, uint8_t* data) { unsigned char n; // set CGRAM adress uint8_t instr=0b01000000 | (((id-1)*8)&0b00111111); lcd_command(instr); for(n=0; n<8; n++) { lcd_data(data[n]); } // leave CGRAM, by setting moving cursor home lcd_home(); }
int8_t Fan_State_Back(uint8_t fan, int8_t input) { lcd_clear(); lcd_home(); lcd_data(' '); lcd_string_P(MENU_STR_DURATION); lcd_number(Fan_fans[fan].dur, 2, ' '); lcd_string_P(MENU_STR_MIN); lcd_setcursor(0, 2); lcd_data('>'); lcd_string_P(MENU_STR_BACK); return 0; }
/******************************************* * Main */ int main(void) { uint32_t i; uint8_t d1 = 0; int8_t delta = +1; // Step for testing clock_init(); gpio_setup(); tim_setup(); i2c_setup(); lcd_init(); lcd_seekto(1, 0 ); lcd_writes("................"); while (1) { // Blink gpio_toggle(GPIOB, GPIO1); // Put chars to LCD //lcd_putchar(' ' + d1); lcd_home(); lcd_writes("Count "); lcd_write_uint(d1, 3); if( d1 % 10 == 0 ) { lcd_seekto(1, d1 / 10 ); lcd_writes(".<^^>."); } // Spinwait s bit for (i = 0; i < ( 20 * 72000 ); i++) { __asm__("nop"); } // Sweep PWM d1 += delta; // Pingpong if( d1 >= 100 ) delta = -1; else if( d1 <= 0 ) delta = +1; pwm_set( d1 ); } // Never reached return 0; }
void initAll(){ SysTick_Config(SystemCoreClock / 1000); lcd_init(); lcd_home(); lcd_cls(); initPWM(PWM_TIME_PERIOD); setServoAngle(0,0); UARTInit(BAUD_RATE); ds1307Init(); eeprom_24aaInit(); eeprom24aaMemoryCheck(); initButtons(); }
//!Function To Print Any input value upto the desired digit on LCD void lcd_print (char row, char coloumn, unsigned int value, int digits) { unsigned char flag=0; if(row==0||coloumn==0) { lcd_home(); } else { lcd_cursor(row,coloumn); } if(digits==5 || flag==1) { million=value/10000+48; lcd_wr_char(million); flag=1; } if(digits==4 || flag==1) { temp = value/1000; thousand = temp%10 + 48; lcd_wr_char(thousand); flag=1; } if(digits==3 || flag==1) { temp = value/100; hundred = temp%10 + 48; lcd_wr_char(hundred); flag=1; } if(digits==2 || flag==1) { temp = value/10; tens = temp%10 + 48; lcd_wr_char(tens); flag=1; } if(digits==1 || flag==1) { unit = value%10 + 48; lcd_wr_char(unit); } if(digits>5) { lcd_wr_char('E'); } }
// PURPOSE: Initialize LCD to 4 bit I/O mode void HD44780::lcd_init() { // configure all port bits as output (LCD data and control lines on different ports LCD_DDR(LCD_RS_PORT) |= _BV(LCD_RS_PIN); LCD_DDR(LCD_E_PORT) |= _BV(LCD_E_PIN); LCD_DDR(LCD_4BIT_D4_PORT) |= _BV(LCD_4BIT_D4_PIN); LCD_DDR(LCD_4BIT_D5_PORT) |= _BV(LCD_4BIT_D5_PIN); LCD_DDR(LCD_4BIT_D6_PORT) |= _BV(LCD_4BIT_D6_PIN); LCD_DDR(LCD_4BIT_D7_PORT) |= _BV(LCD_4BIT_D7_PIN); // wait 25ms or more after power-on fcpu_delay_us(25000); // initial write to lcd is 8bit LCD_4BIT_D5_PORT |= _BV(LCD_4BIT_D5_PIN); // _BV(LCD_FUNCTION)>>4; LCD_4BIT_D4_PORT |= _BV(LCD_4BIT_D4_PIN); // _BV(LCD_FUNCTION_8BIT)>>4; lcd_toggle_e(); fcpu_delay_us(2000); //2000 // delay, busy flag can't be checked here // repeat last command lcd_toggle_e(); fcpu_delay_us(64); //64 // delay, busy flag can't be checked here // now configure for 4bit mode LCD_4BIT_D4_PORT &= ~_BV(LCD_4BIT_D4_PIN); // LCD_FUNCTION_4BIT_1LINE>>4 lcd_toggle_e(); fcpu_delay_us(2000); // some displays need this additional delay // set 4 bit IO lcd_instr(LCD_FUNCTION_4BIT_2LINES); // 4-bit interface, dual line, 5x7 dots lcd_toggle_e(); fcpu_delay_us(2000); // some displays need this additional delay lcd_instr(LCD_ENTRY_INC_);//cursor move right, no shift display lcd_toggle_e(); fcpu_delay_us(2500); // some displays need this additional delay lcd_instr(LCD_DISP_ON);// display on, cursor off, blink char off lcd_toggle_e(); fcpu_delay_us(2500); // some displays need this additional delay lcd_home();//set cursor to home and clear the cursor }
int init(void) { fiftymsdelay(); //allows time for the 82c55 chips to start up after restart p82c55_abc_config = 128; //port a, b, and c are all outputs p82c55_def_config = 128; //ports d, e, f are all aoutputs port_a = 255; //port a is all high port_b = 0; //all port b is clear to inhibit GPS->Xbee //Since both select pins are cleared for the 2G circuit on the 74LS139 chip //the GPS signal is routed to the 2Y0 pins. WHen port_b = 3 , both select //pins are set, causing the GPS signal to goto the 2Y3 pin, which is the xbee //470-Ohm Pull downs are connected to PB.0 and PB.1 because at system reset //the voltage on each pin was around 1.2V, which activated the 74LS139 chip, //which bridged the GPS->Xbee //Ensure all Quasi Pins are configured correctly MD_A = 1; MD_B = 1; MD_G = 1; SONAR_PWM = 1; SONAR_RX = 0; //Disable the sonar COMP_PWM = 1; RFID_EN = 1; EMIC_BUSY = 1; EMICreset(); lcd_init(); lcd_home(); lcd_clear(); //print_to_lcd = 1; //xbee_reset(); fiftymsdelay(); port_e = 254; return 1; }
int main(void) { DDRB = 0x0F; int keyboardPushed = 0; int confirmed = 0; int col = 0; int keyIndex = -100; int keyboard[16] = { 7, 8, 9, 47, 4, 5, 6, 42, 1, 2, 3, 45, -1, 0, -2, 43 }; uint8_t columnIndexes[4] = { 0b11111110, 0b11111101, 0b11111011, 0b11110111 }; lcd_init(); lcd_clrscr(); lcd_home(); while (1) { PORTB = columnIndexes[col]; keyboardPushed = isKeyboardPushed(); keyIndex = getKeyIndex(col); if (keyIndex == -100) { displayValues(); } if (keyboardPushed == 1 && confirmed == 0 && keyIndex != -100) { confirmed = 1; keyHandler(keyboard[keyIndex]); } else if (keyboardPushed == 0 && confirmed == 1) { confirmed = 0; } _delay_ms(25); if (keyboardPushed == 0 && ++col==4) { col=0; } } }
/******************************************************************************* * PRIVATE FUNCTION: lcd_1stline_msg * * PARAMETERS: * ~ csz_string - The null terminated string to display on 1st line * * RETURN: * ~ void * * DESCRIPTIONS: * clear LCD on 1st line (upper row) and display message from home * *******************************************************************************/ void lcd_1stline_msg(const char* csz_string) { unsigned char i = 0; lcd_home(); lcd_putstr(csz_string); while (*csz_string != '\0') { i++; csz_string++; } if(i < 16) { for(; i<16;i++) { lcd_putchar(' '); } } }
/* * This function is called once right after the controller starts up. This * is where the initialization functions of the different libraries are called. */ void setup() { lcd_init(); sensors_init(); // This one doesn't only set the interrupt handler, it also configures // the IO pins used for the wake-up button and for switching power to // the LCD backlight. I simply had no idea how to name that one. interrupt_init(); // Switch off the internal LED on pin13/PB7 in order to save power. That // probably doesn't help much, but every mA counts. :) DDRB |= _BV(PB7); PORTB &= ~_BV(PB7); // Switch on the LCD and print the greeting line. Actually it doesn't only // control the backlight but also the contrast. lcd_light_state(1); lcd_home(); lcd_string("Started! "); }
int8_t Fan_State_Ctrl(uint8_t fan, int8_t input) { // Wert bearbeiten? if (input == MENU_INPUT_PUSH) { Fan_edit ^= 1; eeprom_write_byte((void*) &Fan_fansE[fan].ctrl, Fan_fans[fan].ctrl); } if (Fan_edit && (input == MENU_INPUT_DOWN)) { Fan_fans[fan].ctrl = (Fan_fans[fan].ctrl < FAN_CTRL_MAX) ? (Fan_fans[fan].ctrl+1) : (FAN_CTRL_MAX); } if (Fan_edit && (input == MENU_INPUT_UP)) { Fan_fans[fan].ctrl = (Fan_fans[fan].ctrl > FAN_CTRL_MIN) ? (Fan_fans[fan].ctrl-1) : (FAN_CTRL_MIN); } // Ausgabe lcd_clear(); lcd_home(); if (Fan_edit) lcd_data('*'); else lcd_data('>'); lcd_string_P(MENU_STR_CTRL); switch (Fan_fans[fan].ctrl) { case FAN_CTRL_OFF: lcd_string_P(MENU_STR_CTRL_OFF); break; case FAN_CTRL_HUMI: lcd_string_P(MENU_STR_CTRL_HUMI); break; case FAN_CTRL_TIME: lcd_string_P(MENU_STR_CTRL_TIME); break; case FAN_CTRL_REP: lcd_string_P(MENU_STR_CTRL_REP); break; } lcd_setcursor(0, 2); lcd_data(' '); lcd_string_P(MENU_STR_HUMIDITY); lcd_number(Fan_fans[fan].humi, 2, ' '); lcd_data('%'); return Fan_edit; }
int8_t Fan_State_On(uint8_t fan, int8_t input) { // Wert bearbeiten? if (input == MENU_INPUT_PUSH) { Fan_edit ^= 1; eeprom_write_byte((void*) &Fan_fansE[fan].timeM, Fan_fans[fan].timeM); eeprom_write_byte((void*) &Fan_fansE[fan].timeH, Fan_fans[fan].timeH); } if (Fan_edit && (input == MENU_INPUT_DOWN)) { if (Fan_fans[fan].timeM < 55) { Fan_fans[fan].timeM += 5; } else if (Fan_fans[fan].timeH < 23) { Fan_fans[fan].timeM = 0; Fan_fans[fan].timeH++; } } if (Fan_edit && (input == MENU_INPUT_UP)) { if (Fan_fans[fan].timeM > 0) { Fan_fans[fan].timeM -= 5; } else if (Fan_fans[fan].timeH > 0) { Fan_fans[fan].timeM = 55; Fan_fans[fan].timeH--; } } // Ausgabe lcd_clear(); lcd_home(); if (Fan_edit) lcd_data('*'); else lcd_data('>'); lcd_string_P(MENU_STR_ONTIME); lcd_number(Fan_fans[fan].timeH, 2, ' '); lcd_data(':'); lcd_number(Fan_fans[fan].timeM, 2, '0'); lcd_setcursor(0, 2); lcd_data(' '); lcd_string_P(MENU_STR_REPEAT); lcd_number(Fan_fans[fan].rep, 2, ' '); lcd_data('h'); return Fan_edit; }
/* * Internal - scroll the text on the screen up one * line. */ static void lcd_scroll(void) { int y, x; lcd_home(); /* Home cursor */ /* Scroll up text */ for ( y=0; y<lcd_lines-1; ++y ) for ( x=0; x<lcd_cols; ++x ) { lcd_buf[y][x] = lcd_buf[y+1][x]; lcd_putraw(lcd_buf[y][x]); } /* Blank the last line */ for ( x=0; x<lcd_cols; ++x ) { lcd_buf[lcd_lines-1][x] = ' '; lcd_putraw(' '); } lcd_restore(); /* Restore cursor */ }
void getTemp() { uint16_t last_sample = 0; double this_temp; double temp_avg; uint16_t i; temp_avg = 0.0; for (i=0; i<500; i++) { last_sample = adc_read(); this_temp = sampleToFahrenheit(last_sample); temp_avg = temp_avg + this_temp/500.0; } double c = fahrenheitToCelsius(temp_avg); double k = celsiusToKelvin(c); // write message to LCD lcd_init(); FILE lcd_stream = FDEV_SETUP_STREAM(lcd_putchar, 0, _FDEV_SETUP_WRITE); lcd_home(); lcd_write_string(PSTR("ADC: ")); lcd_write_int16(last_sample); lcd_write_string(PSTR(" of 1024 ")); lcd_line_two(); fprintf_P(&lcd_stream, PSTR("%.2f"), temp_avg); lcd_write_data(0xdf); lcd_write_string(PSTR("F")); lcd_line_three(); fprintf_P(&lcd_stream, PSTR("%.2f"), c); lcd_write_data(0xdf); lcd_write_string(PSTR("C")); lcd_line_four(); fprintf_P(&lcd_stream, PSTR("%.2f"), k); lcd_write_data(0xdf); lcd_write_string(PSTR("K")); }