Differences

This shows you the differences between two versions of the page.

Link to this comparison view

et:examples:communication:rs232:alpha [2012/04/05 18:02] – tekitatud illoet: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 <homelab/usart.h>
 +#include <homelab/module/lcd_alpha.h>
  
 +//
 +// 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("Ootan teadet");
 +
 + // Kursori teise rea algusesse viimine
 + lcd_alpha_goto_xy(0, row);
 +
 + // Arvutile tere ütlemine
 + usart_send_string(port, "Tere, kirjuta midagi!\r\n");
 +
 + // Lõputu tsükkel
 + while (true)
 + {
 + // Jadaliidesest märgi lugemine
 + if (usart_try_read_char(port, &c))
 + {
 + // Kas tegu on reavahetuse märgiga?
 + if (c == '\r')
 + {
 + // 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);
 + }
 + }
 + }
 +}
 +</code>
CC Attribution-Share Alike 4.0 International
www.chimeric.de Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0