Пример #1
0
void initialzie(void)
{
    	// Set all pins on Port A as digital IO.
	ADCON1 = 0x06;

	// Configure the IO direction.
        TRISA0 = 0;
        TRISA1 = 0;
        TRISA2 = 0;
        TRISA3 = 0;
        TRISA4 = 1;
        TRISA5 = 1;
	TRISB = 0b00000001;
	TRISC = 0b11010100;

	// Initialize the IO.
	PORTA = 0;
	PORTB = 0;
	PORTC = 0;

	LED1 = 0;

	CE = 0;
	CSN = 1;

	// Initialize SPI.
	vInitSpi();
	// Initialize nRF24L01.
	vInitNrf24l01();
        // Initialize LCD.
        LCD_initialize();
}
Пример #2
0
// Setup
inline void LCD_setup()
{
    // Register Scan CLI dictionary
    CLI_registerDictionary( lcdCLIDict, lcdCLIDictName );

    // Initialize SPI
    SPI_setup();


    // Setup Register Control Signal (A0)
    // Start in display register mode (1)
    GPIOC_PDDR |= (1<<7);
    PORTC_PCR7 = PORT_PCR_SRE | PORT_PCR_DSE | PORT_PCR_MUX(1);
    GPIOC_PSOR |= (1<<7);

    // Setup LCD Reset pin (RST)
    // 0 - Reset, 1 - Normal Operation
    // Start in normal mode (1)
    GPIOC_PDDR |= (1<<8);
    PORTC_PCR8 = PORT_PCR_SRE | PORT_PCR_DSE | PORT_PCR_MUX(1);
    GPIOC_PSOR |= (1<<8);

    // Run LCD intialization sequence
    LCD_initialize();
}
Пример #3
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;
}
Пример #4
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);
    }
}
Пример #5
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();
        }
    }
}
Пример #6
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) ;
}
Пример #7
0
void main(void)
{
    uint8_t i, j;

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

    LCD_string(0x80, "  *  SOUND  *   ");       // display title
    LCD_string(0xC0, " Telephone Bell ");

    T2CON = 0x04;                               // TR2=1, C/-T2=0

    while (1) {
        for (i = 1; i <= 3; i++) {              // repeat 3 times
            T2MOD = 0x02;                       // speaker on(T2OE=1)
            for (j = 1; j <= 20; j++) {
                RCAP2H = 46786 >> 8;            // 320Hz
                RCAP2L = 46786 & 0x00FF;
                Delay_ms(25);
                RCAP2H = 53036 >> 8;            // 480Hz
                RCAP2L = 53036 & 0x00FF;
                Delay_ms(25);
            }
            T2MOD = 0x00;                       // speaker off(T2OE=0)
            Delay_ms(1000);
        }
        Delay_ms(2000);
    }
}
Пример #8
0
int main(void)
{
    uint8_t i, LED;

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

    LCD_string(0x80, "   INT7 Count   ");       // display title
    LCD_string(0xC0, "      000       ");

    EICRB = _BV(ISC71);                         // INT7 = falling edge trigger
    EIMSK = _BV(INT7);                          // enable INT7
    EIFR = 0xFF;                                // clear interrupt flag
    sei();                                      // global interrupt enable

    while (1) {
        for (i = 1, LED = 0x10; i <= 4; i++) {  // shift from LED1 to LED4
            PORTB = LED;
            Delay_ms(200);
            LED <<= 1;
        }
    }

    return 0;
}
Пример #9
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;
}
Пример #10
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;
}
Пример #11
0
int main(void)
{
    uint8_t i;
    uint8_t tri_table[] = {                     // triangular wave data table
        0x80, 0x84, 0x88, 0x8C, 0x90, 0x94, 0x98, 0x9C, 0xA0, 0xA4,
        0xA8, 0xAC, 0xB0, 0xB4, 0xB8, 0xBC, 0xC0, 0xC4, 0xC8, 0xCC,
        0xD0, 0xD4, 0xD8, 0xDC, 0xE0, 0xE4, 0xE0, 0xDC, 0xD8, 0xD4,
        0xD0, 0xCC, 0xC8, 0xC4, 0xC0, 0xBC, 0xB8, 0xB4, 0xB0, 0xAC,
        0xA8, 0xA4, 0xA0, 0x9C, 0x98, 0x94, 0x90, 0x8C, 0x88, 0x84,
        0x80, 0x7C, 0x78, 0x74, 0x70, 0x6C, 0x68, 0x64, 0x60, 0x5C,
        0x58, 0x54, 0x50, 0x4C, 0x48, 0x44, 0x40, 0x3C, 0x38, 0x34,
        0x30, 0x2C, 0x28, 0x24, 0x20, 0x1C, 0x20, 0x24, 0x28, 0x2C,
        0x30, 0x34, 0x38, 0x3C, 0x40, 0x44, 0x48, 0x4C, 0x50, 0x54,
        0x58, 0x5C, 0x60, 0x64, 0x68, 0x6C, 0x70, 0x74, 0x78, 0x7C
    };

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

    LCD_string(0x80, "  DAC0800 D/A   ");       // display title
    LCD_string(0xC0, "Triangular Wave ");

    while (1) {
        for (i = 0; i < 100; i++) {             // output D/A
            PORTB = tri_table[i];
            Delay_us(10);
        }
    }

    return 0;
}
Пример #12
0
int main(void) {

	// Inicializace displeje
	LCD_initialize();

	GPIO_Initialize();

	// Pocatecni stav uctu
	BankaOperace(10000);
	nVyberu = nVkladu = 0;

	LCD_puts("Spoustim procesy...");



	// Vytvoreni ulohy 1 - obsluha prikazu
	xTaskCreate(prikazy, /* ukazatel na task */
			"GUI", /* jmeno tasku pro ladeni - kernel awareness debugging */
			configMINIMAL_STACK_SIZE, /* velikost zasobniku = task stack size */
			(void*)NULL, /* pripadny parametr pro task = optional task startup argument */
			tskIDLE_PRIORITY + 1, /* priorita tasku, nizsi nez ostatnich */
			(xTaskHandle*)NULL /* pripadne handle na task, pokud ma byt vytvoreno */
		);

	// Vytvoreni ulohy 2 - vklad
	xTaskCreate(vklad, /* ukazatel na task */
			"vklad", /* jmeno tasku pro ladeni - kernel awareness debugging */
			configMINIMAL_STACK_SIZE, /* velikost zasobniku = task stack size */
			(void*)NULL, /* pripadny parametr pro task = optional task startup argument */
			tskIDLE_PRIORITY + 2, /* priorita tasku, vyssi nez u tasku 1 */
			&TaskVklad /* pripadne handle na task, pokud ma byt vytvoreno */
		);

	// Vytvoreni ulohy 2 - vyber
	xTaskCreate(vyber, /* ukazatel na task */
				"vyber", /* jmeno tasku pro ladeni - kernel awareness debugging */
				configMINIMAL_STACK_SIZE, /* velikost zasobniku = task stack size */
				(void*)NULL, /* pripadny parametr pro task = optional task startup argument */
				tskIDLE_PRIORITY + 3, /* priorita tasku, vyssi nez u tasku 1 */
				&TaskVyber /* pripadne handle na task, pokud ma byt vytvoreno */
			);

	// Pozastavime tasky
	vTaskSuspend(TaskVklad);
	vTaskSuspend(TaskVyber);

	// Spusteni jadra FreeRTOS
	vTaskStartScheduler(); /* does not return */

	// Sem bychom se nikdy nemeli dostat
	while (1)
		;

	/* Never leave main */
	return 0;
}
Пример #13
0
void main() {
    initVars();
    
	Init_Registers();
    initPorts();
    
    unsigned char loop=1;
    LCD_initialize();
    while (loop>0) {
        loop += 1;
        
		LCD_Clear();
		//waitForKey();           // attendi che il pin venga messo a massa
        
        // MY_delay_s(1);
		LORETO_LED  = pinRA1;
		// pinRA4  = pinRA1;
        
		if (loop%2 == 0) {
			LCD_gotoRC(0, 0);
			LCD_printRom(romStr, 0);            //DEBUG
			// waitForKey();           // attendi che il pin venga messo a massa
            delay_s(1);
			
			LCD_gotoRC(1, 0);
			LCD_printStr("Loreto");
            delay_s(1);
			// waitForKey();           // attendi che il pin venga messo a massa
			

			LCD_gotoRC(1, 12);
			LCD_printStr("Ale");
            delay_s(1);
			// waitForKey();           // attendi che il pin venga messo a massa
		}
		else {
			LCD_gotoRC(1, 0);
			LCD_printRom(romStr, 0);            //DEBUG
            delay_s(1);
			// waitForKey();           // attendi che il pin venga messo a massa
			
			LCD_gotoRC(0, 0);
			LCD_printStr("Loreto");
            delay_s(1);
			// waitForKey();           // attendi che il pin venga messo a massa
		}
        
        LCD_Clear();
        LCD_printfAt(0,0,   "Dec Number:%02d", 12345);            //DEBUG
        LCD_printfAt(1,0,   "Hex Number:%02X", 12345);            //DEBUG
        delay_s(1);
        
    }
    
} // end main()
Пример #14
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;
}
Пример #15
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
    }
}
Пример #16
0
int main(void)
{
    uint8_t mode, LED;

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

    LCD_string(0x80, " S/W Time Delay ");       // display title
    LCD_string(0xC0, "Press KEY4-KEY1!");

    mode = 1;                                   // initial speed mode
    LED = _BV(PB6) | _BV(PB4);                  // initial LED data

    while (1) {
        switch (Key_input()) {                  // key input
        case 0xE0:
            mode = 1;
            LCD_string(0xC0, "    100 [ms]    ");
            break;
        case 0xD0:
            mode = 2;
            LCD_string(0xC0, "    200 [ms]    ");
            break;
        case 0xB0:
            mode = 3;
            LCD_string(0xC0, "    300 [ms]    ");
            break;
        case 0x70:
            mode = 4;
            LCD_string(0xC0, "    400 [ms]    ");
            break;
        default:
            LED ^= 0xF0;                        // output LED with complement
            PORTB = LED;
            if (mode == 1)
                Delay_ms(100);
            else if (mode == 2)
                Delay_ms(200);
            else if (mode == 3)
                Delay_ms(300);
            else
                Delay_ms(400);
            break;
        }
    }

    return 0;
}
Пример #17
0
int main(void)
{
    uint8_t i;

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

    GLCD_clear();                               // initialize GLCD screen
    cursor_flag = 0;                            // cursor off

    LCD_string(0x80, "Graphic LCD Test");       // display title on text LCD
    LCD_string(0xC0, " ASCII(English) ");

    while (1) {
        GLCD_string(0, 0, "  OK-128 Kit  V3.0  ");  // display screen 1
        GLCD_string(1, 0, "     2006/05/01     ");
        GLCD_string(2, 0, "                    ");
        GLCD_string(3, 0, "     Designed by    ");
        GLCD_string(4, 0, "   Duck-Yong Yoon.  ");
        GLCD_string(5, 0, "                    ");
        GLCD_string(6, 0, "      Made by       ");
        GLCD_string(7, 0, " Ohm Publishing Co. ");
        Delay_ms(5000);

        GLCD_string(0, 0, "     Hyundai LCD    ");  // display screen 2
        GLCD_string(1, 0, "    HG12605NY-LY    ");
        GLCD_string(2, 0, "                    ");
        GLCD_string(3, 0, "    Yellow/Green    ");
        GLCD_string(4, 0, " LED Backlight Type ");
        GLCD_string(5, 0, "                    ");
        GLCD_string(6, 0, "128 x 64 Graphic LCD");
        GLCD_string(7, 0, " 6x8 Box, 5x7 ASCII ");
        Delay_ms(5000);

        GLCD_string(0, 0, "====================");  // display screen 3
        GLCD_string(1, 0, "  ASCII Characters  ");
        GLCD_string(2, 0, "====================");
        GLCD_string(7, 0, "                    ");

        GLCD_xy(3, 0);
        for (i = 0x20; i < 0x7F; i++)           // from 0x20 to 0x7E
            GLCD_character(i);
        Delay_ms(5000);
    }

    return 0;
}
Пример #18
0
void main(void)
{
    uint8_t mode, LED;

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

    LCD_string(0x80, " H/W Time Delay ");       // display title
    LCD_string(0xC0, "Press KEY4-KEY1!");

    mode = 1;                                   // initial speed mode
    LED = 0x05;                                 // initial LED data

    while (1) {
        switch (Key_input()) {                  // key input
        case 0x1C:
            mode = 1;
            LCD_string(0xC0, "    100 [ms]    ");
            break;
        case 0x1A:
            mode = 2;
            LCD_string(0xC0, "    200 [ms]    ");
            break;
        case 0x16:
            mode = 3;
            LCD_string(0xC0, "    300 [ms]    ");
            break;
        case 0x0E:
            mode = 4;
            LCD_string(0xC0, "    400 [ms]    ");
            break;
        default:
            LED ^= 0x0F;                        // output LED with complement
            DIG_SELECT = LED;
            if (mode == 1)
                Timer0_ms(100);
            else if (mode == 2)
                Timer0_ms(200);
            else if (mode == 3)
                Timer0_ms(300);
            else
                Timer0_ms(400);
            break;
        }
    }
}
Пример #19
0
void main(void) {
    configurazione();
    LCD_initialize(16);
    while (1) {
        id = msg.identifier;
        data = msg.data[0];
        LCD_goto_xy(1, 0);
        LCD_write_message("id");
        LCD_goto_xy(1, 3);
        LCD_write_char(id);
        LCD_goto_xy(2, 0);
        LCD_write_char(data);
        delay_ms(1000);
        LCD_clear();
    }
}
Пример #20
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);
    }
}
Пример #21
0
void main() {
	
	Init_Registers();
    initPorts();
	LCD_initialize();
    LCD_Clear();

    while (1) {
        TMR0_GATE_LINE  = 0;	            //Turn OFF Gate line
        LCD_print(0,0,    "Line1");      	// LCD_Line1-0
        LCD_printf(0,7,   ":%03d ", 54);    // LCD_Line1-7 
        LCD_printRom(1,0, "Line2");         // LCD_Line2-0
        delay_s(1);
        TMR0_GATE_LINE  = 1;	            //Turn OFF Gate line
        delay_s(1);
    }

}    
Пример #22
0
void main(void)
{
    Kit_initialize();                           // initialize OK-89S52 kit
    Delay_ms(50);                               // wait for system stabilization
    LCD_initialize();                           // initialize text LCD module

    while (1) {
        Beep();

        LCD_string(0x80, " OK-89S52  V1.0 ");   // display logo 1
        LCD_string(0xC0, "D.Y.YOON in 2005");
        Delay_ms(2000);

        LCD_string(0x80, "  Ohm Book Co.  ");   // display logo 2
        LCD_string(0xC0, "Tel. 02-776-4868");
        Delay_ms(2000);
    }
}
Пример #23
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, " AVR STOP WATCH ");       // display title
    Clear_time();                               // clear time and display
    run_flag = 0;
    Set_timer1();                               // initialize Timer1 and OC1A

    while (1) {
        switch (Key_input()) {                  // key input
        case (0xF0 & ~_BV(PF4)):
            if (run_flag == 1)
                break;                          // if run_flag=1, ignore KEY1
            PORTB = _BV(PB4);                   // if KEY1, start
            TCNT1H = 0x00;
            TCNT1L = 0x00;
            run_flag = 1;
            sei();
            break;
        case (0xF0 & ~_BV(PF6)):
            if (run_flag == 1)
                break;                          // if run_flag=1, ignore KEY3
            cli();                              // if KEY3, reset
            PORTB = _BV(PB6);
            Clear_time();
            break;
        case (0xF0 & ~_BV(PF7)):
            if (run_flag == 0)
                break;                          // if run_flag=0, ignore KEY4
            cli();                              // if KEY4, stop
            PORTB = _BV(PB7);
            run_flag = 0;
            break;
        default:
            break;
        }
    }

    return 0;
}
Пример #24
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);
        }
    }
}
Пример #25
0
int main(void)
{
    uint8_t i, j, k, digit;

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

    LCD_string(0x80, " 7-SEGMENT LED  ");       // display title
    LCD_string(0xC0, "                ");

    while (1) {
        Beep();

        for (i = 0; i < 250; i++)               // display for 2 sec
            for (j = 0, digit = 0x80; j <= 7; j++) {    // display from 0 to 7
                LCD_DATABUS = Bin2LED(j);
                DIG_SELECT = digit;
                digit = digit >> 1;
                Delay_ms(1);
            }

        for (i = 0; i < 250; i++)               // display for 2 sec
            for (j = 8, digit = 0x80; j <= 15; j++) {   // display from 8 to F
                LCD_DATABUS = Bin2LED(j);
                DIG_SELECT = digit;
                Delay_ms(1);
                digit = digit >> 1;
            }
        for (k = 0; k <= 8; k++)                // display shift left
            for (i = 0; i < 125; i++)           // display for 1 sec
                for (j = 0, digit = 0x80; j <= 7; j++) {
                    LCD_DATABUS = Bin2LED(k + j) + 0x01;
                    DIG_SELECT = digit;
                    Delay_ms(1);
                    digit = digit >> 1;
                }

        DIG_SELECT = 0x00;                      // clear 7-segment LED
    }

    return 0;
}
Пример #26
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, " INT7 Interrupt ");       // display title
    LCD_string(0xC0, "(Level Trigger) ");

    EICRB = 0x00;                               // INT7 = level trigger
    EIMSK = _BV(INT7);                          // enable INT7
    EIFR = 0xFF;                                // clear interrupt flag
    sei();                                      // global interrupt enable

    while (1) ;                                 // wait interrupt

    return 0;
}
Пример #27
0
void main()
{
	unsigned char text[]="Crota must\ndie!";
	unsigned char text2[32];
	Delay10KTCYx(25);
	LCD_initialize();
	flag = 0;
	count = 0;
	while(flag == 0)
	{
		//LCD_write('f',1);
		itoa(count,text2);
		LCD_input(text2);
		//LCD_write('f',1);
		LATBbits.LATB2 = ~LATBbits.LATB2;
		Delay10KTCYx(25);
		LCD_clear();
		count++;
	}

}
Пример #28
0
int main(void)
{
    uint8_t i;
    float x;

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

    LCD_string(0x80, "  DAC0800 D/A   ");       // display title
    LCD_string(0xC0, "   Sine Wave    ");

    while (1) {
        for (i = 0; i < 100; i++) {             // output D/A
            x = 360. * (float)i / 100.;
            PORTB = 0x80 + 0x7F * sin(M_PI * x / 180.);
        }
    }

    return 0;
}
Пример #29
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;
}
Пример #30
0
int main(void)
{
    uint8_t i, LED;

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

    LCD_string(0x80, " Infinite Loop  ");       // display title
    LCD_string(0xC0, "  Run One Time  ");

    LED = _BV(PB4);                             // shift from LED1 to LED4
    for (i = 1; i <= 4; i++) {
        PORTB = LED;                            // output LED data
        Delay_ms(500);
        LED <<= 1;                              // shift left
    }

    while (1) ;                                 // infinite loop

    return 0;
}