This shows you the differences between two versions of the page.
| et:examples:communication:rs232:alpha [2012/04/05 18:02] – tekitatud illo | et:examples:communication:rs232:alpha [2020/07/20 12:00] (current) – external edit 127.0.0.1 | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| + | <code c> | ||
| + | // | ||
| + | // Kodulabori Kontrollerimooduli arvutiga RS-232 kaudu liidestamine. | ||
| + | // Näide kasutab Digitaalset sisend-väljundmoodulit koos LCD ekraaniga. | ||
| + | // Arvuti terminalis sisestatud tekst kuvatakse LCD-l. | ||
| + | // | ||
| + | #include < | ||
| + | #include < | ||
| + | // | ||
| + | // USART liidese määramine | ||
| + | // | ||
| + | usart port = USART(0); | ||
| + | |||
| + | // | ||
| + | // Põhiprogramm | ||
| + | // | ||
| + | int main(void) | ||
| + | { | ||
| + | char c; | ||
| + | unsigned char row = 1; | ||
| + | |||
| + | // USART liidese seadistamine | ||
| + | usart_init_async(port, | ||
| + | USART_DATABITS_8, | ||
| + | USART_STOPBITS_ONE, | ||
| + | USART_PARITY_NONE, | ||
| + | USART_BAUDRATE_ASYNC(9600)); | ||
| + | |||
| + | // LCD ekraani seadistamine | ||
| + | lcd_alpha_init(LCD_ALPHA_DISP_ON_BLINK); | ||
| + | |||
| + | // Ekraanil tervituse ütlemine | ||
| + | lcd_alpha_write_string(" | ||
| + | |||
| + | // Kursori teise rea algusesse viimine | ||
| + | lcd_alpha_goto_xy(0, | ||
| + | |||
| + | // Arvutile tere ütlemine | ||
| + | usart_send_string(port, | ||
| + | |||
| + | // Lõputu tsükkel | ||
| + | while (true) | ||
| + | { | ||
| + | // Jadaliidesest märgi lugemine | ||
| + | if (usart_try_read_char(port, | ||
| + | { | ||
| + | // Kas tegu on reavahetuse märgiga? | ||
| + | if (c == ' | ||
| + | { | ||
| + | // Rea vahetamine | ||
| + | row = 1 - row; | ||
| + | |||
| + | // Rea tühjendamine eelmisest teatest | ||
| + | lcd_alpha_clear_line(row); | ||
| + | } | ||
| + | else | ||
| + | { | ||
| + | // Märgi otse ekraanile väljastamine | ||
| + | lcd_alpha_write_char(c); | ||
| + | } | ||
| + | } | ||
| + | } | ||
| + | } | ||
| + | </ | ||