int main(void) { RCC_Configuration(); RCC_ClocksTypeDef RCC_Clocks; RCC_GetClocksFreq(&RCC_Clocks); EnableClock(); //LCD_GLASS_Configure_GPIO(); //LCD_GLASS_Init(); SysTick_Config((RCC_Clocks.SYSCLK_Frequency / 2) / 1000); // Cannot exceed 16,777,215 /* Set SysTick Preemption Priority, it's a system handler rather than a regular interrupt */ //NVIC_SetPriority(SysTick_IRQn, 0x04); lcdInit(); lcdClear(); lcdXY( 2, 5 ); lcdStr( "Test"); //lcdBender(); // init rtc RTC_InitTypeDef rtcInit; rtcInit.RTC_HourFormat = RTC_HourFormat_24; rtcInit.RTC_AsynchPrediv = 0x7F; rtcInit.RTC_SynchPrediv = 0xFF; RTC_Init(&rtcInit); RTC_TimeTypeDef RTC_TimeStructure; RTC_DateTypeDef RTC_DateStructure; usart_init(); SetRTCClock(); GPIO_InitTypeDef gpio_btn; gpio_btn.GPIO_Pin = GPIO_Pin_0; gpio_btn.GPIO_Mode = GPIO_Mode_IN; gpio_btn.GPIO_PuPd = GPIO_PuPd_UP; GPIO_Init(GPIOA, &gpio_btn); int prevSecond = -1; while (1) { //uint8_t __status = GPIO_ReadInputDataBit(GPIOA, GPIO_Pin_0); if (GPIO_ReadInputDataBit(GPIOA, GPIO_Pin_0) == 0x00 && !_sent) { _sent = 1; mini_snprintf( strDisp, 22, "20%02d/%02d/%02d %02d:%02d:%02d Hallo !!!", RTC_DateStructure.RTC_Year, RTC_DateStructure.RTC_Month, RTC_DateStructure.RTC_Date, RTC_TimeStructure.RTC_Hours, RTC_TimeStructure.RTC_Minutes, RTC_TimeStructure.RTC_Seconds); SendSMS("0836325001",strDisp); } if (GPIO_ReadInputDataBit(GPIOA, GPIO_Pin_0) != 0x00 && _sent) { _sent = 0; } RTC_GetTime(RTC_Format_BIN, &RTC_TimeStructure ); RTC_GetDate(RTC_Format_BIN, &RTC_DateStructure); if ( RTC_TimeStructure.RTC_Seconds != prevSecond ) { lcdClear(); mini_snprintf( strDisp, 11, "20%02d/%02d/%02d", RTC_DateStructure.RTC_Year, RTC_DateStructure.RTC_Month, RTC_DateStructure.RTC_Date); lcdXY( 0, 0 ); lcdStr( strDisp); mini_snprintf( strDisp, 10, "%02d:%02d:%02d", RTC_TimeStructure.RTC_Hours, RTC_TimeStructure.RTC_Minutes, RTC_TimeStructure.RTC_Seconds ); lcdXY( 0, 1 ); lcdStr( strDisp); //LCD_GLASS_Clear(); //LCD_GLASS_DisplayString( strDisp ); prevSecond = RTC_TimeStructure.RTC_Seconds; } /*if ( usart_available() ) // data available { //usart_print( "Data Available: " ); uint8_t ch = usart_read(); //usart_write(ch); //usart_print( "\r\n" ); SendSMS("836325001","Wynand"); }*/ } return 0; }
void lcdTest(void) { for(int y=0; y<240; y++) { lcdPixel(0, y, COLOR_WHITE); lcdPixel(319, y, COLOR_WHITE); } for(int x=0; x<320; x++) { lcdPixel(x, 0, COLOR_WHITE); lcdPixel(x, 239, COLOR_WHITE); } lcdStr(2, 2, "Hello world!", COLOR_GREEN, COLOR_BLUE); return; writeReg(0x004f, 0); // Set GDDRAM X address counter writeReg(0x004e, 0); // Set GDDRAM Y address counter setRS(0); writeLcd(0x22); // RAM data write register setRS(1); for(int y=0; y<240; y++) { for(int x=0; x<320; x++) { writeLcd(lcdColor(y, x, 0)); /* if((y & 0x10) ^ (x & 0x10)) { writeLcd(lcdColor(0xff, 0, 0)); } else { writeLcd(lcdColor(0, 0xff, 0)); } */ } } }
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 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); }
int main() { // 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; lcdInit(); adcInit(); readGlobalSettings(); toneCount = 5*F_CPU/tone; initInterrupts(); initPLL(); sprintf(str, "PE1JPD 23cm v%s", version); lcdCursor(0,0); lcdStr(str); _delay_ms(500); for (;;) { switch(mode) { case VFO: mode = Vfo(); writeGlobalSettings(); break; case MEMORY: mode = Memory(); writeGlobalSettings(); break; case SPECTRUM: mode = Spectrum(); break; case MENU: mode = Menu(mode); break; case MEMORY_MENU: mode = MemoryMenu(mode); break; default: mode = VFO; break; } } }