void displayFrequency(long int f) { int i; char c; hex2bcd(f); lcdCursor(4,0); for (i=1; i<8; i++) { c = str[i]; if (i==5) { lcdChar('.'); } lcdChar(c); } }
void lcdStr(int x, int y, char* s, lcd_color_t fg, lcd_color_t bg) { char c; while((c = *s++) != 0) { lcdChar(x, y, c, fg, bg); x += FONT_W; } }
void print_i2c_inbuff(){ lcdGoTo(0); lcd_init(); while(!ringbuffer_is_empty()){ lcdChar(ringbuffer_get()); } print_hello_world(); }
void system6_LCD_RINGBUFFER(){ if(state==1){ SSP1CON1bits.SSPEN = 0; // 0 = Disables serial port and configures these pins as I/O port pins lcd_init(); state = 2; } else if(state==2){ lcdGoTo(0); if(!ringbuffer_is_empty()){ lcdChar(ringbuffer_get()); } else { lcdChar('N'); lcdChar('o'); lcdChar('n'); lcdChar('e'); } state = 3; } else if (state ==3){ delay_1MSx(500); LATD ^= 0xFF; delay_1MSx(500); LATD ^= 0xFF; } }
void main(void) { char packet[] = {'T', 'e', 's', 't'}; unsigned char i = 0; unsigned char packet_size = sizeof (packet) / sizeof (packet[0]); unsigned char cArray[10] = {'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J'}; // temporary local array unsigned char writtenArray[10]; // local variables for all test cases and their initialisation unsigned char chData; unsigned char *pReadArray; unsigned char *pWriteArray; unsigned char j = 0; unsigned char i = 0; pReadArray = pWriteArray = writtenArray; /* Configure the oscillator for the device */ ConfigureOscillator(); /* Initialize I/O and Peripherals for application */ InitApp(); // LCD test TRISAbits.RA2 = 0; // our chip select pin needs to be an output so that we can toggle it CS = 1; // set CS pin to high, meaning we are sending any information to the MCP23S17 chip // configure SPI: the MCP23S17 chip's max frequency is 10MHz, let's use 10MHz/64 (Note FOSC=10Mhz, our external oscillator) OpenSPI1(SPI_FOSC_64, MODE_10, SMPEND); // frequency, master-slave mode, sampling type // set LCD pins DB0-DB7 as outputs setIODIR(IODIRB_ADDRESS, 0x00); // set RS and E LCD pins as outputs setIODIR(IODIRA_ADDRESS, 0x00); // RS=0, E=0 setGPIO(IODIRA_ADDRESS, 0x00); // Function set: 8 bit, 2 lines, 5x8 lcdCommand(0b00111111); // Cursor or Display Shift lcdCommand(0b00001111); // clear display lcdCommand(0b00000001); // entry mode lcdCommand(0b00000110); // send characters lcdWriteString((unsigned char *) "Waiting..."); // using the string function lcdGoTo(0x40); // go to line two /*lcdChar('S'); // using the single character function lcdChar('P'); lcdChar('I'); lcdChar(' '); lcdChar('L'); lcdChar('i'); lcdChar('b'); lcdChar('r'); lcdChar('a'); lcdChar('r'); lcdChar('y'); */ /////////////////////////////////////////////////// /* TODO <INSERT USER APPLICATION CODE HERE> */ /* while(1) { i = 0; do { UARTIntPutChar(packet[i++]); } while (i < packet_size); while (!vUARTIntStatus.UARTIntTxBufferEmpty); Delay10KTCYx(1000); } */ TRISD = 0; PORTD = 0; while (1) { /* for (j = 0; j < 100; j++) { i = 0; do { if (vUARTIntStatus.UARTIntTxBufferEmpty) UARTIntPutChar(cArray[i++]); } while (i < 10); } */ if (!(vUARTIntStatus.UARTIntRxError) && !(vUARTIntStatus.UARTIntRxOverFlow) && !(vUARTIntStatus.UARTIntRxBufferEmpty)) { if (UARTIntGetChar(&chData)) { PORTD = chData; lcdChar(chData); } } } }
void lcdWriteString(unsigned char *s) { while (*s) lcdChar(*s++); }
int main() { timerInit(); lcdInit(); DirectionB &= ~(1 << PB7); DirectionD &= ~(1 << PD0) & ~(1 << PD1) & ~(1 << PD2); int sec = 0; int min = 0; int hrs = 0; while (1) { clearDisplay(); cursorPosition( 5, 1); if ( hrs < 10 ) { lcdChar('0'); lcdInteger(hrs); } else { lcdInteger(hrs); } lcdChar(':'); if ( min < 10 ) { lcdChar('0'); lcdInteger(min); } else { lcdInteger(min); } lcdChar(':'); if ( sec < 10 ) { lcdChar('0'); lcdInteger(sec); } else { lcdInteger(sec); } if ( (InputB & (1 << PB7)) != 0 ) { if ( (InputD & (1 << PD2)) != 0 ) { if ( hrs == 23 ) hrs = 0; else hrs++; } else if ( (InputD & (1 << PD1)) != 0 ) { if ( min == 59 ) min = 0; else min++; } } else { sec++; if ( (sec == 60) && (min == 59) && (hrs == 23) ) { sec = 0; min = 0; hrs = 0; } else if ( (sec == 60) && (min == 59) && (hrs < 23) ) { sec = 0; min = 0; hrs++; } else if ( (sec == 60) && (min < 59) ) { sec = 0; min++; } } timerDelay_s(1); } return 0; }
int rxtx() { int s; // read ptt on PORTD int c = PIND; // listen reverse? if (rv) { if (c & (1<<REVERSE)) { lastFreq = 0; rv = FALSE; } } else { if (!(c & (1<<REVERSE))) { lastFreq = 0; rv = TRUE; } } if (tx) { //keep smeter clear s = 0; // switch from tx to rx?? if (c & (1<<PTT) ) { cbi(PORTC, TXON); lastFreq = 0; tx = FALSE; } } else { s = readRSSI(); displaySmeter(s); // switch from rx to tx? if (!(c & (1<<PTT) )) { // clear smeter s = 0; displaySmeter(s); sbi(PORTC, MUTE); sbi(PORTC, TXON); // force update pll lastFreq = 0; tx = TRUE; } } // calc value for ISR toneCount = 5*F_CPU/tone; // freq change or update needed? if (freq != lastFreq) { long int f = freq; if (tx) { f += (long int) shift*1000; setFrequency(f); } else { if (rv) f += (long int)shift*1000; setFrequency(f - IF); } displayFrequency(f); lastFreq = freq; lcdCursor(15,0); if (tx) lcdChar('T'); else lcdChar('R'); } return s; }
void demo() { lcdCls(); for (uint8_t i = 0x20; i <= 128; ++i) { lcdChar(i, LCD_XOR); } lcdUpdate(); _delay_ms(2000); lcdStrPos (3,11); lcdStr_P(PSTR("Free string"), LCD_WHITE); lcdStrPos (22,37); lcdStr_P(PSTR("positioning"), LCD_WHITE); lcdUpdate(); _delay_ms(3000); lcdCls(); lcdStr_P(PSTR("Lines, rectangles, circles."), LCD_BLACK); lcdUpdate(); _delay_ms(1000); lcdNewLine(); lcdStr_P(PSTR("Filled or unfilled."), LCD_BLACK); lcdUpdate(); _delay_ms(1000); lcdNewLine(); lcdStr_P(PSTR("Solid or XORed filling, text."), LCD_BLACK); lcdUpdate(); _delay_ms(5000); lcdRect(0, 0, LCD_Y_RES, LCD_X_RES, LCD_BLACK, LCD_FILL_BLACK); lcdStrPos(36,0); lcdStr_P(PSTR("MENU"), LCD_XOR); lcdRect(5,7,LCD_Y_RES-8, LCD_X_RES-10,LCD_WHITE, LCD_FILL_WHITE ); for (int i = 1; i < 8; ++i) { lcdStrPos(10, i*8); lcdInt(i, LCD_BLACK); lcdStr_P(PSTR(". Sample"), LCD_BLACK); lcdLine(5,8*i-1,LCD_X_RES-10, LCD_HORIZ, LCD_BLACK); } lcdUpdate(); _delay_ms(2000); lcdCircle(LCD_X_RES/2,LCD_Y_RES/2,30, LCD_XOR, LCD_FILL_XOR); lcdUpdate(); _delay_ms(2000); lcdBresenhamLine(0, 0, LCD_X_RES-1, LCD_Y_RES-1, LCD_XOR); lcdUpdate(); _delay_ms(2000); lcdBresenhamLine(0, LCD_Y_RES-1, LCD_X_RES-1, 0, LCD_XOR); lcdUpdate(); _delay_ms(5000); lcdCls(); lcdStr_P(PSTR("Per-pixel horizontal fill speed test in:"), LCD_BLACK);lcdUpdate();lcdNewLine(); _delay_ms(1000); lcdStr_P(PSTR("3..."), LCD_BLACK);lcdUpdate(); _delay_ms(1000); lcdStr_P(PSTR("2..."), LCD_BLACK);lcdUpdate(); _delay_ms(1000); lcdStr_P(PSTR("1..."), LCD_BLACK);lcdUpdate(); _delay_ms(1000); for (uint8_t x = 0; x < LCD_X_RES; ++x) { for (uint8_t y = 0; y < LCD_Y_RES; ++y) { lcdPixel(x,y,LCD_PIXEL_XOR); lcdUpdate(); } } _delay_ms(1000); lcdNewLine(); lcdStr_P(PSTR("Vertical in:"), LCD_XOR);lcdUpdate();lcdNewLine(); _delay_ms(1000); lcdStr_P(PSTR("3..."), LCD_XOR);lcdUpdate(); _delay_ms(1000); lcdStr_P(PSTR("2..."), LCD_XOR);lcdUpdate(); _delay_ms(1000); lcdStr_P(PSTR("1..."), LCD_XOR);lcdUpdate(); _delay_ms(1000); for (uint8_t y = 0; y < LCD_Y_RES; ++y) { for (uint8_t x = 0; x < LCD_X_RES; ++x) { lcdPixel(x,y,LCD_PIXEL_XOR); lcdUpdate(); } } _delay_ms(2000); lcdCls(); lcdStr_P(PSTR("Every pixel was filled with it's XORed value and updated."), LCD_XOR);lcdUpdate(); _delay_ms(5000); lcdCls(); lcdStr_P(PSTR("That's it!"), LCD_XOR); lcdNewLine(); lcdStr_P(PSTR("Thanks!"), LCD_XOR);lcdUpdate(); _delay_ms(5000); }