This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| et:examples:communication:usb [2015/05/28 10:58] – rellermaa | et:examples:communication:usb [2020/07/20 09:00] (current) – external edit 127.0.0.1 | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| - | ~~PB~~ | + | < |
| ====== USB ====== | ====== USB ====== | ||
| Line 20: | Line 20: | ||
| #include < | #include < | ||
| #include < | #include < | ||
| - | | + | |
| // Põhiprogramm | // Põhiprogramm | ||
| int main(void) | int main(void) | ||
| Line 27: | Line 27: | ||
| unsigned char row = 1; | unsigned char row = 1; | ||
| char buf[20]; | char buf[20]; | ||
| - | + | ||
| - | // USART liidese seadistamine | + | |
| - | usb_init(); | + | |
| - | + | ||
| // LCD ekraani seadistamine ja tervitusteksti kuvamine | // LCD ekraani seadistamine ja tervitusteksti kuvamine | ||
| lcd_gfx_init(); | lcd_gfx_init(); | ||
| lcd_gfx_write_string(" | lcd_gfx_write_string(" | ||
| lcd_gfx_goto_char_xy(0, | lcd_gfx_goto_char_xy(0, | ||
| - | |||
| - | // Arvutile tere ütlemine | ||
| - | usb_send_string(port, | ||
| // Käivita ADC | // Käivita ADC | ||
| adc_init(ADC_REF_AVCC, | adc_init(ADC_REF_AVCC, | ||
| - | + | ||
| + | // USB liidese seadistamine | ||
| + | usb_init(); | ||
| // Lõputu tsükkel | // Lõputu tsükkel | ||
| while (1) | while (1) | ||
| { | { | ||
| - | c = usb_read_byte(); | + | // Loe USB liidesest märk ja kontrolli, kas oli märk olemas |
| - | if (c != 0xFF) // Jadaliidesest märgi lugemine | + | c = usb_read_byte(); |
| + | if (c >= 0) | ||
| { | { | ||
| - | usb_send_char(data); | + | // Saada märk USB liideseesse tagasi |
| + | usb_send_char(c); | ||
| if (c == ' | if (c == ' | ||
| { | { | ||
| // Rea vahetamine | // Rea vahetamine | ||
| - | row | + | if (row < 12) row++; |
| + | else row = 0; | ||
| // Rea tühjendamine eelmisest teatest | // Rea tühjendamine eelmisest teatest | ||
| lcd_gfx_clear_line(row); | lcd_gfx_clear_line(row); | ||
| + | // Kursor uue rea algusesse | ||
| + | lcd_gfx_goto_char_xy(0, | ||
| } | } | ||
| else | else | ||
| Line 61: | Line 63: | ||
| lcd_gfx_write_char(c); | lcd_gfx_write_char(c); | ||
| } | } | ||
| - | + | // Kui saadeti küsimärk, siis tagasta ka ADC lugem. | |
| - | | + | if(c == '?' |
| - | | + | { |
| - | sprintf(buf," | + | sprintf(buf," |
| - | | + | usb_send_string(buf); |
| - | | + | } |
| } | } | ||
| usb_task(); | usb_task(); | ||