Example #1
0
/****************************************************************************
* 名    称:AddNewline
* 功    能:液晶写满,添加一行,其他行向上移动
* 入口参数:无
* 出口参数:无
* 说    明: 此函数供putchar2Lcd函数调用,当输出满液晶后,自动向上滚动。
****************************************************************************/
void AddNewline()
{
    char str[17];
    str[16] = 0;
    
    //第二行 移至第一行
    LcdWriteComm(0x90);
    LcdReadData();              //空读取
    for(int i = 0;i<16;i++)
    {
        str[i] = LcdReadData();
    }
    LcdWriteString(0x80,str);
    
    //第三行 移至第二行
    LcdWriteComm(0x88);
    LcdReadData();
    for(int i = 0;i<16;i++)
    {
        str[i] = LcdReadData();
    }
    LcdWriteString(0x90,str);
    
    //第四行 移至第三行
    LcdWriteComm(0x98);
    LcdReadData();
    for(int i = 0;i<16;i++)
    {
        str[i] = LcdReadData();
    }
    LcdWriteString(0x88,str);
    
    //第四行 空白
    LcdWriteString(0x98,"                ");    //十六个空格
}
Example #2
0
/* Configure the pins on the ATmega328p */
void InitDevice() {
    /* Disable all possible devices on the board */
    power_all_disable();

    /* LCD setup */
    /* All PORTB pins are data pins for the LCD screen */
    DDRB = (uint8_t)(-1);

    /* PDO, PD1, and PD3 are all used as control pins for the LCD screen.
     * PD0 is used as the R/S pin, which determines whether the LCD is getting a
     * command or a character
     * PD1 is the Enable pin, which signals the LCD to read the data pins
     * PD3 is the R/W Pin which is used to activate the Busy flag on the LCD and
     * is used for timing
     */
    DDRD |= (_BV(PD0) | _BV(PD1) | _BV(PD3));

    LcdInit();

    /* Display title screen */
    LcdWriteString(TITLE, LCD_LINE_ONE);
    LcdWriteString(NAME, LCD_LINE_TWO);
    _delay_ms(STARTUP_DELAY);

    LcdWriteString(BOOTUP, LCD_LINE_TWO);

    /* Calibration circuit */
    /* PD4 is used to determine if the calibration circuit is active or not */
    DDRD &= ~_BV(PD4); /* Configure PD4 as an input */
    PORTD |= _BV(PD4); /* Pullup PD4 */

    /* Configure the ADC */
    //Currently not implemented
    //power_adc_enable();

    /* Magnetometer set up */
    /* INT0 is attached to the DataReady pin on the magnometer, and will be used
     * to signal that data is ready to be read (obviously).  INT0 is set to go
     * off on a rising edge.
     */
    EIMSK |= _BV(INT0);
    EICRA |= _BV(ISC01) | _BV(ISC00);

    /* Configure TWI */
    power_twi_enable();
    TWCR = _BV(TWEN); /* Enable TWI */ //May not be needed here, but definitely elsewhere
    //Check to see if the magnetometer needs initialization from the ATmega
    //will need init
    //Display "Waiting on data" on line 2
}
Example #3
0
/* It's the main function for the program, what more do you need to know? */
int main() {
    int16_t  Degrees = 0;
    uint8_t  SregSave;
    //int16_t  Correction = 0;

    Degrees = Degrees; //Because it's a warning otherwise, and I don't think I can get rid of it
    DataReady = FALSE;

    /* Setup the ATmega328p */
    InitDevice();

    /* Enable interrupts */
    sei();

    /* Wait till we get data */
    while(!DataReady);

    /* Main loop */
    while(TRUE) {
        /* If there is pending data, process it */
        if(DataReady) {
            SregSave = SREG; /* Preserve the status register */
            /* We want the data retrevial completely performed without interruptions */
            cli();
            //Hand off to a function

            Degrees = ProcessData();

            DataReady = FALSE;

            /* Restore the status register */
            SREG = SregSave;
        }

        //Currently not used, add in later once supplies are received
        /* Check to see if the calibration circuit is active, and if so, adjust
         * change the mode to calibration mode
         */
        //if(bit_is_clear(PORTD, PD4)) {
        /* Check to so see if there is a low signal from the calibration circuit */
        //Correction = Calibrate(Correction, Degrees);
        //} else {
        /* If we aren't calibrating, display the direction and such */
        LcdWriteString(HeadingString(Degrees), LCD_LINE_ONE);
        //}
        //Degrees += Correction;

        //LcdWriteString(("Degrees: %d", Degrees), LCD_LINE_TWO); //TODO fix this!
    }
    /* If this is ever called, I don't even know anymore */
    return 0;
}