Ejemplo n.º 1
0
void main(void)
{
    uint16_t i, j, k;

    Kit_initialize();                           // initialize OK-89S52 kit
    Delay_ms(50);                               // wait for system stabilization
    LCD_initialize();                           // initialize text LCD module
    Beep();

    LCD_string(0x80, " Multiplication ");       // display title
    LCD_string(0xC0, "   0 * 0 = 00   ");

    while (1) {
        for (i = 2; i <= 9; i++) {
            for (j = 1; j <= 9; j++) {
                LCD_command(0xC3);              // display multiplicand
                LCD_data(i + '0');
                LCD_command(0xC7);              // display multiplier
                LCD_data(j + '0');
                k = Mul_8bit(i, j);             // call assembly routine(1)
                LCD_command(0xCB);              // display multiplication
                LCD_2d(k);
                Delay_1sec();                   // call assembly routine(2)
            }
            Beep();
        }
    }
}
Ejemplo n.º 2
0
int main(void)
{
    MCU_initialize();                           // initialize MCU and kit
    Delay_ms(50);                               // wait for system stabilization
    LCD_initialize();                           // initialize text LCD module
    Beep();

    LCD_string(0x80, "  Analog Comp.  ");       // display title
    LCD_string(0xC0, "  VR1 < 1.23V   ");

    ACSR = _BV(ACBG) | _BV(ACIS1) | _BV(ACIS0); // +input = 1.23V
    SFIOR |= _BV(ACME);                         // use ADC input pin
    ADCSRA &= ~_BV(ADEN);                       // ADEN = 0
    ADMUX = _BV(MUX1) | _BV(MUX0);              // -input = ADC3

    while (1) {
        if ((ACSR & 0x20) == 0x20) {            // if ACO=1, ADC3 < 1.23V
            PORTB = _BV(PB4);                   //   LED1 on
            LCD_command(0xC6);                  //   display "<"
            LCD_data('<');
        } else {                                // if ACO=0, ADC3 > 1.23V
            PORTB = _BV(PB7);                   //   LED4 on
            LCD_command(0xC6);                  //   display ">"
            LCD_data('>');
        }

        Delay_ms(100);                          // delay 100 ms
    }

    return 0;
}
Ejemplo n.º 3
0
void main(void)
{
    Kit_initialize();                           // initialize OK-89S52 kit
    Delay_ms(50);                               // wait for system stabilization
    LCD_initialize();                           // initialize text LCD module
    Beep();

    LCD_string(0x80, " A/D CH0 = 00H  ");       // display title
    LCD_string(0xC0, " A/D CH1 = 00H  ");

    T2CON = 0x04;                               // TR2=1, C/-T2=0
    T2MOD = 0x02;                               // programmable clock out mode
    RCAP2H = 65530 >> 8;                        // clock = 1MHz
    RCAP2L = 65530 & 0x00FF;
    TH2 = 65530 >> 8;
    TL2 = 65530 & 0x00FF;
    Delay_ms(100);                              // wait for ADC stabilization

    while (1) {
        LCD_command(0x8B);                      // cursor position
        ADC_CH0 = 0;                            // select and start ADC0809 IN0
        Delay_us(100);
        LCD_2hex(ADC_READ);                     // display A/D result in hex

        LCD_command(0xCB);                      // cursor position
        ADC_CH1 = 0;                            // select and start ADC0809 IN1
        Delay_us(100);
        LCD_2hex(ADC_READ);                     // display A/D result in hex

        Delay_ms(200);
    }
}
Ejemplo n.º 4
0
int main(void)
{
    uint8_t i, j;
    float x, y;

    MCU_initialize();                           // initialize MCU
    Delay_ms(50);                               // wait for system stabilization
    LCD_initialize();                           // initialize text LCD module

    while (1) {
        LCD_string(0x80, " FLOAT MULTIPLY ");   // display title
        LCD_string(0xC0, "0.0 x 0.0 =00.00");
        Beep();
        Delay_ms(1000);

        x = 0.0;                                // initial floating-point number

        for (i = 1; i <= 9; i++) {
            x += 1.1;
            y = 0.0;
            for (j = 1; j <= 9; j++) {
                y += 1.1;
                LCD_command(0xC0);
                LCD_1d1(x);                     // display multiplicand
                LCD_command(0xC6);
                LCD_1d1(y);                     // display multiplier
                LCD_command(0xCB);
                LCD_2d2(x * y);                 // display multiplication
                Delay_ms(1000);
            }
        }
    }

    return 0;
}
Ejemplo n.º 5
0
void LCD_initialize(void)
{                                               /* initialize text LCD module */
    LCD_command(0x38);                          // function set(8 bit, 2 line, 5x7 dot)
    LCD_command(0x0C);                          // display control(display ON, cursor OFF)
    LCD_command(0x06);                          // entry mode set(increment, not shift)
    LCD_command(0x01);                          // clear display
    Delay_ms(2);

    Key_input();                                // dummy function call to avoid warning
}
Ejemplo n.º 6
0
int
main(int argc, char *argv[])
{
	int		 i, c, done;
	int		 offset;
	char	 buf[128], str[64];
	short	 temp;

	i = 0;
	offset = 0;
	init_board();

read_input:
	if (IS_PRESSED(BUTTON1)) {
		UART0_puts("_BALANCE:1_", 64);
		UART0_gets(str, sizeof(str));
		LCD_command(1);
		LCD_puts(str, sizeof(str));
		LCD_putchar('\n');
		temp = read_temp();
		show_temperature(temp);
	} else if (IS_PRESSED(BUTTON2)) {
		UART0_puts("_RECHARGE:1:", 64);
		escrevenum(leds_state);
		UART0_puts("_", 64);
		UART0_gets(str, sizeof(str));
		LCD_command(1);
		LCD_puts(str, sizeof(str));
		LCD_putchar('\n');
		temp = read_temp();
		show_temperature(temp);
	} else if (IS_PRESSED(BUTTON3)) {
		UART0_puts("_DISCHARGE:1:", 64);
		escrevenum(leds_state);
		UART0_puts("_", 64);
		UART0_gets(str, sizeof(str));
		LCD_command(1);
		LCD_puts(str, sizeof(str));
		LCD_putchar('\n');
		temp = read_temp();
		show_temperature(temp);
	} else if (IS_PRESSED(BUTTON4)) {
		leds_state++;
		UPDATE_LED();
		uwait(1000);
	} else if (IS_PRESSED(BUTTON5)) {
		leds_state--;
		UPDATE_LED();
		uwait(1000);
	}
	goto read_input;

	/* NOTREACHED */
	return (0);
}
Ejemplo n.º 7
0
void LCD_setAddr(unsigned short x0, unsigned short y0, unsigned short x1, unsigned short y1) {
    LCD_command(CMD_CLMADRS); // Column
    LCD_data16(x0);
	LCD_data16(x1);

	LCD_command(CMD_PGEADRS); // Page
	LCD_data16(y0);
	LCD_data16(y1);

	LCD_command(CMD_RAMWR); //Into RAM
}
Ejemplo n.º 8
0
static void Display_time(void)
{                                               /* display time */
    LCD_command(0xC2);                          // display hour
    LCD_2digit(hour);
    LCD_command(0xC5);                          // display minute
    LCD_2digit(minute);
    LCD_command(0xC8);                          // display second
    LCD_2digit(second / 100);
    LCD_command(0xCB);                          // display 1/100 second
    LCD_2digit(second % 100);
}
Ejemplo n.º 9
0
void LCD_initialize(void)
{                                               /* initialize text LCD module */
    LCD_CONTROL = 0x03;                         // E = 1, Rs = 1 (dummy write)
    LCD_CONTROL = 0x02;                         // E = 0, Rs = 1
    Delay_ms(2);

    LCD_command(0x38);                          // function set(8 bit, 2 line, 5x7 dot)
    LCD_command(0x0C);                          // display control(display ON, cursor OFF)
    LCD_command(0x06);                          // entry mode set(increment, not shift)
    LCD_command(0x01);                          // clear display
    Delay_ms(2);
}
Ejemplo n.º 10
0
void main(void)
{
    Kit_initialize();                           // initialize OK-89S52 kit
    Delay_ms(50);                               // wait for system stabilization
    LCD_initialize();                           // initialize text LCD module
    Beep();

    LCD_string(0x80, "    RS-232C     ");       // display title
    LCD_string(0xC0, "                ");

    T2CON = 0x34;                               // TCLK=RCLK=1, TR2=1, C/-T2=0
    T2MOD = 0x00;                               // (baud rate generator)
    RCAP2H = 0xFF;                              // 115200 bps
    RCAP2L = 0xFA;
    SCON = 0x52;                                // 8 data, 1 stop, REN=TI=1
    cursor = SBUF;                              // dummy read(clear SBUF)

    LCD_command(0x0F);                          // cursor ON
    LCD_command(0xC0);                          // initialize cursor position
    cursor = 1;

    while (1) {
        switch (Key_input()) {                  // key input
        case 0x1C:
            DIG_SELECT = 0x01;
            TXD_string("KEY1 was pressed.");
            TXD_char(0x0D);
            TXD_char(0x0A);
            break;
        case 0x1A:
            DIG_SELECT = 0x02;
            TXD_string("KEY2 was pressed.");
            TXD_char(0x0D);
            TXD_char(0x0A);
            break;
        case 0x16:
            DIG_SELECT = 0x04;
            TXD_string("KEY3 was pressed.");
            TXD_char(0x0D);
            TXD_char(0x0A);
            break;
        case 0x0E:
            DIG_SELECT = 0x08;
            TXD_string("KEY4 was pressed.");
            TXD_char(0x0D);
            TXD_char(0x0A);
            break;
        default:
            break;
        }
        RXD_char();                             // check if a character received
    }
}
Ejemplo n.º 11
0
int main(void)
{
    uint8_t key;
    uint8_t key1 = 0, key2 = 0, key3 = 0, key4 = 0;

    MCU_initialize();                           // initialize MCU and kit
    Delay_ms(50);                               // wait for system stabilization
    LCD_initialize();                           // initialize text LCD module
    Beep();

    LCD_string(0x80, "KEY1=00  KEY2=00");       // display title
    LCD_string(0xC0, "KEY3=00  KEY4=00");

    while (1) {
        key = PINF & 0xF0;                      // key input without debouncing
        switch (key) {
        case (0xF0 & ~_BV(PF4)):
            PORTB = key ^ 0xF0;                 // display LED
            key1++;                             // display KEY1 count
            if (key1 > 99)
                key1 = 0;
            LCD_command(0x85);
            LCD_2d(key1);
            break;
        case (0xF0 & ~_BV(PF5)):
            PORTB = key ^ 0xF0;                 // display LED
            key2++;                             // display KEY2 count
            if (key2 > 99)
                key2 = 0;
            LCD_command(0x8E);
            LCD_2d(key2);
            break;
        case (0xF0 & ~_BV(PF6)):
            PORTB = key ^ 0xF0;                 // display LED
            key3++;                             // display KEY3 count
            if (key3 > 99)
                key3 = 0;
            LCD_command(0xC5);
            LCD_2d(key3);
            break;
        case (0xF0 & ~_BV(PF7)):
            PORTB = key ^ 0xF0;                 // display LED
            key4++;                             // display KEY4 count
            if (key4 > 99)
                key4 = 0;
            LCD_command(0xCE);
            LCD_2d(key4);
            break;
        }
    }

    return 0;
}
Ejemplo n.º 12
0
void LCD_show(char *str_0, char *str_1) {
    LCD_command(LCD_CLEAR, 1);
    LCD_setLocation(0, 0);
    LCD_print(str_0);
    LCD_setLocation(0, 1);
    LCD_print(str_1);
}
Ejemplo n.º 13
0
void main(void)
{
    uint16_t i, j, time;
    float x, y;

    Kit_initialize();                           // initialize OK-89S52 kit
    Delay_ms(50);                               // wait for system stabilization
    LCD_initialize();                           // initialize text LCD module
    Beep();

    TMOD = 0x01;                                // Timer 0, mode 1
    TCON = 0x10;                                // TR0=1
    TH0 = 0;                                    // clear Timer 0
    TL0 = 0;

    LCD_string(0x80, " Execution Time ");       // display title
    LCD_string(0xC0, "   00000 [us]   ");

    for (i = 1, x = 0.0; i <= 20; i++) {
        j = i + 500;                            // integer addition
        j = i * 500;                            // integer multiplication
        x += 12.34;                             // real addition
        y = x * 56.78 * j;                      // real & integer
    }

    time = TH0 * 256 + TL0;                     // read Timer 0
    LCD_command(0xC3);                          // display execution time
    LCD_5d(time / 2);

    while (1) ;
}
Ejemplo n.º 14
0
int main( void )
{
  LCD_init();
  LCD_write("Hello World");
  LCD_command(LCD_LINE2 | 5); // move cursor  to row 2, position 5 
  LCD_write("is here");
}
Ejemplo n.º 15
0
int main(void)
{
    MCU_initialize();                           // initialize MCU
    Delay_ms(50);                               // wait for system stabilization
    LCD_initialize();                           // initialize text LCD module

    Set_font();                                 // set user character font

    LCD_command(0x80);                          // display logo
    LCD_data(0x00);
    LCD_string(0x81, " OK-128  V2.2 ");
    LCD_data(0x07);

    while (1) {
        LCD_string(0xC0, "ATmega128 ");         // display message 1
        LCD_data(0x01);
        LCD_data(0x02);
        LCD_data(0x03);
        LCD_data(0x04);
        LCD_data(0x05);
        LCD_data(0x06);
        Beep();
        Delay_ms(2000);
        LCD_string(0xC0, "   2005/03/01   ");   // display message 2
        Delay_ms(2000);
        LCD_string(0xC0, " DUCK-YONG YOON ");   // display message 3
        Delay_ms(2000);
    }

    return 0;
}
Ejemplo n.º 16
0
void main(void)
{
    uint8_t i;
    uint16_t sum;

    Kit_initialize();                           // initialize OK-89S52 kit
    Delay_ms(50);                               // wait for system stabilization
    LCD_initialize();                           // initialize text LCD module
    Beep();

    LCD_string(0x80, " A/D CH0 = 00H  ");       // display title
    LCD_string(0xC0, " A/D CH1 = 00H  ");

    T2CON = 0x04;                               // TR2=1, C/-T2=0
    T2MOD = 0x02;                               // programmable clock out mode
    RCAP2H = 65530 >> 8;                        // clock = 1MHz
    RCAP2L = 65530 & 0x00FF;
    TH2 = 65530 >> 8;
    TL2 = 65530 & 0x00FF;
    Delay_ms(100);                              // wait for ADC stabilization

    while (1) {
        LCD_command(0x8B);                      // cursor position
        sum = 0;                                // clear total sum
        for (i = 1; i <= 16; i++) {
            ADC_CH0 = 0;                        // select and start ADC0809 IN0
            Delay_us(100);
            sum += ADC_READ;                    // add A/D result to total sum
            Delay_ms(1);                        // delay for interval
        }
        sum >>= 4;                              // calculate average
        LCD_2hex(sum);                          // display A/D result in hex

        LCD_command(0xCB);                      // cursor position
        sum = 0;                                // clear total sum
        for (i = 1; i <= 16; i++) {
            ADC_CH1 = 0;                        // select and start ADC0809 IN1
            Delay_us(100);
            sum += ADC_READ;                    // add A/D result to total sum
            Delay_ms(1);                        // delay for interval
        }
        sum >>= 4;                              // calculate average
        LCD_2hex(sum);                          // display A/D result in hex

        Delay_ms(200);
    }
}
Ejemplo n.º 17
0
void LCD_setCursor(uint8 col, uint8 row){
    int row_offsets[] = { 0x00, 0x40, 0x14, 0x54 };
    _numlines = LCD_ROW;
    if ( row > _numlines ) {
        row = _numlines-1;    // we count rows starting w/0
    }
    LCD_command(LCD_SETDDRAMADDR | (col + row_offsets[row]));
}
Ejemplo n.º 18
0
void LCD_string(uint8_t command, char *string)
{                                               /* display a string on LCD */
    LCD_command(command);                       // start position of string
    while (*string != '\0') {                   // display string
        LCD_data(*string);
        string++;
    }
}
Ejemplo n.º 19
0
void LCD_string(uint8_t command, char *string)
{                                               /* display a string on text LCD */
    LCD_command(command);
    while (*string != '\0') {
        LCD_data(*string);
        string++;
    }
}
Ejemplo n.º 20
0
// Allows us to fill the first 8 CGRAM locations
// with custom characters
void LCD_createChar(uint8 location, uint8 charmap[]) {
    location &= 0x7; // we only have 8 locations 0-7
    LCD_command(LCD_SETCGRAMADDR | (location << 3));
    int i;
    for (i=0; i<8; i++) {
        LCD_write(charmap[i]);
    }
}
Ejemplo n.º 21
0
void main(void)
{
    signed int i;
    float x, y;

    Kit_initialize();                           // initialize OK-89S52 kit
    Delay_ms(50);                               // wait for system stabilization
    LCD_initialize();                           // initialize text LCD module

    LCD_string(0x80, "sin(+000)=+0.000");       // display title
    LCD_string(0xC0, "cos(+000)=+0.000");

    T2CON = 0x34;                               // TCLK=RCLK=1, TR2=1, C/-T2=0
    T2MOD = 0x00;                               // (baud rate generator)
    RCAP2H = 0xFF;                              // 115200 bps
    RCAP2L = 0xFA;
    SCON = 0x52;                                // 8 data, 1 stop, REN=TI=1
    i = SBUF;                                   // dummy read(clear SBUF)

    while (1) {
        Beep();
        for (i = -360; i <= +360; i += 30) {
            x = i * 3.141592654 / 180.;
            y = sinf(x);
            LCD_command(0x84);
            LCD_s3d(i);                         // display sin()
            LCD_command(0x8A);
            LCD_s1d3(y);
            printf_fast_f("sin(%c%03d)=%c%1.3f\n",
                    i >= 0 ? '+' : '-', abs(i),
                    y >= 0. ? '+' : '-', fabsf(y));  // printf for sin output
            y = cosf(x);
            LCD_command(0xC4);
            LCD_s3d(i);                         // display cos()
            LCD_command(0xCA);
            LCD_s1d3(cosf(x));
            printf_fast_f("cos(%c%03d)=%c%1.3f\n\n",
                    i >= 0 ? '+' : '-', abs(i),
                    y >= 0. ? '+' : '-', fabsf(y));  // printf for cos output
            Delay_ms(2000);
        }
    }
}
Ejemplo n.º 22
0
static void Ucompare(uint8_t a, uint8_t b)
{                                               /* uint8_t compare */
    LCD_command(0xC7);
    if (a == b)
        LCD_data('=');
    else if (a > b)
        LCD_data('>');
    else
        LCD_data('<');
    Delay_ms(2000);
}
Ejemplo n.º 23
0
void main()
{
	init();
	unsigned char string;
	while(1)
	{
		string = TerimaChar();
		LCD_command(0x80);
		LCD_puts(string);
	}
}
Ejemplo n.º 24
0
static void
write_card(int off, char *buf)
{
	LCD_command(1);
	LCD_puts(INSCAR, sizeof(INSCAR));
	DPRINTF(INSCAR);
	while (FIO0PIN & (1 << 21));

	buf[0] = off;
	escreve_i2c(0xa0, buf, 17);
}
Ejemplo n.º 25
0
static void RXD_char(void)
{                                               /* receive a character */
    if (RI) {                                   // receive ready ?
        LCD_data(SBUF);                         // if yes, receive and RI=0
        RI = 0;                                 //      and display a character
        cursor += 1;                            // 16 characters OK ?
        if (cursor == 17) {
            LCD_command(0xC0);                  // if yes, go first column
            cursor = 1;
            Beep();
        }
    }
}
Ejemplo n.º 26
0
static void Set_font(void)
{                                               /* set user character font */
    uint8_t i;
    uint8_t font[] = {
        0x10, 0x18, 0x1C, 0x1E, 0x1C, 0x18, 0x10, 0x00, // character 0
        0x0F, 0x09, 0x09, 0x09, 0x09, 0x09, 0x0F, 0x00, // character 1
        0x08, 0x08, 0x08, 0x0E, 0x08, 0x08, 0x08, 0x00, // character 2
        0x01, 0x02, 0x04, 0x08, 0x00, 0x00, 0x0F, 0x00, // character 3
        0x10, 0x08, 0x04, 0x02, 0x00, 0x00, 0x1E, 0x00, // character 4
        0x0F, 0x08, 0x08, 0x0F, 0x08, 0x08, 0x0F, 0x00, // character 5
        0x04, 0x04, 0x04, 0x1C, 0x04, 0x04, 0x04, 0x00, // character 6
        0x01, 0x03, 0x07, 0x0F, 0x07, 0x03, 0x01, 0x00  // character 7
    };

    LCD_command(0x40);                          // set CGRAM address
    for (i = 0; i < 64; i++)                    // download font data
        LCD_data(font[i]);
}
Ejemplo n.º 27
0
void LCD_initial(void) {
    unsigned char i;
    LCD_Data = 0;
    for (i = 0; i < 3; i++) {
        LCD_command(0x38, 0);
        delay_ms(5);
    }
    LCD_command(0x38, 1);
    LCD_command(LCD_OFF, 1);
    LCD_command(LCD_CLEAR, 1);
    LCD_command(LCD_CURSOR, 1);
    LCD_command(LCD_ON, 1);
}
Ejemplo n.º 28
0
int main(void)
{
    uint8_t i;
    int16_t sum;

    MCU_initialize();                           // initialize MCU
    Delay_ms(50);                               // wait for system stabilization
    LCD_initialize();                           // initialize text LCD module

    LCD_string(0x80, "  ADC3 vs ADC2  ");       // display title
    LCD_string(0xC0, "    +0.00[V]    ");
    Beep();

    ADMUX = _BV(ADLAR) | _BV(MUX4) |
            _BV(MUX3) | _BV(MUX1) | _BV(MUX0);  // diffrential ADC3 vs ADC2 with gain 1
                                                //   (use left adjust and AREF)
    ADCSRA = _BV(ADEN) | _BV(ADPS2) | _BV(ADPS1) | _BV(ADPS0);  // ADC enable, 125kHz
    Delay_us(200);

    while (1) {
        sum = 0;
        for (i = 0; i < 16; i++) {              // read ADC by 16 times
            ADCSRA &= ~_BV(ADIF);               // clear ADIF
            ADCSRA |= _BV(ADSC);                // start conversion
            loop_until_bit_is_set(ADCSRA, ADIF);
            sum += (ADCL + ADCH * 256) / 64;    // add A/D result 16 times
            Delay_ms(1);
        }

        sum = sum / 16;                         // divide sum by 16

        LCD_command(0xC4);                      // display in voltage(+/-X.XX)
        LCD_s1d2(sum * 5. / 512.);              // Volt = sum*50/512

        Delay_ms(200);                          // delay 200 ms
    }

    return 0;
}
Ejemplo n.º 29
0
static void
read_card(int off, char *buf)
{
	LCD_command(1);
	LCD_puts(INSCAR, sizeof(INSCAR));
	DPRINTF(INSCAR);
	while (FIO0PIN & (1 << 21));

	DPRINTF("AQUI1\n");
	/* Depois de qualquer operacao efetua uma leitura */
	buf[0] = off;
	/* Escreve o offset (endereco no smcard) */
	escreve_i2c(0xa0, buf, 1);
	DPRINTF("AQUI2\n");

	/* Le 16 bytes a partir do offset */
	le_i2c(0xa0, buf, 16);
	buf[16] = '\0';
	DPRINTF("AQUI3\n");
	
	for (x = 0; x < 16; x++)
		PrByte(buf[x]);
}
Ejemplo n.º 30
0
void LCD_init(void){
	//setup the LCD control signals on PortC  (RS and Enable as output)
	DDRC |= ((1<<LCD_RS)|(1<<LCD_E));
	PORTC &= ~((1<<LCD_RS)|(1<<LCD_E));// set both low
	//setup the LCD control signals on PortD
  	DDRE |= ((1<<LCD_RD)|(1<<LCD_WR));// read and write pins (STK300 on PortG)
	PORTE &= ~(1<<LCD_WR); // write pin low
	// data Port A as output
	DDRD = 0xFF;
	/*if called right after power-up, we'll have to wait a bit (fine-tune 
	for faster execution) */
	_delay_ms(50);
   
        LCD_command(LCD_CLR);       // clear display
	LCD_command(LCD_8BIT);      // set 8 data bits  
	LCD_command(LCD_INC);       // cursor increments automatically 
	LCD_command(LCD_MOV);       // cursor  set to move
	//LCD_command(LCD_ALL);     // can call all instead of next line
	LCD_command(LCD_ON | LCD_ON_DISPLAY | LCD_ON_CURSOR | LCD_ON_BLINK);
        LCD_command(LCD_LINE1); // set cursor to  row 1, position 0
}