void initLcd() { int i,j; // 4 bits mode, 2 lines lcdCmd(0x20); _delay_ms(10); lcdCmd(0x20); _delay_ms(10); // cursor shift right, text no shift lcdCmd(0x18); _delay_ms(20); // display on, no cursor, no blink lcdCmd(0x0c); _delay_ms(20); // shift mode lcdCmd(0x06); _delay_ms(20); // home lcdCmd(0x02); _delay_ms(20); // clear display lcdCmd(0x01); _delay_ms(20); // define custom chars lcdCmd(0x40); for (i=0; i<3; i++) { for (j=0; j<8; j++) { lcdData(smeter[i][j]); } } }
void stopWatchReload(void) { char min[4]; char sec[4]; char down[4]; if(swMode==1) { if(sw_down==99) { if(sw_sec==59) { if(sw_min==59) { } else { sw_down=0; sw_sec=0; sw_min++; } } else { sw_down=0; sw_sec++; } } else { sw_down++; } } lcdCmd(0x80);///カーソルを先頭に移動 ByteToStr(sw_min,min); if(sw_min<10) { min[1]='0'; } lcd_str(1,min); ByteToStr(sw_sec,sec); if(sw_sec<10) { sec[1]='0'; } sec[0]=':'; lcd_str(0,sec); ByteToStr(sw_down,down); if(sw_down<10) { down[1]='0'; } down[0]='.'; lcd_str(0,down); }
void lcdInit(void) { _lcd_init(); lcdPrepareWrite(); CMD_SLEEP_MS(16); // 16 ms lcdWriteData(3); // 8bit mode pulse_e(); CMD_SLEEP_MS(5); // 4992 us pulse_e(); // Repeat 8bit mode CMD_SLEEP_MS(1); // 64 us pulse_e(); // Third repeat CMD_SLEEP_MS(1); // 64 us // lcdWriteData(2); // Change to 4bit mode (0x20) // pulse_e(); lcdCmd(LCD_CMD_INIT8); /* lcdCmd(0x24); lcdCmd(0x09); lcdCmd(0x20); */ lcdCmd(0x08); lcdCmd(0x01); lcdCmd(0x06); lcdCmd(0x0C); lcdCmd(0x80); /* lcdCmd(0x02); */ /* lcdCmd(LCD_SET_DM | LCD_DM_DISPLAY_ON); lcdCmd(LCD_SET_INCREMENT_MODE); */ #ifdef WRAPEN cur_col = 0; cur_row = 0; #endif }
void displaySmeter(int level) { short n = 16; lcdCmd(0xc0); // chars in the full bar are 3 vertical lines while(level>=3 && n>0) { lcdData(2); level -= 3; n--; } // last char 0, 1 or 2 lines switch (level) { case 2: lcdData(1); break; case 1: lcdData(0); break; default: lcdData(' '); break; } // clear any chars to the right while (--n > 0) lcdData(' '); }
/* * Application entry point. */ int main(void) { /* * System initializations. * - HAL initialization, this also initializes the configured device drivers * and performs the board-specific initializations. * - Kernel initialization, the main() function becomes a thread and the * RTOS is active. */ halInit(); chSysInit(); /* * Activates the serial driver 2 using the driver default configuration. */ sdStart(&SD2, NULL); /* * This initialization requires the OS already active because it uses delay * APIs inside. */ lcdInit(); lcdCmd(LCD_CLEAR); lcdPuts(LCD_LINE1, " ChibiOS/RT "); lcdPuts(LCD_LINE2, " Hello World! "); /* * Starts the LED blinker thread. */ chThdCreateStatic(waThread1, sizeof(waThread1), NORMALPRIO, Thread1, NULL); while(TRUE) { if (!palReadPad(IOPORT1, PORTA_BUTTON1)) TestThread(&SD2); chThdSleepMilliseconds(500); } }
void lcdShiftTextLeft() { lcdCmd(0x18); }
void lcdDecrementCursor() { lcdCmd(0x10); }
void lcdShiftTextRight() { lcdCmd(0x1C); }
void lcdRowTwoHome() { lcdCmd(0xC0); }
void lcdIncrementCursor() { lcdCmd(0x14); }
void singleHeight(void) { lcdCmd(0x38); }///N=1/DH=0
void lcdHome() { lcdCmd(0x80); }
int main() { long int savedfreq = 0; int s, c; unsigned char sw=0; // PORTB output for LCD DDRB = 0xff; PORTB = 0xff; #ifdef BOARD2 // PORTC PC0-4 output, PC5 input DDRC = 0x1f; PORTC = 0x00; sbi(PORTC, MUTE); #endif #ifdef BOARD1 // PORTC PC0,2-5 output, PC1 input DDRC = 0x3d; PORTC = 0x00; sbi(PORTC, MUTE); #endif // PORTD is input with pullup DDRD = 0x00; PORTD = 0xff; initLcd(); initADC(); // set reference freq fref = eeprom_read_word((unsigned int *)0x00); if (fref < 2000 || (fref % 100) != 0) { fref = 12000; eeprom_write_word((unsigned int *)0x00, fref); } // read squelch level from eeprom muteval = eeprom_read_word((unsigned int *)0x0c); if (muteval < 0 || muteval > 100) { muteval = 0; eeprom_write_word((unsigned int *)0x0c, muteval); } // read last frequency from eeprom freq = eeprom_read_dword((unsigned long int *)0x10); if (freq < 1240000UL || freq > 1300000UL) { freq = 1298375UL; eeprom_write_dword((unsigned long int *)0x10, freq); } // read shift from eeprom shift = eeprom_read_word((unsigned int *)0x18); if (shift < 60000UL || shift > 60000UL) { shift = -28000UL; eeprom_write_word((unsigned int *)0x18, shift); } // read tone (*10) from eeprom tone = eeprom_read_word((unsigned int *)0x1c); if (tone < 650 || tone > 1500) { tone = 650; eeprom_write_word((unsigned int *)0x1c, tone); } initInterrupts(); initPLL(freq - IF); update(); sprintf(str, "JPD 23cm v%s", version); lcdCmd(0x80); lcdStr(str); _delay_ms(500); for (;;) { lcdCmd(0x80); lcdStr("VFO "); lcdCmd(0xc0); lcdStr(" "); update(); for (;;) { // read switches on PORTD sw = PIND; // switch from tx to rx?? if (tx && (sw & (1<<PTT) )) { cbi(PORTC, TXON); // switch TX off tx = FALSE; // TCCR2A &= ~(1<<COM2A1); update(); } // switch from rx to tx? else if (!tx && !(sw & (1<<PTT) )) { tx = TRUE; displaySmeter(0); // switch TX on sbi(PORTC, TXON); sbi(PORTC, MUTE); // if (tone > 650) { // TCCR2A |= (1<<COM2A1); // } update(); } if (!tx) { s = readSmeter(); displaySmeter(s); if (s > muteval) cbi(PORTC, MUTE); else sbi(PORTC, MUTE); } // switch shift off if ( (shiftSwitch == TRUE) && (sw & (1<<SHIFTKEY) )) { shiftSwitch = FALSE; update(); } // switch shift on else if ( (shiftSwitch == FALSE) && !(sw & (1<<SHIFTKEY) )) { shiftSwitch = TRUE; update(); } // save vfo frequency in eeprom after ~2 secs inactivity if (tick > 200) { if (freq != savedfreq) { eeprom_write_dword((unsigned long int *)0x10, freq); savedfreq = freq; } } // handle encoder pulses c = handleRotary(); if (c!=0) { if (c>0) { freq += step; } else { freq -= step; } tick = 0; update(); } if (rotaryPushed()) { doMenu(); break; } } } }
void lcdRowTwoHome() { lcdCmd(0xC0); _delay_us(3300); }
void doMenu() { int s, c=1, quit = FALSE; menu = 0; do { // first time and at an update display the value if (c!=0) { lcdCmd(0x80); lcdStr(menuStr[menu]); switch (menu) { case MUTEVAL: sprintf(str, " %d ", muteval); break; case FSHIFT: sprintf(str, " %+2ld MHz ", shift/1000); break; case CTCSS: if (tone>650) sprintf(str, " %d.%01d Hz ", tone/10, tone-(tone/10)*10 ); else sprintf(str, " off "); break; case FREF: sprintf(str, " %d.%01d MHz ", fref/1000, fref-(fref/1000)*1000); break; default: sprintf(str, " "); break; } lcdCmd(0xc0); lcdStr(str); } // handle encoder c = handleRotary(); if (c!=0) { menu += c; if (menu>4) menu = 0; if (menu<0) menu = 4; } if (rotaryPushed()) { lcdCmd(0x80); lcdData(' '); lcdCmd(0xc0); lcdData('>'); switch (menu) { case MUTEVAL: lcdCmd(0xc5); for (;;) { c = handleRotary(); if (c!=0) { if (c>0) { if (++muteval > 100) muteval = 100; } else { if (--muteval < 0) muteval = 0; } lcdCmd(0xc0); sprintf(str, "> %d ", muteval); lcdStr(str); s = readSmeter(); if (s > muteval) cbi(PORTC, MUTE); else sbi(PORTC, MUTE); } if (rotaryPushed()) { eeprom_write_word((unsigned int *)0x0c, muteval); break; } } break; case FSHIFT: lcdCmd(0xc5); for (;;) { c = handleRotary(); if (c!=0) { if (c>0) { shift += 1000; if (shift>60000) shift = 60000; } else { shift -= 1000; if (shift<-60000) shift = -60000; } lcdCmd(0xc0); sprintf(str, "> %+2ld MHz ", shift/1000); lcdStr(str); } if (rotaryPushed()) { eeprom_write_word((unsigned int *)0x18, shift); break; } } break; case CTCSS: lcdCmd(0xc5); for (;;) { c = handleRotary(); if (c!=0) { if (c>0) { tone++; } else { tone--; if (tone<650) tone = 650; } lcdCmd(0xc0); if (tone>650) sprintf(str, "> %d.%01d Hz ", tone/10, tone-(tone/10)*10 ); else sprintf(str, "> off "); lcdStr(str); toneCount = 5*F_CPU/tone; // *10/2 // T1 counter, Hz*10, 16 samples/period // toneCount = 10*F_CPU/(tone*16); } if (rotaryPushed()) { eeprom_write_word((unsigned int *)0x1c, tone); break; } } break; case FREF: lcdCmd(0xc5); for (;;) { c = handleRotary(); if (c!=0) { if (c>0) { fref += 100; } else { fref -= 100; } lcdCmd(0xc0); sprintf(str, "> %d.%01d MHz ", fref/1000, fref-(fref/1000)*1000 ); lcdStr(str); } if (rotaryPushed()) { eeprom_write_word((unsigned int *)0x00, fref); initPLL(freq - IF); break; } } break; case BACK: quit = TRUE; default: break; } lcdCmd(0x80); lcdData('>'); lcdCmd(0xc0); lcdData(' '); } } while (!quit); }
void lcdHome() { lcdCmd(0x80); _delay_us(3300); }
/* * Writes a string on the LCD at an absolute address. */ void lcdPuts(uint8_t pos, char *p) { lcdCmd(LCD_SET_DDRAM_ADDRESS | pos); while (*p) lcdPutc(*p++); }
void lcdClear(void) { lcdCmd(0x01); }
void doubleHeight(void) { lcdCmd(0x34); }///N=0/DH=1
void AQM1248A::initLCD() { lcdCmd(0xAE); //Display = OFF lcdCmd(0xA0); //ADC = normal lcdCmd(0xC8); //Common output = revers lcdCmd(0xA3); //LCD bias = 1/7 //内部レギュレータON lcdCmd(0x2C); delay(2); lcdCmd(0x2E); delay(2); lcdCmd(0x2F); //コントラスト設定 lcdCmd(0x23); //Vo voltage regulator internal resistor ratio set lcdCmd(0x81); //Electronic volume mode set lcdCmd(0x1C); //Electronic volume register set //表示設定 lcdCmd(0xA4); //Display all point ON/OFF = normal lcdCmd(0x40); //Display start line = 0 lcdCmd(0xA6); //Display normal/revers = normal lcdCmd(0xAF); //Dsiplay = ON }
void lcdClear() { lcdCmd(0x01); _delay_us(3300); }
void clearLcd(void) { // Send command to LCD (0x01) lcdCmd(0x01); }
void lcdOff(void) { lcdCmd(0x08); lcdIsOn = 0; }