Differences

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

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
et:examples:communication:usb [2015/05/28 10:53] rellermaaet:examples:communication:usb [2020/07/20 09:00] (current) – external edit 127.0.0.1
Line 1: Line 1:
-~~PB~~+<pagebreak>
 ====== USB ====== ====== USB ======
  
Line 19: Line 19:
 #include <homelab/module/lcd_gfx.h> #include <homelab/module/lcd_gfx.h>
 #include <homelab/usb/usb.h> #include <homelab/usb/usb.h>
-  +#include <homelab/adc.h> 
 // Põhiprogramm // Põhiprogramm
 int main(void) int main(void)
Line 25: Line 26:
  char c;  char c;
  unsigned char row = 1;  unsigned char row = 1;
-  + 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("Ootan teadet");  lcd_gfx_write_string("Ootan teadet");
  lcd_gfx_goto_char_xy(0, row);  lcd_gfx_goto_char_xy(0, row);
- // Arvutile tere ütlemine + 
- usb_send_string(port"Tere, kirjuta midagi!\r\n"); + // Käivita ADC 
- + adc_init(ADC_REF_AVCC,ADC_PRESCALE_128); 
 + 
 + // 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 == '\r') // Kas tegu on reavahetuse märgiga?  if (c == '\r') // Kas tegu on reavahetuse märgiga?
  {  {
  // Rea vahetamine  // Rea vahetamine
- row = 1 - 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,row);
  }  }
  else  else
Line 55: Line 63:
  lcd_gfx_write_char(c);  lcd_gfx_write_char(c);
  }  }
- +            // Kui saadeti küsimärk, siis tagasta ka ADC lugem. 
-         if(c == '?'+            if(c == '?'
-         +            
-         sprintf(buf,"\n\r ADC val: %4d. \n\r",adc_get_average_value(15,5)); +                sprintf(buf,"\n\r ADC val: %4d. \n\r",adc_get_average_value(15,5)); 
-         usb_send_string(buf); +                usb_send_string(buf); 
-         }+            }
  }  }
  usb_task();  usb_task();
et/examples/communication/usb.1432810433.txt.gz · Last modified: 2020/07/20 09:00 (external edit)
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